Skip to content

Package: EMFFormsTemplateWizard$2

EMFFormsTemplateWizard$2

nameinstructionbranchcomplexitylinemethod
run(IProgressMonitor)
M: 6 C: 12
67%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 4
80%
M: 0 C: 1
100%
{...}
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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.tooling.wizards;
15:
16: import java.io.ByteArrayInputStream;
17: import java.io.IOException;
18: import java.lang.reflect.InvocationTargetException;
19: import java.util.ArrayList;
20: import java.util.Collections;
21: import java.util.List;
22:
23: import javax.xml.parsers.DocumentBuilder;
24: import javax.xml.parsers.DocumentBuilderFactory;
25: import javax.xml.parsers.ParserConfigurationException;
26: import javax.xml.transform.OutputKeys;
27: import javax.xml.transform.Transformer;
28: import javax.xml.transform.TransformerException;
29: import javax.xml.transform.TransformerFactory;
30: import javax.xml.transform.dom.DOMSource;
31: import javax.xml.transform.stream.StreamResult;
32:
33: import org.eclipse.core.resources.IContainer;
34: import org.eclipse.core.resources.IFile;
35: import org.eclipse.core.resources.IProject;
36: import org.eclipse.core.resources.IResource;
37: import org.eclipse.core.resources.IWorkspaceRoot;
38: import org.eclipse.core.resources.ResourcesPlugin;
39: import org.eclipse.core.runtime.CoreException;
40: import org.eclipse.core.runtime.IProgressMonitor;
41: import org.eclipse.core.runtime.IStatus;
42: import org.eclipse.core.runtime.Path;
43: import org.eclipse.core.runtime.Status;
44: import org.eclipse.emf.common.command.Command;
45: import org.eclipse.emf.common.command.CompoundCommand;
46: import org.eclipse.emf.common.util.TreeIterator;
47: import org.eclipse.emf.common.util.URI;
48: import org.eclipse.emf.ecore.EClass;
49: import org.eclipse.emf.ecore.EObject;
50: import org.eclipse.emf.ecore.resource.Resource;
51: import org.eclipse.emf.ecore.resource.ResourceSet;
52: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
53: import org.eclipse.emf.ecore.util.EcoreUtil;
54: import org.eclipse.emf.ecore.xmi.XMLResource;
55: import org.eclipse.emf.ecp.view.spi.model.VControl;
56: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
57: import org.eclipse.emf.ecp.view.spi.model.VElement;
58: import org.eclipse.emf.ecp.view.spi.model.VView;
59: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
60: import org.eclipse.emf.ecp.view.spi.model.util.VViewResourceImpl;
61: import org.eclipse.emf.ecp.view.template.internal.tooling.Activator;
62: import org.eclipse.emf.ecp.view.template.internal.tooling.Messages;
63: import org.eclipse.emf.ecp.view.template.model.VTStyle;
64: import org.eclipse.emf.ecp.view.template.model.VTStyleSelector;
65: import org.eclipse.emf.ecp.view.template.model.VTTemplateFactory;
66: import org.eclipse.emf.ecp.view.template.model.VTTemplatePackage;
67: import org.eclipse.emf.ecp.view.template.model.VTViewTemplate;
68: import org.eclipse.emf.ecp.view.template.selector.domainmodelreference.model.VTDomainModelReferenceSelector;
69: import org.eclipse.emf.ecp.view.template.selector.domainmodelreference.model.VTDomainmodelreferencePackage;
70: import org.eclipse.emf.ecp.view.template.selector.viewModelElement.model.VTViewModelElementPackage;
71: import org.eclipse.emf.ecp.view.template.selector.viewModelElement.model.VTViewModelElementSelector;
72: import org.eclipse.emf.ecp.view.template.tooling.editor.TemplateModelEditorPart;
73: import org.eclipse.emf.edit.command.AddCommand;
74: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
75: import org.eclipse.emf.edit.domain.EditingDomain;
76: import org.eclipse.emfforms.common.Optional;
77: import org.eclipse.jface.dialogs.ErrorDialog;
78: import org.eclipse.jface.dialogs.MessageDialog;
79: import org.eclipse.jface.operation.IRunnableWithProgress;
80: import org.eclipse.jface.viewers.ISelection;
81: import org.eclipse.jface.viewers.IStructuredSelection;
82: import org.eclipse.jface.wizard.IWizardPage;
83: import org.eclipse.jface.wizard.Wizard;
84: import org.eclipse.ui.IEditorPart;
85: import org.eclipse.ui.INewWizard;
86: import org.eclipse.ui.IPartListener2;
87: import org.eclipse.ui.IWorkbench;
88: import org.eclipse.ui.IWorkbenchPage;
89: import org.eclipse.ui.IWorkbenchPartReference;
90: import org.eclipse.ui.PartInitException;
91: import org.eclipse.ui.PlatformUI;
92: import org.eclipse.ui.ide.IDE;
93: import org.w3c.dom.Document;
94: import org.w3c.dom.Element;
95: import org.xml.sax.SAXException;
96:
97: /**
98: * This is a sample new wizard. Its role is to create a new file
99: * resource in the provided container. If the container resource
100: * (a folder or a project) is selected in the workspace
101: * when the wizard is opened, it will accept it as the target
102: * container. The wizard creates one file with the extension
103: * "template". If a sample multi-page editor (also available
104: * as a template) is registered for the same extension, it will
105: * be able to open it.
106: */
107:
108: public class EMFFormsTemplateWizard extends Wizard implements INewWizard {
109:
110:         private ISelection selection;
111:
112:         private final Optional<VElement> vElement;
113:
114:         private Optional<EMFFormsChooseTemplateWizardPage> choosePage = Optional.empty();
115:         private Optional<EMFFormsNewTemplateWizardPage> newPage = Optional.empty();
116:         private Optional<EMFFormsSelectTemplateWizardPage> selectPage = Optional.empty();
117:         private Optional<EMFFormsStyleSelectorWizardPage> selectorPage = Optional.empty();
118:
119:         /**
120:          * Constructor for EMFFormsTemplateWizard. This wizard allows you to create a new template model.
121:          */
122:         public EMFFormsTemplateWizard() {
123:                 this(null);
124:         }
125:
126:         /**
127:          * Constructs a wizard which will help you to create styles for the {@link VElement}. The style may be added to a
128:          * new template model or to an existing one.
129:          *
130:          * @param vElement the element
131:          */
132:         public EMFFormsTemplateWizard(VElement vElement) {
133:                 super();
134:                 setNeedsProgressMonitor(true);
135:                 this.vElement = Optional.ofNullable(vElement);
136:
137:         }
138:
139:         /**
140:          * Adding the paged to the wizard. If a {@link VElement} was passed to the constructor creating a style is enabled.
141:          */
142:         @Override
143:         public void addPages() {
144:                 if (vElement.isPresent()) {
145:                         choosePage = Optional.of(new EMFFormsChooseTemplateWizardPage());
146:                         addPage(choosePage.get());
147:                 }
148:
149:                 newPage = Optional.of(new EMFFormsNewTemplateWizardPage(selection));
150:                 addPage(newPage.get());
151:
152:                 if (vElement.isPresent()) {
153:                         selectPage = Optional.of(new EMFFormsSelectTemplateWizardPage());
154:                         addPage(selectPage.get());
155:                 }
156:
157:                 if (vElement.isPresent()) {
158:                         selectorPage = Optional.of(new EMFFormsStyleSelectorWizardPage(VControl.class.isInstance(vElement.get())));
159:                         addPage(selectorPage.get());
160:                 }
161:         }
162:
163:         @Override
164:         public IWizardPage getNextPage(IWizardPage page) {
165:                 /*
166:                  * if we may choose between creating a new template model or an existing one show the new page or the select
167:                  * page accordingly
168:                  */
169:                 if (choosePage.isPresent() && page == choosePage.get()) {
170:                         if (choosePage.get().createNewTemplate()) {
171:                                 return newPage.get();
172:                         }
173:                         return selectPage.get();
174:                 }
175:
176:                 /* if we allow to create a style (selector page is present) show the selector page after the new/select page */
177:                 if (newPage.isPresent() && page == newPage.get() ||
178:                         selectPage.isPresent() && page == selectPage.get()) {
179:                         if (selectorPage.isPresent()) {
180:                                 return selectorPage.get();
181:                         }
182:                         return null;
183:                 }
184:
185:                 return super.getNextPage(page);
186:         }
187:
188:         @Override
189:         public boolean canFinish() {
190:                 if (!vElement.isPresent()) {
191:                         /* we only have one page (new) -> super call is sufficient */
192:                         return super.canFinish();
193:                 }
194:                 /* otherwise check if all pages are filled as expected */
195:                 for (int i = 0; i < getPages().length; i++) {
196:                         final IWizardPage page = getPages()[i];
197:                         if (choosePage.get().createNewTemplate() && selectPage.get() == page) {
198:                                 continue;
199:                         }
200:                         if (!choosePage.get().createNewTemplate() && newPage.get() == page) {
201:                                 continue;
202:                         }
203:                         if (!page.isPageComplete()) {
204:                                 return false;
205:                         }
206:                 }
207:                 return true;
208:         }
209:
210:         @Override
211:         public boolean performFinish() {
212:                 if (!vElement.isPresent()) {
213:                         /* we dont allow to create a style -> simply create a new template */
214:                         return performFinishNewPage();
215:                 }
216:
217:                 /*
218:                  * register a listener on the active page. once the template editor shows, we will access the template and add
219:                  * the style we created. The editor will become dirty because of this, so the user may still discard/undo the
220:                  * change.
221:                  */
222:                 final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
223:                 activePage.addPartListener(new AddToTemplatePartListener(activePage));
224:
225:                 /* (create template and) open editor */
226:                 if (choosePage.get().createNewTemplate()) {
227:                         if (!performFinishNewPage()) {
228:                                 return false;
229:                         }
230:                 } else {
231:                         /* open the editor for the existing template model */
232:                         final IFile resource = (IFile) ResourcesPlugin.getWorkspace().getRoot()
233:                                 .findMember(selectPage.get().getTemplateName());
234:                         getShell().getDisplay().asyncExec(new Runnable() {
235:                                 @Override
236:                                 public void run() {
237:                                         final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
238:                                         try {
239:                                                 IDE.openEditor(page, resource, true);
240:                                         } catch (final PartInitException e) {
241:                                                 ErrorDialog.openError(
242:                                                         getShell(),
243:                                                         Messages.EMFFormsTemplateWizard_OpenEditorFailTitle,
244:                                                         Messages.EMFFormsTemplateWizard_OpenEditorFailMessage,
245:                                                         new Status(
246:                                                                 IStatus.ERROR,
247:                                                                 Activator.PLUGIN_ID,
248:                                                                 e.getMessage(),
249:                                                                 e));
250:                                         }
251:                                 }
252:                         });
253:                 }
254:                 return true;
255:         }
256:
257:         private boolean addStyleToTemplate(
258:                 final VTStyleSelector styleSelector,
259:                 final TemplateModelEditorPart templateEditor) {
260:
261:                 final VTViewTemplate template = templateEditor.getTemplate();
262:                 if (template == null) {
263:                         return false;
264:                 }
265:
266:                 /*
267:                  * We must set the root e class for a dmr selector.
268:                  * This must be done before checking whether it is present to ensure an equivalent selector is found.
269:                  */
270:                 if (VTDomainModelReferenceSelector.class.isInstance(styleSelector)) {
271:                         VTDomainModelReferenceSelector.class.cast(styleSelector).setRootEClass(getView().getRootEClass());
272:                 }
273:
274:                 /* check if there is a style with the same selector already present */
275:                 final TreeIterator<EObject> templateContents = EcoreUtil.getAllContents(template, true);
276:                 while (templateContents.hasNext()) {
277:                         final EObject next = templateContents.next();
278:                         if (!VTStyleSelector.class.isInstance(next)) {
279:                                 continue;
280:                         }
281:                         if (EcoreUtil.equals(next, styleSelector)) {
282:                                 /* we have found a style. instead of creating a second style, reveal the existing one. */
283:                                 templateEditor.reveal(next);
284:                                 return true;
285:                         }
286:                 }
287:
288:                 /* we have to create a new style */
289:                 final VTStyle style = VTTemplateFactory.eINSTANCE.createStyle();
290:                 style.setSelector(styleSelector);
291:
292:                 final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(template);
293:                 Command command = AddCommand.create(domain, template,
294:                         VTTemplatePackage.eINSTANCE.getViewTemplate_Styles(), style);
295:
296:                 if (VTDomainModelReferenceSelector.class.isInstance(styleSelector)) {
297:                         command = addEcorePathIfRequired(template, domain, command, getView());
298:                 }
299:
300:                 if (!command.canExecute()) {
301:                         return false;
302:                 }
303:                 domain.getCommandStack().execute(command);
304:                 templateEditor.reveal(styleSelector);
305:
306:                 return true;
307:         }
308:
309:         /**
310:          * @return the {@link VView} containing the {@link VElement}.
311:          */
312:         private VView getView() {
313:                 EObject view = vElement.get();
314:                 while (!VView.class.isInstance(view) && view != null) {
315:                         view = view.eContainer();
316:                 }
317:                 return VView.class.cast(view);
318:         }
319:
320:         private Command addEcorePathIfRequired(
321:                 final VTViewTemplate template,
322:                 final EditingDomain domain,
323:                 Command command,
324:                 EObject view) {
325:                 if (view == null) {
326:                         return command;
327:                 }
328:
329:                 final List<Command> ecorePathCommands = new ArrayList<Command>();
330:                 ecorePathCommands.add(command);
331:
332:                 for (final String ecorePaths : VView.class.cast(view).getEcorePaths()) {
333:                         if (template.getReferencedEcores().contains(ecorePaths)) {
334:                                 continue;
335:                         }
336:                         ecorePathCommands.add(
337:                                 AddCommand.create(domain, template,
338:                                         VTTemplatePackage.eINSTANCE.getViewTemplate_ReferencedEcores(), ecorePaths));
339:                 }
340:
341:                 if (ecorePathCommands.size() > 1) {
342:                         return new CompoundCommand(ecorePathCommands);
343:                 }
344:                 return command;
345:
346:         }
347:
348:         private boolean performFinishNewPage() {
349:                 final String containerName = newPage.get().getContainerName();
350:                 final String fileName = newPage.get().getFileName();
351:                 final IRunnableWithProgress op = new IRunnableWithProgress() {
352:                         @Override
353:                         public void run(IProgressMonitor monitor) throws InvocationTargetException {
354:                                 try {
355:                                         doFinish(containerName, fileName, monitor);
356:                                 } catch (final CoreException e) {
357:                                         throw new InvocationTargetException(e);
358:                                 } finally {
359:                                         monitor.done();
360:                                 }
361:                         }
362:                 };
363:                 try {
364:                         getContainer().run(true, false, op);
365:                 } catch (final InterruptedException e) {
366:                         return false;
367:                 } catch (final InvocationTargetException e) {
368:                         final Throwable realException = e.getTargetException();
369:                         MessageDialog.openError(getShell(), Messages.EMFFormsTemplateWizard_errorTitle, realException.getMessage());
370:                         return false;
371:                 }
372:                 return true;
373:         }
374:
375:         private void addToPluginXML(IFile modelFile, IProgressMonitor monitor) {
376:                 final IProject project = modelFile.getProject();
377:                 final IFile pluginFile = project.getFile("plugin.xml"); //$NON-NLS-1$
378:
379:                 try {
380:                         if (!pluginFile.exists()) {
381:                                 final String pluginXmlContents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?eclipse version=\"3.4\"?>\n<plugin>\n</plugin>"; //$NON-NLS-1$
382:                                 pluginFile.create(new ByteArrayInputStream(pluginXmlContents.getBytes()), true, null);
383:                                 project.refreshLocal(IResource.DEPTH_INFINITE, null);
384:                         }
385:                         final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
386:                         final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
387:                         final Document doc = dBuilder.parse(pluginFile.getLocationURI().toString());
388:                         final Element element = doc.createElement("extension"); //$NON-NLS-1$
389:                         element.setAttribute("point", "org.eclipse.emf.ecp.view.template"); //$NON-NLS-1$ //$NON-NLS-2$
390:                         final Element templateElement = doc.createElement("viewTemplate"); //$NON-NLS-1$
391:                         templateElement.setAttribute("xmi", modelFile.getProjectRelativePath().toString()); //$NON-NLS-1$
392:                         element.appendChild(templateElement);
393:                         doc.getDocumentElement().appendChild(element);
394:
395:                         final Transformer tf = TransformerFactory.newInstance().newTransformer();
396:                         tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
397:                         tf.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
398:                         final StreamResult file = new StreamResult(pluginFile.getLocation().toFile());
399:                         tf.transform(new DOMSource(doc), file);
400:                 } catch (final SAXException ex) {
401:                         Activator.log(ex);
402:                 } catch (final IOException ex) {
403:                         Activator.log(ex);
404:                 } catch (final ParserConfigurationException ex) {
405:                         Activator.log(ex);
406:                 } catch (final TransformerException ex) {
407:                         Activator.log(ex);
408:                 } catch (final CoreException ex) {
409:                         Activator.log(ex);
410:                 }
411:         }
412:
413:         /**
414:          * The worker method. It will find the container, create the
415:          * file if missing or just replace its contents, and open
416:          * the editor on the newly created file.
417:          */
418:
419:         private void doFinish(
420:                 String containerName,
421:                 String fileName,
422:                 IProgressMonitor monitor)
423:                 throws CoreException {
424:                 // create a sample file
425:                 monitor.beginTask(Messages.EMFFormsTemplateWizard_creatingTask + fileName, 2);
426:                 final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
427:                 final IResource resource = root.findMember(new Path(containerName));
428:                 if (!resource.exists() || !(resource instanceof IContainer)) {
429:                         throwCoreException(String.format("Container \"%s\" does not exist.", containerName)); //$NON-NLS-1$
430:                 }
431:                 final IContainer container = (IContainer) resource;
432:                 final IFile file = container.getFile(new Path(fileName));
433:                 try {
434:                         final VTViewTemplate template = VTTemplateFactory.eINSTANCE.createViewTemplate();
435:
436:                         final ResourceSet rs = new ResourceSetImpl();
437:                         final Resource templateResource = rs.createResource(URI.createURI(file.getLocationURI().toString()));
438:                         templateResource.getContents().add(template);
439:                         templateResource.save(Collections.singletonMap(XMLResource.OPTION_ENCODING, "UTF-8")); //$NON-NLS-1$
440:                         container.refreshLocal(IResource.DEPTH_ONE, monitor);
441:                 } catch (final IOException e) {
442:
443:                 }
444:                 monitor.worked(1);
445:                 monitor.setTaskName(Messages.EMFFormsTemplateWizard_editingTask);
446:                 getShell().getDisplay().asyncExec(new Runnable() {
447:                         @Override
448:                         public void run() {
449:                                 final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
450:                                 try {
451:                                         IDE.openEditor(page, file, true);
452:                                 } catch (final PartInitException e) {
453:                                 }
454:                         }
455:                 });
456:                 monitor.worked(1);
457:                 addToPluginXML(file, monitor);
458:         }
459:
460:         private void throwCoreException(String message) throws CoreException {
461:                 final IStatus status = new Status(IStatus.ERROR, "org.eclipse.emf.ecp.view.template.tooling", IStatus.OK, //$NON-NLS-1$
462:                         message, null);
463:                 throw new CoreException(status);
464:         }
465:
466:         @Override
467:         public void init(IWorkbench workbench, IStructuredSelection selection) {
468:                 this.selection = selection;
469:         }
470:
471:         private static Optional<String> getUUID(VElement vElement) {
472:                 final Resource eResource = vElement.eResource();
473:                 if (!VViewResourceImpl.class.isInstance(eResource)) {
474:                         return Optional.empty();
475:                 }
476:                 return Optional.ofNullable(VViewResourceImpl.class.cast(eResource).getID(vElement));
477:         }
478:
479:         /**
480:          * Listener which waits for the template editor to open and add a style to it.
481:          *
482:          * @author Johannes Faltermeier
483:          *
484:          */
485:         private final class AddToTemplatePartListener implements IPartListener2 {
486:                 private final IWorkbenchPage activePage;
487:
488:                 /**
489:                  * @param activePage
490:                  */
491:                 private AddToTemplatePartListener(IWorkbenchPage activePage) {
492:                         this.activePage = activePage;
493:                 }
494:
495:                 @Override
496:                 public void partVisible(IWorkbenchPartReference partRef) {
497:                         /* no op */
498:                 }
499:
500:                 @Override
501:                 public void partOpened(IWorkbenchPartReference partRef) {
502:                         /* no op */
503:                 }
504:
505:                 @Override
506:                 public void partInputChanged(IWorkbenchPartReference partRef) {
507:                         /* no op */
508:                 }
509:
510:                 @Override
511:                 public void partHidden(IWorkbenchPartReference partRef) {
512:                         /* no op */
513:                 }
514:
515:                 @Override
516:                 public void partDeactivated(IWorkbenchPartReference partRef) {
517:                         /* no op */
518:                 }
519:
520:                 @Override
521:                 public void partClosed(IWorkbenchPartReference partRef) {
522:                         /* no op */
523:                 }
524:
525:                 @Override
526:                 public void partBroughtToTop(IWorkbenchPartReference partRef) {
527:                         /* no op */
528:                 }
529:
530:                 @Override
531:                 public void partActivated(IWorkbenchPartReference partRef) {
532:                         if (!"org.eclipse.emf.ecp.view.template.tooling.editor".equals(partRef.getId())) { //$NON-NLS-1$
533:                                 return;
534:                         }
535:
536:                         activePage.removePartListener(this);
537:
538:                         EClass selectorEClass = VTViewModelElementPackage.eINSTANCE.getViewModelElementSelector();
539:                         Optional<Boolean> useUUID = Optional.empty();
540:                         if (selectorPage.isPresent()) {
541:                                 selectorEClass = selectorPage.get().getSelectorEClass();
542:                                 useUUID = selectorPage.get().getUseUUID();
543:                         }
544:
545:                         final VTStyleSelector styleSelector = (VTStyleSelector) EcoreUtil.create(selectorEClass);
546:                         if (selectorEClass == VTViewModelElementPackage.eINSTANCE.getViewModelElementSelector()) {
547:                                 final VTViewModelElementSelector selector = VTViewModelElementSelector.class.cast(styleSelector);
548:                                 selector.setClassType(vElement.get().eClass());
549:                                 if (useUUID.isPresent() && useUUID.get()) {
550:                                         final Optional<String> uuid = getUUID(vElement.get());
551:                                         if (uuid.isPresent()) {
552:                                                 selector.setAttribute(VViewPackage.eINSTANCE.getElement_Uuid());
553:                                                 selector.setAttributeValue(uuid.get());
554:                                         }
555:                                 }
556:                         } else if (selectorEClass == VTDomainmodelreferencePackage.eINSTANCE
557:                                 .getDomainModelReferenceSelector()) {
558:                                 final VTDomainModelReferenceSelector selector = VTDomainModelReferenceSelector.class
559:                                         .cast(styleSelector);
560:                                 final VDomainModelReference dmr = VControl.class.cast(vElement.get()).getDomainModelReference();
561:                                 selector.setDomainModelReference(EcoreUtil.copy(dmr));
562:                         }
563:
564:                         final IEditorPart editor = activePage.getActiveEditor();
565:                         final TemplateModelEditorPart templateEditor = TemplateModelEditorPart.class.cast(editor);
566:                         addStyleToTemplate(styleSelector, templateEditor);
567:                 }
568:
569:         }
570: }