Skip to content

Package: LeafConditionSegmentControlRenderer

LeafConditionSegmentControlRenderer

nameinstructionbranchcomplexitylinemethod
LeafConditionSegmentControlRenderer(VControl, ViewModelContext, ReportService, EMFFormsDatabindingEMF, EMFFormsLabelProvider, VTViewTemplateProvider)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getEMFFormsDatabinding()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
onSelectButton(Label)
M: 12 C: 92
88%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 3 C: 30
91%
M: 0 C: 1
100%
showInfo(Shell, String, String)
M: 5 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-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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.editor.controls;
15:
16: import javax.inject.Inject;
17:
18: import org.eclipse.emf.databinding.IEMFValueProperty;
19: import org.eclipse.emf.ecore.EAttribute;
20: import org.eclipse.emf.ecore.EClass;
21: import org.eclipse.emf.ecore.EStructuralFeature;
22: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
23: import org.eclipse.emf.ecp.view.spi.model.VControl;
24: import org.eclipse.emf.ecp.view.spi.rule.RuleConditionDmrUtil;
25: import org.eclipse.emf.ecp.view.spi.rule.model.LeafCondition;
26: import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
27: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
28: import org.eclipse.emf.edit.command.SetCommand;
29: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
30: import org.eclipse.emf.edit.domain.EditingDomain;
31: import org.eclipse.emfforms.spi.common.report.ReportService;
32: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
33: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
34: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
35: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
36: import org.eclipse.jface.dialogs.MessageDialog;
37: import org.eclipse.swt.widgets.Label;
38: import org.eclipse.swt.widgets.Shell;
39:
40: /**
41: * Renders a control to select the expected value of a LeafCondition which uses a segment based domain model
42: * reference.
43: * <p>
44: * This implementation does not support selecting a value dmr anymore.
45: * If iterating over a multi reference is wanted, this should be done with an
46: * {@link org.eclipse.emf.ecp.view.spi.rule.model.IterateCondition IterateCondition} instead.
47: *
48: * @author Lucas Koehler
49: *
50: */
51: public class LeafConditionSegmentControlRenderer extends ExpectedValueControlRenderer {
52:
53:         /**
54:          * @param vElement The {@link VControl}
55:          * @param viewContext The {@link ViewModelContext}
56:          * @param reportService The {@link ReportService}
57:          * @param databindingService The {@link EMFFormsDatabindingEMF}
58:          * @param labelProvider The {@link EMFFormsLabelProvider}
59:          * @param viewTemplateProvider The {@link VTViewTemplateProvider}
60:          */
61:         @Inject
62:         public LeafConditionSegmentControlRenderer(VControl vElement, ViewModelContext viewContext,
63:                 ReportService reportService, EMFFormsDatabindingEMF databindingService, EMFFormsLabelProvider labelProvider,
64:                 VTViewTemplateProvider viewTemplateProvider) {
65:                 super(vElement, viewContext, reportService, databindingService, labelProvider, viewTemplateProvider);
66:         }
67:
68:         @Override
69:         protected void onSelectButton(Label control) {
70:                 LeafCondition condition;
71:                 try {
72:                         condition = (LeafCondition) getObservedEObject();
73:                 } catch (final DatabindingFailedException ex) {
74:                         getReportService().report(new DatabindingFailedReport(ex));
75:                         return;
76:                 }
77:
78:•                if (condition.getDomainModelReference() == null) {
79:                         showError(control.getShell(), "No Domain Model Reference found", //$NON-NLS-1$
80:                                 "A Domain Model Reference needs to be added to the condition first."); //$NON-NLS-1$
81:                         return;
82:                 }
83:
84:                 EStructuralFeature structuralFeature;
85:                 try {
86:                         final EClass conditionRoot = RuleConditionDmrUtil.getDmrRootEClass(getEMFFormsDatabinding(),
87:                                 getReportService(), condition).orElse(null);
88:                         final IEMFValueProperty valueProperty = getEMFFormsDatabinding()
89:                                 .getValueProperty(condition.getDomainModelReference(), conditionRoot);
90:                         structuralFeature = valueProperty.getStructuralFeature();
91:                 } catch (final DatabindingFailedException ex) {
92:                         getReportService().report(new DatabindingFailedReport(ex));
93:                         return;
94:                 }
95:
96:•                if (!EAttribute.class.isInstance(structuralFeature)) {
97:                         showError(control.getShell(), "No EAttribute selected", //$NON-NLS-1$
98:                                 "The condition's domain model reference must point to an EAttribute."); //$NON-NLS-1$
99:                         return;
100:                 }
101:
102:•                if (condition.getValueDomainModelReference() != null) {
103:                         showInfo(control.getShell(), "Legacy Value DMR will be removed", //$NON-NLS-1$
104:                                 "The LeafCondition's Value DMR is deprecated with the usage of segments. This LeafCondition's value DMR is removed now. If you want to iterate over a multi reference, please use the Iterate Condition."); //$NON-NLS-1$
105:                         // This should not be undoable
106:                         condition.setValueDomainModelReference(null);
107:                 }
108:
109:                 final Object object = getSelectedObject((EAttribute) structuralFeature);
110:                 final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(condition);
111:                 editingDomain.getCommandStack().execute(
112:                         SetCommand.create(editingDomain, condition, RulePackage.Literals.LEAF_CONDITION__EXPECTED_VALUE, object));
113:
114:•                if (object != null) {
115:                         control.setText(object.toString());
116:                 } else {
117:                         control.setText("null"); //$NON-NLS-1$
118:                 }
119:         }
120:
121:         @Override
122:         protected EMFFormsDatabindingEMF getEMFFormsDatabinding() {
123:                 return (EMFFormsDatabindingEMF) super.getEMFFormsDatabinding();
124:         }
125:
126:         /**
127:          * Opens a dialog showing information to the user.
128:          *
129:          * @param parent The parent {@link Shell}
130:          * @param title The title of the warning dialog
131:          * @param message The message describing the warning
132:          */
133:         protected void showInfo(Shell parent, String title, String message) {
134:                 MessageDialog.openInformation(parent, title, message);
135:         }
136: }