Skip to content

Package: BooleanControlSWTRenderer

BooleanControlSWTRenderer

nameinstructionbranchcomplexitylinemethod
BooleanControlSWTRenderer(VControl, ViewModelContext, ReportService, EMFFormsDatabinding, 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%
createBindings(Control)
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createControlCell(int)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createSWTControl(Composite)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getUnsetText()
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%
setValidationColor(Control, Color)
M: 0 C: 1
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-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.internal.core.swt.renderer;
15:
16: import javax.inject.Inject;
17:
18: import org.eclipse.core.databinding.Binding;
19: import org.eclipse.core.databinding.UpdateValueStrategy;
20: import org.eclipse.emf.ecp.view.internal.core.swt.MessageKeys;
21: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
22: import org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTControlSWTRenderer;
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.core.services.databinding.DatabindingFailedException;
27: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
28: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
29: import org.eclipse.emfforms.spi.localization.LocalizationServiceHelper;
30: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
31: import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
32: import org.eclipse.swt.SWT;
33: import org.eclipse.swt.graphics.Color;
34: import org.eclipse.swt.widgets.Button;
35: import org.eclipse.swt.widgets.Composite;
36: import org.eclipse.swt.widgets.Control;
37:
38: /**
39: * @author Eugen
40: *
41: */
42: public class BooleanControlSWTRenderer extends SimpleControlSWTControlSWTRenderer {
43:
44:         /**
45:          * Default constructor.
46:          *
47:          * @param vElement the view model element to be rendered
48:          * @param viewContext the view context
49:          * @param reportService The {@link ReportService}
50:          * @param emfFormsDatabinding The {@link EMFFormsDatabinding}
51:          * @param emfFormsLabelProvider The {@link EMFFormsLabelProvider}
52:          * @param vtViewTemplateProvider The {@link VTViewTemplateProvider}
53:          */
54:         @Inject
55:         public BooleanControlSWTRenderer(VControl vElement, ViewModelContext viewContext,
56:                 ReportService reportService,
57:                 EMFFormsDatabinding emfFormsDatabinding, EMFFormsLabelProvider emfFormsLabelProvider,
58:                 VTViewTemplateProvider vtViewTemplateProvider) {
59:                 super(vElement, viewContext, reportService, emfFormsDatabinding, emfFormsLabelProvider, vtViewTemplateProvider);
60:         }
61:
62:         /**
63:          * {@inheritDoc}
64:          *
65:          * @see org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer#createControlCell(int)
66:          */
67:         @Override
68:         protected SWTGridCell createControlCell(int column) {
69:                 // checkbox button representing Boolean value can not grow
70:                 final SWTGridCell booleanControlCell = super.createControlCell(column);
71:                 booleanControlCell.setHorizontalGrab(false);
72:                 booleanControlCell.setHorizontalFill(false);
73:                 return booleanControlCell;
74:         }
75:
76:         @Override
77:         protected Binding[] createBindings(Control control) throws DatabindingFailedException {
78:                 final Binding binding = getDataBindingContext().bindValue(
79:                         WidgetProperties.buttonSelection().observe((Button) control),
80:                         getModelValue(), withPreSetValidation(new UpdateValueStrategy()), null);
81:                 return new Binding[] { binding };
82:         }
83:
84:         @Override
85:         protected Control createSWTControl(final Composite parent) {
86:                 final Button check = new Button(parent, SWT.CHECK);
87:                 check.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_control_boolean"); //$NON-NLS-1$
88:
89:                 return check;
90:         }
91:
92:         @Override
93:         protected void setValidationColor(Control control, Color validationColor) {
94:                 /* no op */
95:         }
96:
97:         /**
98:          * {@inheritDoc}
99:          *
100:          * @see org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer#getUnsetText()
101:          */
102:         @Override
103:         protected String getUnsetText() {
104:                 return LocalizationServiceHelper
105:                         .getString(getClass(), MessageKeys.BooleanControl_NoBooleanSetClickToSetBoolean);
106:         }
107:
108: }