Skip to content

Package: FeaturePathDMRControlSWTRenderer

FeaturePathDMRControlSWTRenderer

nameinstructionbranchcomplexitylinemethod
FeaturePathDMRControlSWTRenderer(VControl, ViewModelContext, ReportService)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
linkValue(Shell)
M: 96 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 31 C: 0
0%
M: 1 C: 0
0%

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.keyattributedmr.tooling;
15:
16: import java.util.Collection;
17: import java.util.HashSet;
18:
19: import org.eclipse.core.databinding.observable.IObserving;
20: import org.eclipse.core.databinding.observable.value.IObservableValue;
21: import org.eclipse.emf.ecore.EClass;
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EPackage;
24: import org.eclipse.emf.ecore.EReference;
25: import org.eclipse.emf.ecore.EStructuralFeature;
26: import org.eclipse.emf.ecp.common.spi.EMFUtils;
27: import org.eclipse.emf.ecp.spi.common.ui.CompositeFactory;
28: import org.eclipse.emf.ecp.spi.common.ui.composites.SelectionComposite;
29: import org.eclipse.emf.ecp.view.internal.editor.controls.EditableEReferenceLabelControlSWTRenderer;
30: import org.eclipse.emf.ecp.view.internal.editor.handler.CreateDomainModelReferenceWizard;
31: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
32: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyAttributeDomainModelReference;
33: import org.eclipse.emf.ecp.view.spi.model.VControl;
34: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
35: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
36: import org.eclipse.emfforms.spi.common.report.ReportService;
37: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
38: import org.eclipse.emfforms.spi.localization.LocalizationServiceHelper;
39: import org.eclipse.jface.viewers.TreeViewer;
40: import org.eclipse.jface.wizard.WizardDialog;
41: import org.eclipse.swt.widgets.Shell;
42:
43: /**
44: * Control for a {@link org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference
45: * VFeaturePathDomainModelReference} that is a child of a {@link VKeyAttributeDomainModelReference}.
46: *
47: * @author Eugen Neufeld
48: *
49: */
50: @SuppressWarnings("restriction")
51: public class FeaturePathDMRControlSWTRenderer extends
52:         EditableEReferenceLabelControlSWTRenderer {
53:
54:         /**
55:          * @param vElement the view model element to be rendered
56:          * @param viewContext the view context
57:          * @param reportService the {@link ReportService}
58:          */
59:         public FeaturePathDMRControlSWTRenderer(VControl vElement, ViewModelContext viewContext,
60:                 ReportService reportService) {
61:                 super(vElement, viewContext, reportService);
62:                 // TODO Auto-generated constructor stub
63:         }
64:
65:         @Override
66:         protected void linkValue(Shell shell) {
67:                 IObservableValue observableValue;
68:                 try {
69:                         observableValue = getEMFFormsDatabinding()
70:                                 .getObservableValue(getVElement().getDomainModelReference(), getViewModelContext().getDomainModel());
71:                 } catch (final DatabindingFailedException ex) {
72:                         showLinkValueFailedMessageDialog(shell, ex);
73:                         return;
74:                 }
75:                 final EObject eObject = (EObject) ((IObserving) observableValue).getObserved();
76:                 final EStructuralFeature structuralFeature = (EStructuralFeature) observableValue.getValueType();
77:                 observableValue.dispose();
78:
79:                 final VKeyAttributeDomainModelReference mappingDomainModelReference = VKeyAttributeDomainModelReference.class
80:                         .cast(eObject);
81:
82:                 final EClass eclass = EReference.class.cast(mappingDomainModelReference.getDomainModelEFeature())
83:                         .getEReferenceType();
84:
85:                 final Collection<EClass> classes = EMFUtils.getSubClasses(VViewPackage.eINSTANCE
86:                         .getDomainModelReference());
87:                 // Don't allow to create a plain DMR legacy mode
88:                 classes.remove(VViewPackage.Literals.DOMAIN_MODEL_REFERENCE);
89:
90:                 final CreateDomainModelReferenceWizard wizard = new CreateDomainModelReferenceWizard(
91:                         eObject, structuralFeature, getEditingDomain(eObject), eclass, "New Reference Element", //$NON-NLS-1$
92:                         LocalizationServiceHelper.getString(EditableEReferenceLabelControlSWTRenderer.class,
93:                                 "NewModelElementWizard_WizardTitle_AddModelElement"), //$NON-NLS-1$
94:                         LocalizationServiceHelper.getString(EditableEReferenceLabelControlSWTRenderer.class,
95:                                 "NewModelElementWizard_PageTitle_AddModelElement"), //$NON-NLS-1$
96:                         LocalizationServiceHelper.getString(EditableEReferenceLabelControlSWTRenderer.class,
97:                                 "NewModelElementWizard_PageDescription_AddModelElement"), //$NON-NLS-1$
98:                         (VDomainModelReference) eObject.eGet(structuralFeature, true));
99:
100:                 final SelectionComposite<TreeViewer> helper = CompositeFactory.getSelectModelClassComposite(
101:                         new HashSet<EPackage>(),
102:                         new HashSet<EPackage>(), classes);
103:                 wizard.setCompositeProvider(helper);
104:
105:                 final WizardDialog wd = new WizardDialog(shell, wizard);
106:                 wd.open();
107:
108:         }
109: }