Skip to content

Package: KeyValueControlRenderer

KeyValueControlRenderer

nameinstructionbranchcomplexitylinemethod
KeyValueControlRenderer(VControl, ViewModelContext, ReportService, EMFFormsDatabinding, EMFFormsLabelProvider, VTViewTemplateProvider)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
onSelectButton(Label)
M: 67 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 24 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: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.keyattributedmr.tooling;
15:
16: import org.eclipse.emf.ecore.EAttribute;
17: import org.eclipse.emf.ecore.EReference;
18: import org.eclipse.emf.ecore.EStructuralFeature;
19: import org.eclipse.emf.ecp.view.internal.editor.controls.ExpectedValueControlRenderer;
20: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
21: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyAttributeDomainModelReference;
22: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyattributedmrPackage;
23: import org.eclipse.emf.ecp.view.spi.model.VControl;
24: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
25: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
26: import org.eclipse.emf.edit.command.SetCommand;
27: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
28: import org.eclipse.emf.edit.domain.EditingDomain;
29: import org.eclipse.emfforms.spi.common.report.ReportService;
30: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
31: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
32: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
33: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
34: import org.eclipse.jface.dialogs.MessageDialog;
35: import org.eclipse.swt.widgets.Label;
36:
37: /**
38: * @author Eugen Neufeld
39: *
40: */
41: @SuppressWarnings("restriction")
42: public class KeyValueControlRenderer extends ExpectedValueControlRenderer {
43:
44:         /**
45:          * @param vElement the view model element to be rendered
46:          * @param viewContext the view context
47:          * @param reportService the {@link ReportService}
48:          * @param databindingService The {@link EMFFormsDatabinding}
49:          * @param labelProvider The {@link EMFFormsLabelProvider}
50:          * @param viewTemplateProvider The {@link VTViewTemplateProvider}
51:          */
52:         public KeyValueControlRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService,
53:                 EMFFormsDatabinding databindingService, EMFFormsLabelProvider labelProvider,
54:                 VTViewTemplateProvider viewTemplateProvider) {
55:                 super(vElement, viewContext, reportService, databindingService, labelProvider, viewTemplateProvider);
56:         }
57:
58:         @Override
59:         protected void onSelectButton(Label control) {
60:                 VKeyAttributeDomainModelReference condition;
61:                 try {
62:                         condition = (VKeyAttributeDomainModelReference) getObservedEObject();
63:                 } catch (final DatabindingFailedException ex) {
64:                         getReportService().report(new DatabindingFailedReport(ex));
65:                         return;
66:                 }
67:
68:•                if (!VFeaturePathDomainModelReference.class.isInstance(condition.getKeyDMR())) {
69:                         MessageDialog.openError(control.getShell(), "No Feature Path Domain Model Reference found", //$NON-NLS-1$
70:                                 "A Feature Path Domain Model Reference needs to be added to the VKeyAttributeDomainModelReference first. " //$NON-NLS-1$
71:                         );
72:                         return;
73:                 }
74:                 final EStructuralFeature structuralFeature = ((VFeaturePathDomainModelReference) condition
75:                         .getKeyDMR()).getDomainModelEFeature();
76:•                if (structuralFeature == null) {
77:                         MessageDialog.openError(control.getShell(), "No value selected", //$NON-NLS-1$
78:                                 "Please set a value to the Domain Model Reference first. " //$NON-NLS-1$
79:                         );
80:                         return;
81:                 }
82:•                if (EReference.class.isInstance(structuralFeature)) {
83:                         // TODO show all references
84:                         return;
85:                 }
86:
87:                 final Object object = getSelectedObject((EAttribute) structuralFeature);
88:
89:•                if (object != null) {
90:                         final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(condition);
91:                         editingDomain.getCommandStack().execute(
92:                                 SetCommand.create(editingDomain, condition,
93:                                         VKeyattributedmrPackage.eINSTANCE.getKeyAttributeDomainModelReference_KeyValue(), object));
94:
95:                         control.setText(object.toString());
96:                 }
97:         }
98: }