Skip to content

Package: SelectModelElementWizard$WizardPageExtension

SelectModelElementWizard$WizardPageExtension

nameinstructionbranchcomplexitylinemethod
SelectModelElementWizard.WizardPageExtension(SelectModelElementWizard, String)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createControl(Composite)
M: 0 C: 53
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2012 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: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15:
16: package org.eclipse.emf.ecp.spi.common.ui;
17:
18: import org.eclipse.emf.ecore.EClass;
19: import org.eclipse.emf.ecp.spi.common.ui.composites.SelectionComposite;
20: import org.eclipse.jface.viewers.ColumnViewer;
21: import org.eclipse.jface.viewers.DoubleClickEvent;
22: import org.eclipse.jface.viewers.IDoubleClickListener;
23: import org.eclipse.jface.viewers.ISelectionChangedListener;
24: import org.eclipse.jface.viewers.IStructuredSelection;
25: import org.eclipse.jface.viewers.SelectionChangedEvent;
26: import org.eclipse.jface.viewers.TreeViewer;
27: import org.eclipse.jface.wizard.WizardDialog;
28: import org.eclipse.jface.wizard.WizardPage;
29: import org.eclipse.swt.widgets.Composite;
30:
31: /**
32: * This is implementation of New Model Element wizard. This wizard is show through
33: * "Add new model element..." command in context menu of Navigator (only on right click on LeafSection). The
34: * wizard shows a tree of model packages and their classes. The user can select a Model Element type in this
35: * tree and on finish the model element is created, added to Leaf- or CompositeSection and opend for editing.
36: *
37: * @author Eugen Neufeld
38: */
39: public class SelectModelElementWizard extends ECPWizard<SelectionComposite<? extends ColumnViewer>> {
40:
41:         /**
42:          * @author Jonas
43:          *
44:          */
45:         public final class WizardPageExtension extends WizardPage {
46:                 /**
47:                  * @param pageName the name of the page
48:                  */
49:                 public WizardPageExtension(String pageName) {
50:                         super(pageName);
51:                 }
52:
53:                 @Override
54:                 public void createControl(Composite parent) {
55:                         final Composite composite = getCompositeProvider().createUI(parent);
56:•                        if (getCompositeProvider().getViewer() instanceof TreeViewer) {
57:                                 final TreeViewer tv = (TreeViewer) getCompositeProvider().getViewer();
58:                                 tv.expandToLevel(2);
59:                         }
60:                         getCompositeProvider().getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
61:
62:                                 @Override
63:                                 public void selectionChanged(SelectionChangedEvent event) {
64:                                         final IStructuredSelection sel = (IStructuredSelection) getCompositeProvider().getViewer()
65:                                                 .getSelection();
66:
67:                                         if (sel != null && !sel.isEmpty()
68:                                                 && classtoSelect.isAssignableFrom(sel.getFirstElement().getClass())) {
69:                                                 setPageComplete(true);
70:                                         } else {
71:                                                 setPageComplete(false);
72:                                         }
73:                                 }
74:                         });
75:                         getCompositeProvider().getViewer().addDoubleClickListener(new IDoubleClickListener() {
76:
77:                                 @Override
78:                                 public void doubleClick(DoubleClickEvent event) {
79:                                         if (isPageComplete() && performFinish()) {
80:                                                 ((WizardDialog) getContainer()).close();
81:                                         }
82:
83:                                 }
84:
85:                         });
86:                         setPageComplete(false);
87:                         setControl(composite);
88:                 }
89:         }
90:
91:         private final String pageName;
92:         private final String description;
93:         private final String pageTitle;
94:         private final Class<?> classtoSelect;
95:
96:         /**
97:          * Constructor to select an EClass.
98:          *
99:          * @param windowTitle The window title
100:          * @param pageName the name of the page
101:          * @param pageTitle the title of the page
102:          * @param description the description
103:          */
104:         public SelectModelElementWizard(String windowTitle, String pageName, String pageTitle, String description) {
105:                 this(windowTitle, pageName, pageTitle, description, EClass.class);
106:         }
107:
108:         /**
109:          * Constructor to select an class to be specified.
110:          *
111:          * @param windowTitle The window title
112:          * @param pageName the name of the page
113:          * @param pageTitle the title of the page
114:          * @param description the description
115:          * @param classtoSelect the class which can be selected
116:          */
117:         public SelectModelElementWizard(String windowTitle, String pageName, String pageTitle, String description,
118:                 Class<?> classtoSelect) {
119:                 this.classtoSelect = classtoSelect;
120:                 setWindowTitle(windowTitle);
121:                 this.pageName = pageName;
122:                 this.description = description;
123:                 this.pageTitle = pageTitle;
124:         }
125:
126:         /**
127:          * {@inheritDoc}
128:          */
129:         @Override
130:         public void addPages() {
131:                 super.addPages();
132:                 final WizardPage wp = new WizardPageExtension(pageName);
133:                 addPage(wp);
134:                 wp.setTitle(pageTitle);
135:                 wp.setDescription(description);
136:
137:         }
138:
139:         /**
140:          * . ({@inheritDoc}) This method creates a model element instance from selected type, adds it to Leaf- or
141:          * CompositeSection, and opens it.
142:          */
143:         @Override
144:         public boolean performFinish() {
145:                 return true;
146:         }
147:
148:         @Override
149:         public void dispose() {
150:                 getCompositeProvider().dispose();
151:                 super.dispose();
152:         }
153:
154:         /**
155:          * @return the pageName
156:          * @since 1.5
157:          */
158:         public String getPageName() {
159:                 return pageName;
160:         }
161:
162:         /**
163:          * @return the description
164:          * @since 1.5
165:          */
166:         public String getDescription() {
167:                 return description;
168:         }
169:
170:         /**
171:          * @return the pageTitle
172:          * @since 1.5
173:          */
174:         public String getPageTitle() {
175:                 return pageTitle;
176:         }
177: }