Skip to content

Package: CreateViewModel$ViewModelWizardDialog

CreateViewModel$ViewModelWizardDialog

nameinstructionbranchcomplexitylinemethod
CreateViewModel.ViewModelWizardDialog(CreateViewModel, Shell, ViewModelWizard)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
backPressed()
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.model.actions;
15:
16: import org.eclipse.core.commands.AbstractHandler;
17: import org.eclipse.core.commands.ExecutionEvent;
18: import org.eclipse.core.commands.ExecutionException;
19: import org.eclipse.core.resources.IFile;
20: import org.eclipse.emf.ecp.view.model.presentation.SelectEClassForViewWizardPage;
21: import org.eclipse.emf.ecp.view.model.presentation.ViewModelWizard;
22: import org.eclipse.jface.viewers.IStructuredSelection;
23: import org.eclipse.jface.wizard.WizardDialog;
24: import org.eclipse.swt.widgets.Shell;
25: import org.eclipse.ui.PlatformUI;
26: import org.eclipse.ui.handlers.HandlerUtil;
27:
28: /**
29: * An {@link AbstractHandler} that creates a new wizard allowing the creation of new view model files.
30: */
31: public class CreateViewModel extends AbstractHandler {
32:
33:         @Override
34:         public Object execute(ExecutionEvent event) throws ExecutionException {
35:                 // get ecore
36:                 final IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
37:
38:                 // TODO - check if the object can be cast and is an ecore
39:                 final IFile selectedEcore = (IFile) selection.getFirstElement();
40:
41:                 final ViewModelWizard w = new ViewModelWizard();
42:                 w.setSelection(selection);
43:                 w.setSelectedContainer(selectedEcore);
44:                 w.setWorkbench(PlatformUI.getWorkbench());
45:
46:                 final WizardDialog dialog = new ViewModelWizardDialog(HandlerUtil.getActiveShell(event), w);
47:                 dialog.open();
48:
49:                 return null;
50:         }
51:
52:         /** {@link WizardDialog} containing a {@link ViewModelWizard}. */
53:         private class ViewModelWizardDialog extends WizardDialog {
54:
55:                 private final ViewModelWizard wizard;
56:
57:                 /**
58:                  * Creates a new wizard dialog for the given wizard.
59:                  *
60:                  * @param parentShell the parent shell
61:                  * @param newWizard the wizard this dialog is working on
62:                  */
63:                 ViewModelWizardDialog(Shell parentShell, ViewModelWizard newWizard) {
64:                         super(parentShell, newWizard);
65:                         wizard = newWizard;
66:                 }
67:
68:                 @Override
69:                 protected void backPressed() {
70:•                        if (SelectEClassForViewWizardPage.class.isInstance(getCurrentPage())) {
71:                                 wizard.clearSelectedContainer();
72:                         }
73:                         super.backPressed();
74:                 }
75:         }
76: }