Skip to content

Package: DMRCreationWizard

DMRCreationWizard

nameinstructionbranchcomplexitylinemethod
DMRCreationWizard()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addPages()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
canFinish()
M: 17 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getEPackage()
M: 64 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
getNextPage(IWizardPage)
M: 33 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getPreviousPage(IWizardPage)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getSelectedEStructuralFeature()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSelectedEcore()
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getStartingPage()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
init(IWorkbench, IStructuredSelection)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
performFinish()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setSelection(IStructuredSelection)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 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: * Eugen Neufeld - initial API and implementation
13: */
14: package org.eclipse.emf.ecp.view.template.internal.tooling.util;
15:
16: import java.util.List;
17:
18: import org.eclipse.core.resources.IFile;
19: import org.eclipse.emf.common.util.EList;
20: import org.eclipse.emf.common.util.URI;
21: import org.eclipse.emf.ecore.EObject;
22: import org.eclipse.emf.ecore.EPackage;
23: import org.eclipse.emf.ecore.EStructuralFeature;
24: import org.eclipse.emf.ecore.resource.Resource;
25: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
26: import org.eclipse.emf.ecp.view.internal.editor.handler.SelectEcorePage;
27: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
28: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
29: import org.eclipse.emf.ecp.view.template.internal.tooling.Messages;
30: import org.eclipse.jface.viewers.IStructuredSelection;
31: import org.eclipse.jface.wizard.IWizardPage;
32: import org.eclipse.jface.wizard.Wizard;
33: import org.eclipse.ui.INewWizard;
34: import org.eclipse.ui.IWorkbench;
35:
36: /**
37: * Wizard for creating a {@link org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference
38: * VFeaturePathDomainModelReference} for a DomainModelReferenceSelector.
39: *
40: * @author Eugen Neufeld
41: *
42: */
43: public class DMRCreationWizard extends Wizard implements INewWizard {
44:
45:         private static final String PLUGIN_ID = "org.eclipse.emf.ecp.view.template.tooling"; //$NON-NLS-1$
46:         private Object selectedContainer;
47:
48:         /**
49:          * This caches an instance of the model package. <!-- begin-user-doc -->
50:          * <!-- end-user-doc -->
51:          *
52:          * @generated
53:          */
54:         protected VViewPackage viewPackage = VViewPackage.eINSTANCE;
55:
56:         /**
57:          * This caches an instance of the model factory. <!-- begin-user-doc -->
58:          * <!-- end-user-doc -->
59:          *
60:          * @generated
61:          */
62:         protected VViewFactory viewFactory = viewPackage.getViewFactory();
63:
64:         /**
65:          * Remember the selection during initialization for populating the default
66:          * container. <!-- begin-user-doc --> <!-- end-user-doc -->
67:          *
68:          * @generated
69:          */
70:         protected IStructuredSelection selection;
71:
72:         /**
73:          * @param selection the selection to set
74:          */
75:         public void setSelection(IStructuredSelection selection) {
76:                 this.selection = selection;
77:         }
78:
79:         /**
80:          * Remember the workbench during initialization. <!-- begin-user-doc -->
81:          * <!-- end-user-doc -->
82:          *
83:          * @generated
84:          */
85:         protected IWorkbench workbench;
86:
87:         /**
88:          * Caches the names of the types that can be created as the root object.
89:          * <!-- begin-user-doc --> <!-- end-user-doc -->
90:          *
91:          * @generated
92:          */
93:         protected List<String> initialObjectNames;
94:
95:         private SelectEcorePage selectEcorePage;
96:         private SelectEStructuralFeatureWizardPage selectEClassPage;
97:         private EStructuralFeature selectedEStructuralFeature;
98:
99:         /**
100:          * This just records the information. <!-- begin-user-doc --> <!--
101:          * end-user-doc -->
102:          *
103:          * @generated
104:          */
105:         @Override
106:         public void init(IWorkbench workbench, IStructuredSelection selection) {
107:                 this.workbench = workbench;
108:                 this.selection = selection;
109:                 setWindowTitle(Messages.DMRCreationWizard_Title);
110:                 // setDefaultPageImageDescriptor();
111:         }
112:
113:         /**
114:          * The framework calls this to create the contents of the wizard. <!--
115:          * begin-user-doc --> <!-- end-user-doc -->
116:          *
117:          * @generated
118:          */
119:         @Override
120:         public void addPages() {
121:
122:                 selectEcorePage = new SelectEcorePage(PLUGIN_ID);
123:                 addPage(selectEcorePage);
124:                 selectEClassPage = new SelectEStructuralFeatureWizardPage();
125:                 addPage(selectEClassPage);
126:         }
127:
128:         /**
129:          * {@inheritDoc}
130:          *
131:          * @see org.eclipse.jface.wizard.Wizard#getStartingPage()
132:          */
133:         @Override
134:         public IWizardPage getStartingPage() {
135:•                if (selectedContainer == null) {
136:                         return selectEcorePage;
137:                 }
138:
139:                 return selectEClassPage;
140:         }
141:
142:         /**
143:          * {@inheritDoc}
144:          *
145:          * @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
146:          */
147:         @Override
148:         public IWizardPage getNextPage(IWizardPage page) {
149:
150:•                if (page == selectEcorePage) {
151:                         selectedContainer = selectEcorePage.getSelectedContainer();
152:•                        if (selectedContainer != null) {
153:                                 selectEClassPage.setSelectedEPackage(getEPackage());
154:                                 return selectEClassPage;
155:                         }
156:                         return null;
157:•                } else if (page == selectEClassPage) {
158:                         selectedEStructuralFeature = selectEClassPage.getEStructuralFeature();
159:
160:                 }
161:
162:                 return null;
163:         }
164:
165:         /**
166:          * @return
167:          */
168:         private EPackage getEPackage() {
169:                 EPackage ePackage = null;
170:•                if (EPackage.class.isInstance(selectedContainer)) {
171:                         ePackage = EPackage.class.cast(selectedContainer);
172:•                } else if (IFile.class.isInstance(selectedContainer)) {
173:                         final ResourceSetImpl resourceSet = new ResourceSetImpl();
174:                         final String path = ((IFile) selectedContainer).getFullPath().toString();
175:                         final URI uri = URI.createPlatformResourceURI(path, true);
176:
177:                         final Resource resource = resourceSet.getResource(uri, true);
178:•                        if (resource != null) {
179:
180:                                 final EList<EObject> contents = resource.getContents();
181:•                                if (contents.size() != 1) {
182:                                         return null;
183:                                 }
184:
185:                                 final EObject object = contents.get(0);
186:•                                if (!(object instanceof EPackage)) {
187:                                         return null;
188:                                 }
189:
190:                                 ePackage = (EPackage) object;
191:                         }
192:                 }
193:                 return ePackage;
194:
195:         }
196:
197:         /**
198:          * {@inheritDoc}
199:          *
200:          * @see org.eclipse.jface.wizard.Wizard#getPreviousPage(org.eclipse.jface.wizard.IWizardPage)
201:          */
202:         @Override
203:         public IWizardPage getPreviousPage(IWizardPage page) {
204:
205:•                if (page == selectEClassPage) {
206:                         return selectEcorePage;
207:                 }
208:
209:                 return null;
210:
211:         }
212:
213:         /**
214:          * {@inheritDoc}
215:          *
216:          * @see org.eclipse.jface.wizard.Wizard#canFinish()
217:          */
218:         @Override
219:         public boolean canFinish() {
220:•                if (selectEClassPage != null) {
221:                         selectedEStructuralFeature = selectEClassPage.getEStructuralFeature();
222:•                        return selectedEStructuralFeature != null;
223:                 }
224:                 return false;
225:         }
226:
227:         @Override
228:         public boolean performFinish() {
229:                 return true;
230:         }
231:
232:         public IFile getSelectedEcore() {
233:•                if (IFile.class.isInstance(selectedContainer)) {
234:                         return (IFile) selectedContainer;
235:                 }
236:                 return null;
237:         }
238:
239:         public EStructuralFeature getSelectedEStructuralFeature() {
240:                 return selectedEStructuralFeature;
241:         }
242:
243: }