Skip to content

Package: SimpleControlSWTControlSWTRenderer$1

SimpleControlSWTControlSWTRenderer$1

nameinstructionbranchcomplexitylinemethod
widgetDisposed(DisposeEvent)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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-2013 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: * Edagr Mueller - initial API and implementation
13: * Eugen Neufeld - Refactoring
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.view.spi.core.swt;
16:
17: import org.eclipse.core.databinding.Binding;
18: import org.eclipse.core.databinding.UpdateValueStrategy;
19: import org.eclipse.core.databinding.property.value.IValueProperty;
20: import org.eclipse.emf.ecore.EStructuralFeature;
21: import org.eclipse.emf.ecp.edit.spi.swt.util.PreSetValidationStrategy;
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.template.model.VTViewTemplateProvider;
25: import org.eclipse.emfforms.spi.common.report.ReportService;
26: import org.eclipse.emfforms.spi.common.validation.PreSetValidationService;
27: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
28: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
29: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
30: import org.eclipse.swt.events.DisposeEvent;
31: import org.eclipse.swt.events.DisposeListener;
32: import org.eclipse.swt.widgets.Composite;
33: import org.eclipse.swt.widgets.Control;
34:
35: /**
36: * Renderer for {@link org.eclipse.swt.widgets.Control Controls}.
37: *
38: * @author Eugen Neufeld
39: *
40: */
41: public abstract class SimpleControlSWTControlSWTRenderer extends SimpleControlSWTRenderer {
42:
43:         private Binding[] bindings;
44:         private Control control;
45:
46:         /**
47:          * Default constructor.
48:          *
49:          * @param vElement the view model element to be rendered
50:          * @param viewContext the view context
51:          * @param reportService The {@link ReportService}
52:          * @param emfFormsDatabinding The {@link EMFFormsDatabinding}
53:          * @param emfFormsLabelProvider The {@link EMFFormsLabelProvider}
54:          * @param vtViewTemplateProvider The {@link VTViewTemplateProvider}
55:          * @since 1.6
56:          */
57:         public SimpleControlSWTControlSWTRenderer(VControl vElement, ViewModelContext viewContext,
58:                 ReportService reportService,
59:                 EMFFormsDatabinding emfFormsDatabinding, EMFFormsLabelProvider emfFormsLabelProvider,
60:                 VTViewTemplateProvider vtViewTemplateProvider) {
61:                 super(vElement, viewContext, reportService, emfFormsDatabinding, emfFormsLabelProvider, vtViewTemplateProvider);
62:         }
63:
64:         /**
65:          * Creates the control itself.
66:          *
67:          * @param parent the {@link Composite} to render onto
68:          * @return the rendered control
69:          * @throws DatabindingFailedException if the databinding of the control fails
70:          */
71:         @Override
72:         protected final Control createControl(Composite parent) throws DatabindingFailedException {
73:                 control = createSWTControl(parent);
74:                 if (control == null) {
75:                         return null;
76:                 }
77:                 bindings = createBindings(control);
78:
79:                 control.addDisposeListener(new DisposeListener() {
80:                         @Override
81:                         public void widgetDisposed(DisposeEvent e) {
82:                                 disposeBindings();
83:
84:                         }
85:                 });
86:
87:                 return control;
88:         }
89:
90:         /**
91:          * {@inheritDoc}
92:          *
93:          * @see org.eclipse.emf.ecp.view.spi.core.swt.AbstractControlSWTRenderer#rootDomainModelChanged()
94:          */
95:         @Override
96:         protected void rootDomainModelChanged() throws DatabindingFailedException {
97:                 disposeBindings();
98:                 bindings = createBindings(control);
99:                 super.rootDomainModelChanged();
100:         }
101:
102:         /**
103:          * Disposes all bindings of this renderer.
104:          */
105:         private void disposeBindings() {
106:                 if (bindings != null) {
107:                         for (final Binding binding : bindings) {
108:                                 binding.dispose();
109:                         }
110:                 }
111:         }
112:
113:         /**
114:          * Create a {@link PreSetValidationStrategy}.
115:          *
116:          * @param delegate a delegate {@link UpdateValueStrategy}
117:          *
118:          * @return a {@link PreSetValidationStrategy}
119:          * @throws DatabindingFailedException in case the necessary feature can not be obtained
120:          *
121:          * @since 1.13
122:          */
123:         protected UpdateValueStrategy withPreSetValidation(UpdateValueStrategy delegate)
124:                 throws DatabindingFailedException {
125:                 if (getViewModelContext().hasService(PreSetValidationService.class)) {
126:                         return new PreSetValidationStrategy(getVElement(), getFeature(), delegate);
127:                 }
128:                 return delegate;
129:         }
130:
131:         /**
132:          * Retrieves the associated {@link EStructuralFeature} of this renderer.
133:          *
134:          * @return the feature
135:          * @throws DatabindingFailedException in case the necessary feature can not be obtained
136:          *
137:          * @since 1.13
138:          */
139:         protected EStructuralFeature getFeature() throws DatabindingFailedException {
140:                 final EMFFormsDatabinding databindingService = getEMFFormsDatabinding();
141:                 final IValueProperty valueProperty = databindingService.getValueProperty(
142:                         getVElement().getDomainModelReference(),
143:                         getViewModelContext().getDomainModel());
144:                 return EStructuralFeature.class.cast(valueProperty.getValueType());
145:         }
146:
147:         /**
148:          * Create the {@link Binding Bindings} for this controls.
149:          *
150:          * @param control the {@link Control} to create the binding for
151:          * @return all the bindings created by this renderer
152:          * @throws DatabindingFailedException if the creation of the bindings fails.
153:          * @since 1.6
154:          */
155:         protected abstract Binding[] createBindings(Control control) throws DatabindingFailedException;
156:
157:         /**
158:          * Creates the Control.
159:          *
160:          * @param parent the {@link Composite} to use as a parent
161:          * @return the created control
162:          * @throws DatabindingFailedException if the creation of the control fails due to databinding problems
163:          * @since 1.6
164:          */
165:         protected abstract Control createSWTControl(Composite parent) throws DatabindingFailedException;
166:
167: }