Skip to content

Package: DomainModelReferenceControlSWTRenderer$3

DomainModelReferenceControlSWTRenderer$3

nameinstructionbranchcomplexitylinemethod
convert(Object)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
{...}
M: 0 C: 6
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-2019 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: * Lucas Koehler - Also support DMR segments (Bug 542669)
14: * Christian W. Damus - bugs 527686, 548592
15: ******************************************************************************/
16: package org.eclipse.emf.ecp.view.internal.editor.controls;
17:
18: import java.text.MessageFormat;
19: import java.util.Collection;
20: import java.util.HashSet;
21:
22: import javax.inject.Inject;
23:
24: import org.eclipse.core.databinding.Binding;
25: import org.eclipse.core.databinding.DataBindingContext;
26: import org.eclipse.core.databinding.UpdateValueStrategy;
27: import org.eclipse.core.databinding.observable.IObserving;
28: import org.eclipse.core.databinding.observable.value.IObservableValue;
29: import org.eclipse.emf.common.command.Command;
30: import org.eclipse.emf.common.notify.AdapterFactory;
31: import org.eclipse.emf.common.notify.Notification;
32: import org.eclipse.emf.common.util.EList;
33: import org.eclipse.emf.databinding.IEMFValueProperty;
34: import org.eclipse.emf.ecore.EClass;
35: import org.eclipse.emf.ecore.EObject;
36: import org.eclipse.emf.ecore.EPackage;
37: import org.eclipse.emf.ecore.EReference;
38: import org.eclipse.emf.ecore.EStructuralFeature;
39: import org.eclipse.emf.ecore.resource.Resource;
40: import org.eclipse.emf.ecp.common.spi.EMFUtils;
41: import org.eclipse.emf.ecp.edit.internal.swt.SWTImageHelper;
42: import org.eclipse.emf.ecp.edit.spi.ReferenceService;
43: import org.eclipse.emf.ecp.edit.spi.swt.reference.DeleteReferenceAction;
44: import org.eclipse.emf.ecp.edit.spi.swt.reference.NewReferenceAction;
45: import org.eclipse.emf.ecp.edit.spi.util.ECPModelElementChangeListener;
46: import org.eclipse.emf.ecp.spi.common.ui.CompositeFactory;
47: import org.eclipse.emf.ecp.spi.common.ui.composites.SelectionComposite;
48: import org.eclipse.emf.ecp.view.internal.editor.handler.CreateDomainModelReferenceWizard;
49: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
50: import org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTControlSWTRenderer;
51: import org.eclipse.emf.ecp.view.spi.editor.controls.Helper;
52: import org.eclipse.emf.ecp.view.spi.label.model.VLabel;
53: import org.eclipse.emf.ecp.view.spi.model.VControl;
54: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
55: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
56: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
57: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
58: import org.eclipse.emf.ecp.view.spi.model.util.VViewResourceImpl;
59: import org.eclipse.emf.ecp.view.spi.rule.model.LeafCondition;
60: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
61: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
62: import org.eclipse.emf.edit.command.SetCommand;
63: import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
64: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
65: import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
66: import org.eclipse.emfforms.spi.common.report.ReportService;
67: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
68: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
69: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
70: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
71: import org.eclipse.emfforms.spi.core.services.editsupport.EMFFormsEditSupport;
72: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
73: import org.eclipse.emfforms.spi.ide.view.segments.ToolingModeUtil;
74: import org.eclipse.emfforms.spi.localization.LocalizationServiceHelper;
75: import org.eclipse.jface.action.Action;
76: import org.eclipse.jface.databinding.swt.ISWTObservableValue;
77: import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
78: import org.eclipse.jface.layout.GridDataFactory;
79: import org.eclipse.jface.layout.GridLayoutFactory;
80: import org.eclipse.jface.viewers.TreeViewer;
81: import org.eclipse.jface.wizard.WizardDialog;
82: import org.eclipse.swt.SWT;
83: import org.eclipse.swt.custom.StackLayout;
84: import org.eclipse.swt.events.SelectionAdapter;
85: import org.eclipse.swt.events.SelectionEvent;
86: import org.eclipse.swt.events.SelectionListener;
87: import org.eclipse.swt.widgets.Button;
88: import org.eclipse.swt.widgets.Composite;
89: import org.eclipse.swt.widgets.Control;
90: import org.eclipse.swt.widgets.Display;
91: import org.eclipse.swt.widgets.Label;
92:
93: /**
94: * Renderer for DomainModelReferences.
95: *
96: * @author Alexandra Buzila
97: *
98: */
99: public class DomainModelReferenceControlSWTRenderer extends SimpleControlSWTControlSWTRenderer {
100:
101:         private final EMFFormsEditSupport emfFormsEditSupport;
102:         private final EMFFormsDatabindingEMF emfFormsDatabindingEMF;
103:
104:         /**
105:          * Default constructor.
106:          *
107:          * @param vElement the view model element to be rendered
108:          * @param viewContext the view context
109:          * @param reportService The {@link ReportService}
110:          * @param emfFormsDatabindingEMF The {@link EMFFormsDatabinding}
111:          * @param emfFormsLabelProvider The {@link EMFFormsLabelProvider}
112:          * @param vtViewTemplateProvider The {@link VTViewTemplateProvider}
113:          * @param emfFormsEditSupport The {@link EMFFormsEditSupport}
114:          */
115:         @Inject
116:         public DomainModelReferenceControlSWTRenderer(VControl vElement, ViewModelContext viewContext,
117:                 ReportService reportService, EMFFormsDatabindingEMF emfFormsDatabindingEMF,
118:                 EMFFormsLabelProvider emfFormsLabelProvider, VTViewTemplateProvider vtViewTemplateProvider,
119:                 EMFFormsEditSupport emfFormsEditSupport) {
120:                 super(vElement, viewContext, reportService, emfFormsDatabindingEMF, emfFormsLabelProvider,
121:                         vtViewTemplateProvider);
122:                 this.emfFormsDatabindingEMF = emfFormsDatabindingEMF;
123:                 this.emfFormsEditSupport = emfFormsEditSupport;
124:         }
125:
126:         private Composite mainComposite;
127:         private StackLayout stackLayout;
128:         private Label unsetLabel;
129:         private EObject eObject;
130:         private EStructuralFeature structuralFeature;
131:         // private Setting setting;
132:         private ECPModelElementChangeListener modelElementChangeListener;
133:         private ComposedAdapterFactory composedAdapterFactory;
134:         private AdapterFactoryItemDelegator adapterFactoryItemDelegator;
135:         private Composite parentComposite;
136:         private Label setLabel;
137:         private Label imageLabel;
138:         private Composite contentSetComposite;
139:         private Button setBtn;
140:
141:         @Override
142:         protected Binding[] createBindings(Control control) throws DatabindingFailedException {
143:
144:                 final Binding[] bindings = new Binding[3];
145:                 final IObservableValue value = WidgetProperties.text().observe(setLabel);
146:
147:                 bindings[0] = getDataBindingContext().bindValue(value, getModelValue(),
148:                         withPreSetValidation(new UpdateValueStrategy() {
149:
150:                                 @Override
151:                                 public Object convert(Object value) { // target to model
152:                                         try {
153:                                                 return getModelValue().getValue();
154:                                         } catch (final DatabindingFailedException ex) {
155:                                                 getReportService().report(new DatabindingFailedReport(ex));
156:                                                 return null;
157:                                         }
158:                                 }
159:                         }), new UpdateValueStrategy() {// model to target
160:                                 @Override
161:                                 public Object convert(Object value) {
162:                                         updateChangeListener((EObject) value);
163:                                         return getText(value);
164:                                 }
165:                         });
166:
167:                 final IObservableValue imageValue = WidgetProperties.image().observe(imageLabel);
168:                 bindings[1] = getDataBindingContext().bindValue(imageValue, getModelValue(),
169:                         withPreSetValidation(new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)),
170:                         new UpdateValueStrategy() {
171:                                 @Override
172:                                 public Object convert(Object value) {
173:                                         return getImage(value);
174:                                 }
175:                         });
176:
177:                 final ISWTObservableValue setLabelTooltip = WidgetProperties.tooltipText().observe(setLabel);
178:                 bindings[2] = getDataBindingContext().bindValue(
179:                         setLabelTooltip,
180:                         getModelValue(),
181:                         withPreSetValidation(new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)),
182:                         new UpdateValueStrategy() {
183:                                 @Override
184:                                 public Object convert(Object value) {
185:                                         if (!EObject.class.isInstance(value)) {
186:                                                 return ""; //$NON-NLS-1$
187:                                         }
188:                                         final EObject eObject = EObject.class.cast(value);
189:                                         final Resource resource = eObject.eResource();
190:                                         if (!VViewResourceImpl.class.isInstance(resource)) {
191:                                                 return ""; //$NON-NLS-1$
192:                                         }
193:                                         final String id = VViewResourceImpl.class.cast(resource).getID(eObject);
194:                                         return MessageFormat.format("UUID: {0}", id); //$NON-NLS-1$
195:                                 }
196:                         });
197:                 return bindings;
198:         }
199:
200:         private Object getImage(Object value) {
201:                 final Object image = adapterFactoryItemDelegator.getImage(value);
202:                 return SWTImageHelper.getImage(image);
203:         }
204:
205:         // TODO this whole method is ugly as it has to many dependencies, the generating of the text should be delegated to
206:         // some service
207:         // BEGIN COMPLEX CODE
208:         private Object getText(Object object) {
209:                 if (ToolingModeUtil.isSegmentToolingEnabled()) {
210:                         return getTextForSegments((VDomainModelReference) object);
211:                 }
212:
213:                 VFeaturePathDomainModelReference modelReference = (VFeaturePathDomainModelReference) object;
214:                 if (VTableDomainModelReference.class.isInstance(modelReference)) {
215:                         VTableDomainModelReference tableRef = VTableDomainModelReference.class.cast(modelReference);
216:                         while (tableRef.getDomainModelReference() != null
217:                                 && VTableDomainModelReference.class.isInstance(tableRef.getDomainModelReference())) {
218:                                 tableRef = VTableDomainModelReference.class.cast(tableRef.getDomainModelReference());
219:                         }
220:                         modelReference = (VFeaturePathDomainModelReference) tableRef.getDomainModelReference();
221:                 }
222:                 if (modelReference == null) {
223:                         return null;
224:                 }
225:                 final EStructuralFeature value = modelReference.getDomainModelEFeature();
226:
227:                 String className = ""; //$NON-NLS-1$
228:                 final String attributeName = " -> " + adapterFactoryItemDelegator.getText(value); //$NON-NLS-1$
229:                 String referencePath = ""; //$NON-NLS-1$
230:
231:                 for (final EReference ref : modelReference.getDomainModelEReferencePath()) {
232:                         if (className.isEmpty()) {
233:                                 className = ref.getEContainingClass().getName();
234:                         }
235:                         referencePath = referencePath + " -> " + adapterFactoryItemDelegator.getText(ref); //$NON-NLS-1$
236:                 }
237:                 if (className.isEmpty() && modelReference.getDomainModelEFeature() != null
238:                         && modelReference.getDomainModelEFeature().getEContainingClass() != null) {
239:                         className = modelReference.getDomainModelEFeature().getEContainingClass().getName();
240:                 }
241:
242:                 final String linkText = className + referencePath + attributeName;
243:                 if (linkText.equals(" -> ")) { //$NON-NLS-1$
244:                         return null;
245:                 }
246:                 return linkText;
247:         }
248:         // END COMPLEX CODE
249:
250:         /**
251:          * Provides a label text for a segment based DMR.
252:          */
253:         private String getTextForSegments(VDomainModelReference dmr) {
254:                 final EList<VDomainModelReferenceSegment> segments = dmr.getSegments();
255:                 if (segments.isEmpty()) {
256:                         return adapterFactoryItemDelegator.getText(dmr);
257:                 }
258:
259:                 String attributeType = null;
260:                 final EClass rootEClass = getDmrRootEClass();
261:                 try {
262:                         final IEMFValueProperty valueProperty = emfFormsDatabindingEMF.getValueProperty(
263:                                 dmr, rootEClass);
264:                         attributeType = valueProperty.getStructuralFeature().getEType().getName();
265:                 } catch (final DatabindingFailedException ex) {
266:                         // TODO handle?
267:                 }
268:
269:                 final String className = rootEClass.getName();
270:                 String attributeName = " -> " + adapterFactoryItemDelegator.getText(segments.get(segments.size() - 1)); //$NON-NLS-1$
271:                 if (attributeType != null && !attributeType.isEmpty()) {
272:                         attributeName += " : " + attributeType; //$NON-NLS-1$
273:                 }
274:                 String referencePath = ""; //$NON-NLS-1$
275:
276:                 for (int i = 0; i < segments.size() - 1; i++) {
277:                         referencePath = referencePath + " -> " //$NON-NLS-1$
278:                                 + adapterFactoryItemDelegator.getText(segments.get(i));
279:                 }
280:
281:                 final String linkText = className + referencePath + attributeName;
282:                 if (linkText.equals(" -> ")) { //$NON-NLS-1$
283:                         return null;
284:                 }
285:                 return linkText;
286:         }
287:
288:         private void updateChangeListener(final EObject value) {
289:                 if (modelElementChangeListener != null) {
290:                         if (modelElementChangeListener.getTarget().equals(value)) {
291:                                 return;
292:                         }
293:                         modelElementChangeListener.remove();
294:                         modelElementChangeListener = null;
295:                 }
296:
297:                 if (value == null) {
298:                         if (stackLayout.topControl != unsetLabel) {
299:                                 stackLayout.topControl = unsetLabel;
300:                                 mainComposite.layout();
301:                         }
302:
303:                 } else {
304:                         if (stackLayout.topControl != contentSetComposite) {
305:                                 stackLayout.topControl = contentSetComposite;
306:                                 mainComposite.layout();
307:                         }
308:
309:                         modelElementChangeListener = new ECPModelElementChangeListener(value) {
310:
311:                                 @Override
312:                                 public void onChange(Notification notification) {
313:                                         Display.getDefault().syncExec(() -> getDataBindingContext().updateTargets());
314:                                 }
315:                         };
316:                 }
317:         }
318:
319:         @Override
320:         protected Control createSWTControl(Composite parent) throws DatabindingFailedException {
321:                 final IObservableValue<?> observableValue = getEMFFormsDatabinding()
322:                         .getObservableValue(getVElement().getDomainModelReference(), getViewModelContext().getDomainModel());
323:                 eObject = (EObject) ((IObserving) observableValue).getObserved();
324:                 structuralFeature = (EStructuralFeature) observableValue.getValueType();
325:                 observableValue.dispose();
326:
327:                 final Composite containerComposite = new Composite(parent, SWT.NONE);
328:                 containerComposite.setBackground(parent.getBackground());
329:                 GridLayoutFactory.fillDefaults().applyTo(containerComposite);
330:                 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(containerComposite);
331:
332:                 parentComposite = new Composite(containerComposite, SWT.NONE);
333:                 parentComposite.setBackground(parent.getBackground());
334:                 GridLayoutFactory.fillDefaults().numColumns(4).spacing(0, 0).equalWidth(false)
335:                         .applyTo(parentComposite);
336:                 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(parentComposite);
337:
338:                 stackLayout = new StackLayout();
339:
340:                 mainComposite = new Composite(parentComposite, SWT.NONE);
341:                 mainComposite.setBackground(parentComposite.getBackground());
342:                 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(mainComposite);
343:                 mainComposite.setLayout(stackLayout);
344:
345:                 unsetLabel = new Label(mainComposite, SWT.NONE);
346:                 GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(unsetLabel);
347:                 unsetLabel.setText(
348:                         LocalizationServiceHelper.getString(DomainModelReferenceControlSWTRenderer.class, "LinkControl_NotSet")); //$NON-NLS-1$
349:                 unsetLabel.setBackground(mainComposite.getBackground());
350:                 unsetLabel.setForeground(parentComposite.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
351:                 unsetLabel.setAlignment(SWT.CENTER);
352:
353:                 contentSetComposite = new Composite(mainComposite, SWT.NONE);
354:                 GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(contentSetComposite);
355:                 contentSetComposite.setBackground(mainComposite.getBackground());
356:                 imageLabel = new Label(contentSetComposite, SWT.NONE);
357:                 imageLabel.setBackground(contentSetComposite.getBackground());
358:                 GridDataFactory.fillDefaults().grab(false, false).align(SWT.FILL, SWT.FILL).hint(17, SWT.DEFAULT)
359:                         .applyTo(imageLabel);
360:                 setLabel = new Label(contentSetComposite, SWT.NONE);
361:                 setLabel.setBackground(contentSetComposite.getBackground());
362:                 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(setLabel);
363:
364:                 if (eObject.eIsSet(structuralFeature)) {
365:                         stackLayout.topControl = contentSetComposite;
366:                 } else {
367:                         stackLayout.topControl = unsetLabel;
368:                 }
369:
370:                 createButtons(parentComposite);
371:
372:                 composedAdapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
373:                         new ReflectiveItemProviderAdapterFactory(),
374:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) });
375:                 adapterFactoryItemDelegator = new AdapterFactoryItemDelegator(composedAdapterFactory);
376:
377:                 return containerComposite;
378:         }
379:
380:         /**
381:          * @param parentComposite
382:          * @throws DatabindingFailedException
383:          */
384:         private void createButtons(Composite composite) throws DatabindingFailedException {
385:                 final Button unsetBtn = createButtonForAction(new DeleteReferenceAction(getEditingDomain(eObject), eObject,
386:                         structuralFeature, null), composite);
387:                 unsetBtn.addSelectionListener(new SelectionListener() {
388:
389:                         @Override
390:                         public void widgetSelected(SelectionEvent e) {
391:                                 final Command setCommand = SetCommand.create(getEditingDomain(eObject), eObject, structuralFeature,
392:                                         SetCommand.UNSET_VALUE);
393:                                 getEditingDomain(eObject).getCommandStack().execute(setCommand);
394:                         }
395:
396:                         @Override
397:                         public void widgetDefaultSelected(SelectionEvent e) {
398:                                 // TODO Auto-generated method stub
399:                         }
400:                 });
401:
402:                 setBtn = createButtonForAction(new NewReferenceAction(getEditingDomain(eObject), eObject,
403:                         structuralFeature, emfFormsEditSupport, getEMFFormsLabelProvider(), null, getReportService(), getVElement()
404:                                 .getDomainModelReference(),
405:                         getViewModelContext().getDomainModel()), composite); // getViewModelContext().getService(ReferenceService.class)
406:                 setBtn.addSelectionListener(new SelectionAdapterExtension(setLabel, getModelValue(), getViewModelContext(),
407:                         getDataBindingContext(), (EReference) structuralFeature));
408:
409:         }
410:
411:         /**
412:          * A helper method which creates a button for an action on a composite.
413:          *
414:          * @param action the action to create a button for
415:          * @param composite the composite to create the button onto
416:          * @return the created button
417:          */
418:         protected Button createButtonForAction(final Action action, final Composite composite) {
419:                 final Button selectButton = new Button(composite, SWT.PUSH);
420:                 selectButton.setImage(Activator.getImage(action));
421:                 selectButton.setEnabled(true);
422:                 selectButton.setToolTipText(action.getToolTipText());
423:                 return selectButton;
424:         }
425:
426:         @Override
427:         protected String getUnsetText() {
428:                 return LocalizationServiceHelper.getString(getClass(), "LinkControl_NoLinkSetClickToSetLink"); //$NON-NLS-1$
429:         }
430:
431:         /**
432:          * Create a new segment based domain model reference and set it in the <code>reference</code> of the given
433:          * <code>container</code> object.
434:          *
435:          * @param container The EObject which will contain the new domain model reference
436:          * @param reference The EReference which the new domain model reference will be set in
437:          */
438:         protected void addNewSegmentDmr(EObject container, EReference reference) {
439:                 final ReferenceService referenceService = getViewModelContext().getService(ReferenceService.class);
440:                 referenceService.addNewModelElements(eObject, (EReference) structuralFeature, false);
441:         }
442:
443:         /**
444:          * Edits the existing DMR set in the <code>reference</code> of the given
445:          * <code>container</code> object.
446:          *
447:          * @param container The EObject which will contain the new domain model reference
448:          * @param reference The EReference which contains the current new domain model reference
449:          * @param dmr The domain model reference to edit
450:          */
451:         protected void editSegmentDmr(EObject container, EReference reference, VDomainModelReference dmr) {
452:                 final ReferenceService referenceService = getViewModelContext().getService(ReferenceService.class);
453:                 referenceService.openInNewContext(dmr);
454:         }
455:
456:         /**
457:          * Returns the root EClass of the domain model reference.
458:          *
459:          * @return the DMR's root EClass.
460:          */
461:         protected EClass getDmrRootEClass() {
462:                 return Helper.getRootEClass(getViewModelContext().getDomainModel());
463:         }
464:
465:         @Override
466:         protected void rootDomainModelChanged() throws DatabindingFailedException {
467:                 final IObservableValue<?> observableValue = getEMFFormsDatabinding()
468:                         .getObservableValue(getVElement().getDomainModelReference(), getViewModelContext().getDomainModel());
469:                 try {
470:                         eObject = (EObject) ((IObserving) observableValue).getObserved();
471:                 } finally {
472:                         observableValue.dispose();
473:                 }
474:
475:                 super.rootDomainModelChanged();
476:         }
477:
478:         @Override
479:         public void scrollToReveal() {
480:                 if (canReveal(setBtn) && setBtn.isEnabled()) {
481:                         scrollToReveal(setBtn);
482:                 } else {
483:                         super.scrollToReveal();
484:                 }
485:         }
486:
487:         /** SelectionAdapter for the set button. */
488:         private class SelectionAdapterExtension extends SelectionAdapter {
489:
490:                 private final EReference eReference;
491:
492:                 SelectionAdapterExtension(Label label, IObservableValue<?> modelValue, ViewModelContext viewModelContext,
493:                         DataBindingContext dataBindingContext, EReference eReference) {
494:                         this.eReference = eReference;
495:                 }
496:
497:                 @Override
498:                 public void widgetSelected(SelectionEvent e) {
499:                         final EClass eclass = getDmrRootEClass();
500:
501:                         VDomainModelReference reference = null;
502:                         if (VControl.class.isInstance(eObject)) {
503:                                 reference = VControl.class.cast(eObject).getDomainModelReference();
504:                         } else if (VLabel.class.isInstance(eObject)) {
505:                                 reference = VLabel.class.cast(eObject).getDomainModelReference();
506:                         } else if (eObject instanceof LeafCondition) {
507:                                 reference = LeafCondition.class.cast(eObject).getDomainModelReference();
508:                         }
509:
510:                         if (ToolingModeUtil.isSegmentToolingEnabled()) {
511:                                 if (reference == null) {
512:                                         addNewSegmentDmr(eObject, eReference);
513:                                 } else {
514:                                         editSegmentDmr(eObject, eReference, reference);
515:                                 }
516:                         } else {
517:                                 final Collection<EClass> classes = EMFUtils.getSubClasses(eReference.getEReferenceType());
518:                                 // Don't allow to create a plain DMR legacy mode
519:                                 classes.remove(VViewPackage.Literals.DOMAIN_MODEL_REFERENCE);
520:
521:                                 final CreateDomainModelReferenceWizard wizard = new CreateDomainModelReferenceWizard(
522:                                         eObject, structuralFeature, getEditingDomain(eObject), eclass,
523:                                         reference == null ? "New Reference Element" : "Configure " + reference.eClass().getName(), //$NON-NLS-1$ //$NON-NLS-2$
524:                                         LocalizationServiceHelper.getString(DomainModelReferenceControlSWTRenderer.class,
525:                                                 "NewModelElementWizard_WizardTitle_AddModelElement"), //$NON-NLS-1$
526:                                         LocalizationServiceHelper.getString(DomainModelReferenceControlSWTRenderer.class,
527:                                                 "NewModelElementWizard_PageTitle_AddModelElement"), //$NON-NLS-1$
528:                                         LocalizationServiceHelper.getString(DomainModelReferenceControlSWTRenderer.class,
529:                                                 "NewModelElementWizard_PageDescription_AddModelElement"), //$NON-NLS-1$
530:                                         reference);
531:
532:                                 final SelectionComposite<TreeViewer> helper = CompositeFactory.getSelectModelClassComposite(
533:                                         new HashSet<EPackage>(),
534:                                         new HashSet<EPackage>(), classes);
535:                                 wizard.setCompositeProvider(helper);
536:                                 new WizardDialog(Display.getDefault().getActiveShell(), wizard).open();
537:                         }
538:
539:                 }
540:         }
541: }