Skip to content

Package: SimpleControlSWTRenderer$1

SimpleControlSWTRenderer$1

nameinstructionbranchcomplexitylinemethod
run()
M: 0 C: 19
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 4
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-2017 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.spi.core.swt;
15:
16: import java.util.ArrayList;
17: import java.util.List;
18:
19: import org.eclipse.core.databinding.observable.IObserving;
20: import org.eclipse.core.databinding.observable.value.IObservableValue;
21: import org.eclipse.core.databinding.property.value.IValueProperty;
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EStructuralFeature;
24: import org.eclipse.emf.ecp.view.internal.core.swt.Activator;
25: import org.eclipse.emf.ecp.view.model.common.util.RendererUtil;
26: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
27: import org.eclipse.emf.ecp.view.spi.model.LabelAlignment;
28: import org.eclipse.emf.ecp.view.spi.model.ModelChangeListener;
29: import org.eclipse.emf.ecp.view.spi.model.ModelChangeNotification;
30: import org.eclipse.emf.ecp.view.spi.model.VControl;
31: import org.eclipse.emf.ecp.view.spi.provider.ECPTooltipModifierHelper;
32: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
33: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
34: import org.eclipse.emf.ecp.view.spi.swt.reporting.RenderingFailedReport;
35: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
36: import org.eclipse.emf.ecp.view.template.style.labelwidth.model.VTLabelWidthStyleProperty;
37: import org.eclipse.emf.ecp.view.template.style.unsettable.model.ButtonAlignmentType;
38: import org.eclipse.emf.ecp.view.template.style.unsettable.model.ButtonPlacementType;
39: import org.eclipse.emf.ecp.view.template.style.unsettable.model.VTUnsettableFactory;
40: import org.eclipse.emf.ecp.view.template.style.unsettable.model.VTUnsettableStyleProperty;
41: import org.eclipse.emf.edit.command.SetCommand;
42: import org.eclipse.emf.edit.domain.EditingDomain;
43: import org.eclipse.emfforms.common.Optional;
44: import org.eclipse.emfforms.spi.common.report.ReportService;
45: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
46: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
47: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
48: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
49: import org.eclipse.emfforms.spi.swt.core.SWTDataElementIdHelper;
50: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
51: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
52: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
53: import org.eclipse.jface.layout.GridDataFactory;
54: import org.eclipse.jface.layout.GridLayoutFactory;
55: import org.eclipse.swt.SWT;
56: import org.eclipse.swt.custom.StackLayout;
57: import org.eclipse.swt.events.SelectionAdapter;
58: import org.eclipse.swt.events.SelectionEvent;
59: import org.eclipse.swt.graphics.Color;
60: import org.eclipse.swt.layout.GridData;
61: import org.eclipse.swt.widgets.Button;
62: import org.eclipse.swt.widgets.Composite;
63: import org.eclipse.swt.widgets.Control;
64: import org.eclipse.swt.widgets.Display;
65: import org.eclipse.swt.widgets.Label;
66:
67: /**
68: * @author Eugen
69: *
70: */
71: public abstract class SimpleControlSWTRenderer extends AbstractControlSWTRenderer<VControl> {
72:
73:         /**
74:          * {@link ModelChangeListener} which will sync the top-control to the unset state.
75:          *
76:          * @author Johannes Faltermeier
77:          *
78:          */
79:         private static final class UnsetModelChangeListener implements ModelChangeListener {
80:                 private final EObject eObject;
81:                 private final Button unsetButton;
82:                 private final EStructuralFeature structuralFeature;
83:                 private final Control createUnsetLabel;
84:                 private final Composite controlComposite;
85:                 private final StackLayout sl;
86:                 private final Control baseControl;
87:
88:                 private UnsetModelChangeListener(EObject eObject, Button unsetButton, EStructuralFeature structuralFeature,
89:                         Control createUnsetLabel, Composite controlComposite, StackLayout sl, Control baseControl) {
90:                         this.eObject = eObject;
91:                         this.unsetButton = unsetButton;
92:                         this.structuralFeature = structuralFeature;
93:                         this.createUnsetLabel = createUnsetLabel;
94:                         this.controlComposite = controlComposite;
95:                         this.sl = sl;
96:                         this.baseControl = baseControl;
97:                 }
98:
99:                 @Override
100:                 public void notifyChange(ModelChangeNotification notification) {
101:                         updateTopControl();
102:                 }
103:
104:                 void updateTopControl() {
105:                         if (eObject.eIsSet(structuralFeature)) {
106:                                 if (getStack().topControl == getBaseControl()) {
107:                                         return;
108:                                 }
109:                                 getStack().topControl = getBaseControl();
110:                                 getUnsetButton().setImage(Activator.getImage(ICONS_UNSET_FEATURE));
111:                                 getControlComposite().layout(true);
112:                         } else {
113:                                 if (getStack().topControl == getUnsetLabel()) {
114:                                         return;
115:                                 }
116:                                 getStack().topControl = getUnsetLabel();
117:                                 getUnsetButton().setImage(Activator.getImage(ICONS_SET_FEATURE));
118:                                 getControlComposite().layout(true);
119:                         }
120:                 }
121:
122:                 Composite getControlComposite() {
123:                         return controlComposite;
124:                 }
125:
126:                 StackLayout getStack() {
127:                         return sl;
128:                 }
129:
130:                 Control getBaseControl() {
131:                         return baseControl;
132:                 }
133:
134:                 Control getUnsetLabel() {
135:                         return createUnsetLabel;
136:                 }
137:
138:                 Button getUnsetButton() {
139:                         return unsetButton;
140:                 }
141:         }
142:
143:         /**
144:          * @author Jonas
145:          *
146:          */
147:         private final class UnsetSelectionAdapter extends SelectionAdapter {
148:                 private final StackLayout sl;
149:                 private final Button unsetButton;
150:                 private final Control createUnsetLabel;
151:                 private final Control baseControl;
152:                 private final Composite controlComposite;
153:
154:                 /**
155:                  * @param sl
156:                  * @param unsetButton
157:                  * @param createUnsetLabel
158:                  * @param baseControl
159:                  * @param controlComposite
160:                  */
161:                 private UnsetSelectionAdapter(StackLayout sl, Button unsetButton, Control createUnsetLabel, Control baseControl,
162:                         Composite controlComposite) {
163:                         this.sl = sl;
164:                         this.unsetButton = unsetButton;
165:                         this.createUnsetLabel = createUnsetLabel;
166:                         this.baseControl = baseControl;
167:                         this.controlComposite = controlComposite;
168:                 }
169:
170:                 /**
171:                  * {@inheritDoc}
172:                  *
173:                  * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
174:                  */
175:                 @Override
176:                 public void widgetSelected(SelectionEvent e) {
177:                         super.widgetSelected(e);
178:                         IObservableValue observableValue;
179:                         try {
180:                                 observableValue = getEMFFormsDatabinding()
181:                                         .getObservableValue(getVElement().getDomainModelReference(),
182:                                                 getViewModelContext().getDomainModel());
183:                         } catch (final DatabindingFailedException ex) {
184:                                 getReportService().report(new DatabindingFailedReport(ex));
185:                                 return;
186:                         }
187:                         final EStructuralFeature structuralFeature = (EStructuralFeature) observableValue.getValueType();
188:                         final EObject eObject = (EObject) ((IObserving) observableValue).getObserved();
189:                         observableValue.dispose();
190:                         Object value = null;
191:                         final ButtonAlignmentType buttonAlignment = getUnsettableStyleProperty().getButtonAlignment();
192:                         final ButtonPlacementType buttonPlacement = getUnsettableStyleProperty().getButtonPlacement();
193:                         if (!eObject.eIsSet(structuralFeature)) {
194:                                 sl.topControl = baseControl;
195:                                 unsetButton.setImage(Activator.getImage(ICONS_UNSET_FEATURE));
196:                                 value = structuralFeature.getDefaultValue();
197:                                 // adjust space grabbing if the unset button is alignend directly on the right side of the unset label.
198:                                 if (buttonAlignment == ButtonAlignmentType.LEFT
199:                                         && buttonPlacement == ButtonPlacementType.RIGHT_OF_LABEL) {
200:                                         GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false)
201:                                                 .applyTo(controlComposite);
202:                                 }
203:                         } else {
204:                                 sl.topControl = createUnsetLabel;
205:                                 unsetButton.setImage(Activator.getImage(ICONS_SET_FEATURE));
206:                                 value = SetCommand.UNSET_VALUE;
207:                                 // re-set standard space grabbing if the unset button was alignend directly on the right side of the
208:                                 // unset label.
209:                                 if (buttonAlignment == ButtonAlignmentType.LEFT
210:                                         && buttonPlacement == ButtonPlacementType.RIGHT_OF_LABEL) {
211:                                         GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, false)
212:                                                 .applyTo(controlComposite);
213:                                 }
214:                         }
215:                         final EditingDomain editingDomain = getEditingDomain(eObject);
216:                         editingDomain.getCommandStack().execute(
217:                                 SetCommand.create(editingDomain, eObject, structuralFeature, value));
218:                         if (buttonAlignment == ButtonAlignmentType.LEFT) {
219:                                 controlComposite.getParent().layout();
220:                         }
221:                         controlComposite.layout();
222:                 }
223:         }
224:
225:         private static final String UNSET = "unset"; //$NON-NLS-1$
226:         private static final String ICONS_UNSET_FEATURE = "icons/unset_feature.png"; //$NON-NLS-1$
227:         private static final String ICONS_SET_FEATURE = "icons/set_feature.png"; //$NON-NLS-1$
228:
229:         /**
230:          * Default constructor.
231:          *
232:          * @param vElement the view model element to be rendered
233:          * @param viewContext the view context
234:          * @param reportService The {@link ReportService}
235:          * @param emfFormsDatabinding The {@link EMFFormsDatabinding}
236:          * @param emfFormsLabelProvider The {@link EMFFormsLabelProvider}
237:          * @param vtViewTemplateProvider The {@link VTViewTemplateProvider}
238:          * @since 1.6
239:          */
240:         public SimpleControlSWTRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService,
241:                 EMFFormsDatabinding emfFormsDatabinding, EMFFormsLabelProvider emfFormsLabelProvider,
242:                 VTViewTemplateProvider vtViewTemplateProvider) {
243:                 super(vElement, viewContext, reportService, emfFormsDatabinding, emfFormsLabelProvider, vtViewTemplateProvider);
244:         }
245:
246:         private SWTGridDescription rendererGridDescription;
247:         private UnsetModelChangeListener unsetModelChangeListener;
248:
249:         private Label validationIcon;
250:         private Control editControl;
251:         private Button unsetButton;
252:
253:         /**
254:          * {@inheritDoc}
255:          *
256:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#getGridDescription(SWTGridDescription)
257:          */
258:         @Override
259:         public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
260:                 if (rendererGridDescription == null) {
261:                         final int columns = SimpleControlSWTRendererUtil
262:                                 .showLabel(getVElement(), getReportService(), getClass().getName()) ? 3 : 2;
263:
264:                         rendererGridDescription = GridDescriptionFactory.INSTANCE.createEmptyGridDescription();
265:                         rendererGridDescription.setRows(1);
266:                         rendererGridDescription.setColumns(columns);
267:
268:                         final List<SWTGridCell> grid = new ArrayList<SWTGridCell>();
269:
270:                         if (columns == 3) {
271:                                 final SWTGridCell labelCell = createLabelCell(grid.size());
272:                                 grid.add(labelCell);
273:                         }
274:
275:                         final SWTGridCell validationCell = createValidationCell(grid.size());
276:                         grid.add(validationCell);
277:
278:                         final SWTGridCell controlCel = createControlCell(grid.size());
279:                         grid.add(controlCel);
280:
281:                         rendererGridDescription.setGrid(grid);
282:                 }
283:                 return rendererGridDescription;
284:         }
285:
286:         /**
287:          * Creates the label cell if necessary.
288:          *
289:          * @param column column number within the grid row
290:          * @return created and configured label cell
291:          * @since 1.9
292:          */
293:         protected SWTGridCell createLabelCell(int column) {
294:                 return SimpleControlSWTRendererUtil.createLabelCell(column, this, getLabelWidth());
295:         }
296:
297:         /**
298:          * @return an optional width for the control's label
299:          * @since 1.16
300:          */
301:         protected Optional<Integer> getLabelWidth() {
302:                 final VTLabelWidthStyleProperty styleProperty = RendererUtil.getStyleProperty(
303:                         getVTViewTemplateProvider(),
304:                         getVElement(),
305:                         getViewModelContext(),
306:                         VTLabelWidthStyleProperty.class);
307:                 if (styleProperty == null || !styleProperty.isSetWidth()) {
308:                         return Optional.empty();
309:                 }
310:                 return Optional.of(styleProperty.getWidth());
311:         }
312:
313:         /**
314:          * Creates the validation cell.
315:          *
316:          * @param column column number within the grid row
317:          * @return created and configured label cell
318:          * @since 1.9
319:          */
320:         protected SWTGridCell createValidationCell(int column) {
321:                 return SimpleControlSWTRendererUtil.createValidationCell(column, this);
322:         }
323:
324:         /**
325:          * Creates the control cell.
326:          *
327:          * @param column column number within the grid row
328:          * @return created and configured label cell
329:          * @since 1.9
330:          */
331:         protected SWTGridCell createControlCell(int column) {
332:                 return SimpleControlSWTRendererUtil.createControlCell(column, this);
333:         }
334:
335:         /**
336:          * {@inheritDoc}
337:          *
338:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#renderControl(int, org.eclipse.swt.widgets.Composite,
339:          * org.eclipse.emf.ecp.view.spi.model.VElement, org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
340:          */
341:         @Override
342:         protected final Control renderControl(SWTGridCell gridCell, Composite parent)
343:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
344:                 int controlIndex = gridCell.getColumn();
345:                 if (getVElement().getLabelAlignment() == LabelAlignment.NONE) {
346:                         controlIndex++;
347:                 }
348:                 switch (controlIndex) {
349:                 case 0:
350:                         return createLabel(parent);
351:                 case 1:
352:                         validationIcon = createValidationIcon(parent);
353:                         return validationIcon;
354:                 case 2:
355:                         editControl = createEditControl(parent);
356:                         return editControl;
357:                 default:
358:                         throw new IllegalArgumentException(
359:                                 String
360:                                         .format(
361:                                                 "The provided SWTGridCell (%1$s) cannot be used by this (%2$s) renderer.", gridCell.toString(), //$NON-NLS-1$
362:                                                 toString()));
363:                 }
364:         }
365:
366:         private Control createEditControl(Composite parent) {
367:                 try {
368:                         if (isUnsettable()) {
369:                                 return createUnsettableControl(parent);
370:                         }
371:                         final Control control = createControl(parent);
372:                         setControlIdData(control);
373:                         return control;
374:                 } catch (final DatabindingFailedException ex) {
375:                         getReportService().report(new RenderingFailedReport(ex));
376:                         final Label errorLabel = new Label(parent, SWT.NONE);
377:                         errorLabel.setText(ex.getMessage());
378:                         return errorLabel;
379:                 }
380:         }
381:
382:         /**
383:          * Returns true if the control is unsettable.
384:          *
385:          * @return true if unsettable, false otherwise
386:          * @throws DatabindingFailedException if the databinding fails
387:          */
388:         protected boolean isUnsettable() throws DatabindingFailedException {
389:                 final IValueProperty valueProperty = getEMFFormsDatabinding()
390:                         .getValueProperty(getVElement().getDomainModelReference(), getViewModelContext().getDomainModel());
391:                 final EStructuralFeature feature = (EStructuralFeature) valueProperty.getValueType();
392:                 return feature.isUnsettable();
393:         }
394:
395:         private Control createUnsettableControl(Composite parent) throws DatabindingFailedException {
396:                 final Composite composite = new Composite(parent, SWT.NONE);
397:                 composite.setBackground(parent.getBackground());
398:                 GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(composite);
399:
400:                 final ButtonPlacementType buttonPlacement = getUnsettableStyleProperty().getButtonPlacement();
401:                 final Composite controlComposite;
402:                 if (buttonPlacement == ButtonPlacementType.RIGHT_OF_LABEL) {
403:                         controlComposite = new Composite(composite, SWT.NONE);
404:                         unsetButton = new Button(composite, SWT.PUSH);
405:                 } else {
406:                         unsetButton = new Button(composite, SWT.PUSH);
407:                         controlComposite = new Composite(composite, SWT.NONE);
408:                 }
409:                 controlComposite.setBackground(parent.getBackground());
410:                 final ButtonAlignmentType buttonAlignment = getUnsettableStyleProperty().getButtonAlignment();
411:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(controlComposite);
412:
413:                 if (buttonAlignment == ButtonAlignmentType.LEFT && buttonPlacement == ButtonPlacementType.RIGHT_OF_LABEL) {
414:                         // If the (un)set button is configured to be left aligned and no value is set,
415:                         // align the button directly next to the unset label.
416:                         try {
417:                                 IObservableValue observableValue;
418:                                 observableValue = getEMFFormsDatabinding().getObservableValue(getVElement().getDomainModelReference(),
419:                                         getViewModelContext().getDomainModel());
420:                                 final EStructuralFeature structuralFeature = (EStructuralFeature) observableValue.getValueType();
421:                                 final EObject eObject = (EObject) ((IObserving) observableValue).getObserved();
422:                                 if (!eObject.eIsSet(structuralFeature)) {
423:                                         GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, false)
424:                                                 .applyTo(controlComposite);
425:                                 }
426:                         } catch (final DatabindingFailedException ex) {
427:                                 getReportService().report(new DatabindingFailedReport(ex));
428:                         }
429:                 }
430:
431:                 final StackLayout sl = new StackLayout();
432:                 controlComposite.setLayout(sl);
433:                 final Control baseControl = createControl(controlComposite);
434:                 setControlIdData(baseControl);
435:                 final Control createUnsetLabel = createUnsetLabel(controlComposite);
436:                 SWTDataElementIdHelper.setElementIdDataWithSubId(createUnsetLabel, getVElement(), UNSET, getViewModelContext());
437:                 GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(false, false).applyTo(unsetButton);
438:                 unsetButton.addSelectionListener(
439:                         new UnsetSelectionAdapter(sl, unsetButton, createUnsetLabel, baseControl, controlComposite));
440:
441:                 unsetModelChangeListener = registerUnsetStateListener(controlComposite, sl, baseControl, createUnsetLabel,
442:                         unsetButton);
443:                 return composite;
444:         }
445:
446:         private UnsetModelChangeListener registerUnsetStateListener(final Composite controlComposite, final StackLayout sl,
447:                 final Control baseControl, final Control createUnsetLabel, final Button unsetButton)
448:                 throws DatabindingFailedException {
449:                 final EStructuralFeature structuralFeature = (EStructuralFeature) getModelValue().getValueType();
450:                 final EObject eObject = (EObject) ((IObserving) getModelValue()).getObserved();
451:                 if (eObject.eIsSet(structuralFeature)) {
452:                         sl.topControl = baseControl;
453:                         unsetButton.setImage(Activator.getImage(ICONS_UNSET_FEATURE));
454:                 } else {
455:                         sl.topControl = createUnsetLabel;
456:                         unsetButton.setImage(Activator.getImage(ICONS_SET_FEATURE));
457:                 }
458:                 controlComposite.layout(true);
459:                 /* There is no UNSET databinding trigger available */
460:                 final UnsetModelChangeListener unsetModelChangeListener = new UnsetModelChangeListener(eObject, unsetButton,
461:                         structuralFeature, createUnsetLabel, controlComposite, sl, baseControl);
462:                 getViewModelContext().registerDomainChangeListener(unsetModelChangeListener);
463:                 return unsetModelChangeListener;
464:         }
465:
466:         private Control createUnsetLabel(Composite parent) {
467:                 final Composite composite = new Composite(parent, SWT.NONE);
468:                 GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(true).applyTo(composite);
469:                 final Label unsetLabel = new Label(composite, SWT.NONE);
470:                 unsetLabel.setBackground(parent.getBackground());
471:                 unsetLabel.setText(getUnsetText());
472:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, true).applyTo(unsetLabel);
473:                 return composite;
474:         }
475:
476:         /**
477:          * Provide the unset text to show on the label when value is unset.
478:          *
479:          * @return the text to show on the unset label
480:          */
481:         protected abstract String getUnsetText();
482:
483:         /**
484:          * Set the provided validation color as the background for the provided control.
485:          *
486:          * @param control the control to set the color on
487:          * @param validationColor the validation color to set
488:          */
489:         protected void setValidationColor(Control control, Color validationColor) {
490:                 control.setBackground(validationColor);
491:         }
492:
493:         /**
494:          * Set the provided validation color as the foreground for the provided control.
495:          *
496:          * @param control the control to set the color on
497:          * @param validationColor the validation color to set
498:          * @since 1.10
499:          */
500:         protected void setValidationForegroundColor(Control control, Color validationColor) {
501:                 control.setForeground(validationColor);
502:         }
503:
504:         @Override
505:         protected void setControlEnabled(SWTGridCell gridCell, Control control, boolean enabled) {
506:                 int controlIndex = gridCell.getColumn();
507:                 if (getVElement().getLabelAlignment() == LabelAlignment.NONE) {
508:                         controlIndex++;
509:                 }
510:                 switch (controlIndex) {
511:                 case 0:
512:                 case 1:
513:                         break;
514:                 default:
515:                         control.setEnabled(enabled);
516:                 }
517:         }
518:
519:         @Override
520:         protected final void applyValidation() {
521:                 Display.getDefault().asyncExec(new Runnable() {
522:
523:                         @Override
524:                         public void run() {
525:•                                if (getControls().size() == 0 || getControls().values().iterator().next().isDisposed()) {
526:                                         return;
527:                                 }
528:                                 applyInnerValidation();
529:                         }
530:                 });
531:         }
532:
533:         private void applyInnerValidation() {
534:                 // triggered due to another validation rule before this control is rendered
535:                 if (validationIcon == null || editControl == null) {
536:                         return;
537:                 }
538:                 // validation rule triggered after the control was disposed
539:                 if (validationIcon.isDisposed()) {
540:                         return;
541:                 }
542:
543:                 validationIcon.setImage(getValidationIcon());
544:                 setValidationColor(editControl, getValidationBackgroundColor());
545:                 setValidationForegroundColor(editControl, getValidationForegroundColor());
546:                 if (getVElement().getDiagnostic() == null) {
547:                         validationIcon.setToolTipText(null);
548:                 } else {
549:                         validationIcon.setToolTipText(ECPTooltipModifierHelper.modifyString(getVElement().getDiagnostic()
550:                                 .getMessage(),
551:                                 null));
552:                 }
553:         }
554:
555:         /**
556:          * Creates the control itself.
557:          *
558:          * @param parent the {@link Composite} to render onto
559:          * @return the rendered control
560:          * @throws DatabindingFailedException if the databinding of the control fails
561:          */
562:         protected abstract Control createControl(Composite parent) throws DatabindingFailedException;
563:
564:         /**
565:          * This method will set the element id data on the control created by {@link #createControl(Composite)}.
566:          *
567:          * @param control the control created by {@link #createControl(Composite)}
568:          * @since 1.9
569:          */
570:         protected void setControlIdData(final Control control) {
571:                 if (control != null) {
572:                         SWTDataElementIdHelper.setElementIdDataForVControl(control, getVElement(), getViewModelContext());
573:                 }
574:         }
575:
576:         /**
577:          * {@inheritDoc}
578:          *
579:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#dispose()
580:          */
581:         @Override
582:         protected void dispose() {
583:                 rendererGridDescription = null;
584:                 if (unsetModelChangeListener != null) {
585:                         getViewModelContext().unregisterDomainChangeListener(unsetModelChangeListener);
586:                         unsetModelChangeListener = null;
587:                 }
588:                 validationIcon = null;
589:                 editControl = null;
590:                 super.dispose();
591:         }
592:
593:         @Override
594:         protected void rootDomainModelChanged() throws DatabindingFailedException {
595:                 if (unsetModelChangeListener == null) {
596:                         super.rootDomainModelChanged();
597:                         return;
598:                 }
599:                 getViewModelContext().unregisterDomainChangeListener(unsetModelChangeListener);
600:                 unsetModelChangeListener = registerUnsetStateListener(
601:                         unsetModelChangeListener.getControlComposite(),
602:                         unsetModelChangeListener.getStack(),
603:                         unsetModelChangeListener.getBaseControl(),
604:                         unsetModelChangeListener.getUnsetLabel(),
605:                         unsetModelChangeListener.getUnsetButton());
606:                 super.rootDomainModelChanged();
607:         }
608:
609:         /**
610:          * Creates the default {@link VTUnsettableStyleProperty}.
611:          *
612:          * @return the default {@link VTUnsettableStyleProperty}
613:          * @since 1.14
614:          */
615:         protected VTUnsettableStyleProperty createDefaultUnsettableStyleProperty() {
616:                 return VTUnsettableFactory.eINSTANCE.createUnsettableStyleProperty();
617:         }
618:
619:         /**
620:          * Returns the {@link VTUnsettableStyleProperty}.
621:          *
622:          * @return the {@link VTUnsettableStyleProperty}
623:          * @since 1.14
624:          */
625:         protected VTUnsettableStyleProperty getUnsettableStyleProperty() {
626:                 VTUnsettableStyleProperty styleProperty = RendererUtil.getStyleProperty(getVTViewTemplateProvider(),
627:                         getVElement(), getViewModelContext(), VTUnsettableStyleProperty.class);
628:                 if (styleProperty == null) {
629:                         styleProperty = createDefaultUnsettableStyleProperty();
630:                 }
631:                 return styleProperty;
632:         }
633:
634:         @Override
635:         protected void applyReadOnly() {
636:                 super.applyReadOnly();
637:                 if (unsetButton != null) {
638:                         final boolean readonly = getVElement().isEffectivelyReadonly();
639:                         unsetButton.setVisible(!readonly);
640:                         final GridData data = (GridData) unsetButton.getLayoutData();
641:                         data.exclude = readonly;
642:                         unsetButton.getParent().layout();
643:                 }
644:         }
645: }