Skip to content

Package: DMRSelectorControlSWTRenderer

DMRSelectorControlSWTRenderer

nameinstructionbranchcomplexitylinemethod
DMRSelectorControlSWTRenderer(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%
addEcorePathToTemplate(String)
M: 26 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
linkValue(Shell)
M: 113 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 33 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 - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.template.internal.tooling.controls;
15:
16: import java.io.IOException;
17:
18: import org.eclipse.core.databinding.observable.IObserving;
19: import org.eclipse.core.databinding.observable.value.IObservableValue;
20: import org.eclipse.core.resources.IFile;
21: import org.eclipse.emf.common.command.Command;
22: import org.eclipse.emf.ecore.EClass;
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecore.EPackage;
25: import org.eclipse.emf.ecore.EStructuralFeature;
26: import org.eclipse.emf.ecp.ide.spi.util.EcoreHelper;
27: import org.eclipse.emf.ecp.view.internal.editor.controls.EditableEReferenceLabelControlSWTRenderer;
28: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
29: import org.eclipse.emf.ecp.view.spi.model.VControl;
30: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
31: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
32: import org.eclipse.emf.ecp.view.template.internal.tooling.Activator;
33: import org.eclipse.emf.ecp.view.template.internal.tooling.util.DMRCreationWizard;
34: import org.eclipse.emf.ecp.view.template.model.VTViewTemplate;
35: import org.eclipse.emf.edit.command.SetCommand;
36: import org.eclipse.emf.edit.domain.EditingDomain;
37: import org.eclipse.emfforms.spi.common.report.ReportService;
38: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
39: import org.eclipse.jface.window.Window;
40: import org.eclipse.jface.wizard.WizardDialog;
41: import org.eclipse.swt.widgets.Shell;
42:
43: /**
44: * Control for setting the DomainModelReference in the DomainModelReferenceSelector.
45: *
46: * @author Eugen Neufeld
47: *
48: */
49: public class DMRSelectorControlSWTRenderer extends EditableEReferenceLabelControlSWTRenderer {
50:
51:         /**
52:          * @param vElement the view model element to be rendered
53:          * @param viewContext the view context
54:          * @param reportService the {@link ReportService}
55:          */
56:         public DMRSelectorControlSWTRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService) {
57:                 super(vElement, viewContext, reportService);
58:         }
59:
60:         @Override
61:         protected void linkValue(Shell shell) {
62:                 final DMRCreationWizard dmrWizard = new DMRCreationWizard();
63:                 final WizardDialog wd = new WizardDialog(shell, dmrWizard);
64:                 final int open = wd.open();
65:•                if (Window.CANCEL == open) {
66:                         return;
67:                 }
68:
69:                 final IFile selectedEcore = dmrWizard.getSelectedEcore();
70:                 EStructuralFeature featureToSet = dmrWizard.getSelectedEStructuralFeature();
71:•                if (selectedEcore != null) {
72:                         try {
73:                                 final String ecorePath = selectedEcore.getFullPath().toString();
74:                                 EcoreHelper.registerEcore(ecorePath);
75:                                 addEcorePathToTemplate(ecorePath);
76:                                 final EPackage ePackage = (EPackage) featureToSet.eResource().getContents().get(0);
77:                                 final EPackage registeredPackage = (EPackage) EPackage.Registry.INSTANCE.get(ePackage.getNsURI());
78:                                 final EClass eClass = (EClass) registeredPackage.getEClassifier(featureToSet.getEContainingClass()
79:                                         .getName());
80:                                 featureToSet = eClass.getEStructuralFeature(featureToSet.getFeatureID());
81:                         } catch (final IOException ex) {
82:                                 Activator.log(ex);
83:                         }
84:                 }
85:
86:                 IObservableValue observableValue;
87:                 try {
88:                         observableValue = getEMFFormsDatabinding()
89:                                 .getObservableValue(getVElement().getDomainModelReference(), getViewModelContext().getDomainModel());
90:                 } catch (final DatabindingFailedException ex) {
91:                         showLinkValueFailedMessageDialog(shell, ex);
92:                         return;
93:                 }
94:                 final EObject eObject = (EObject) ((IObserving) observableValue).getObserved();
95:                 final EStructuralFeature structuralFeature = (EStructuralFeature) observableValue.getValueType();
96:                 observableValue.dispose();
97:
98:                 final VFeaturePathDomainModelReference value = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
99:                 value.setDomainModelEFeature(featureToSet);
100:
101:                 final EditingDomain editingDomain = getEditingDomain(eObject);
102:                 final Command command = SetCommand.create(editingDomain, eObject, structuralFeature,
103:                         value);
104:                 editingDomain.getCommandStack().execute(command);
105:
106:         }
107:
108:         /**
109:          * @param ecorePath
110:          */
111:         private void addEcorePathToTemplate(String ecorePath) {
112:                 EObject domain = getViewModelContext().getDomainModel();
113:•                while (!VTViewTemplate.class.isInstance(domain)) {
114:                         domain = domain.eContainer();
115:                 }
116:•                if (!VTViewTemplate.class.isInstance(domain)) {
117:                         return;
118:                 }
119:                 VTViewTemplate.class.cast(domain).getReferencedEcores().add(ecorePath);
120:         }
121: }