Skip to content

Package: GroupSWTRenderer

GroupSWTRenderer

nameinstructionbranchcomplexitylinemethod
GroupSWTRenderer(VGroup, ViewModelContext, ReportService, EMFFormsRendererFactory)
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%
dispose()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getChildren()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getComposite(Composite)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
getCustomVariant()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getGridDescription(SWTGridDescription)
M: 0 C: 26
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 6
100%
M: 0 C: 1
100%
getLayout(int, boolean)
M: 0 C: 9
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: * Eugen Neufeld - initial API and implementation
13: */
14: package org.eclipse.emf.ecp.view.spi.group.swt;
15:
16: import java.util.Collection;
17:
18: import javax.inject.Inject;
19:
20: import org.eclipse.core.databinding.observable.value.IObservableValue;
21: import org.eclipse.emf.databinding.EMFDataBindingContext;
22: import org.eclipse.emf.databinding.edit.EMFEditObservables;
23: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
24: import org.eclipse.emf.ecp.view.spi.core.swt.ContainerSWTRenderer;
25: import org.eclipse.emf.ecp.view.spi.group.model.VGroup;
26: import org.eclipse.emf.ecp.view.spi.model.VContainedElement;
27: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
28: import org.eclipse.emf.ecp.view.spi.swt.layout.LayoutProviderHelper;
29: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
30: import org.eclipse.emf.edit.domain.EditingDomain;
31: import org.eclipse.emfforms.internal.group.swt.GroupTextProperty;
32: import org.eclipse.emfforms.spi.common.report.ReportService;
33: import org.eclipse.emfforms.spi.swt.core.EMFFormsRendererFactory;
34: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
35: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
36: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
37: import org.eclipse.jface.databinding.swt.ISWTObservableValue;
38: import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
39: import org.eclipse.swt.SWT;
40: import org.eclipse.swt.graphics.Point;
41: import org.eclipse.swt.widgets.Composite;
42: import org.eclipse.swt.widgets.Group;
43: import org.eclipse.swt.widgets.Layout;
44:
45: /**
46: * Renders a SWT group.
47: *
48: * @since 1.5
49: *
50: */
51: public class GroupSWTRenderer extends ContainerSWTRenderer<VGroup> {
52:
53:         /**
54:          * Default constructor.
55:          *
56:          * @param vElement the view model element to be rendered
57:          * @param viewContext the view context
58:          * @param reportService the {@link ReportService}
59:          * @param factory the {@link EMFFormsRendererFactory}
60:          * @since 1.6
61:          */
62:         @Inject
63:         public GroupSWTRenderer(VGroup vElement, ViewModelContext viewContext, ReportService reportService,
64:                 EMFFormsRendererFactory factory) {
65:                 super(vElement, viewContext, reportService, factory);
66:                 dbc = new EMFDataBindingContext();
67:         }
68:
69:         private static final String CONTROL_GROUP = "org_eclipse_emf_ecp_ui_control_group"; //$NON-NLS-1$
70:         private final EMFDataBindingContext dbc;
71:         private SWTGridDescription rendererGridDescription;
72:
73:         /**
74:          * {@inheritDoc}
75:          *
76:          * @see org.eclipse.emf.ecp.view.spi.core.swt.ContainerSWTRenderer#getCustomVariant()
77:          */
78:         @Override
79:         protected String getCustomVariant() {
80:                 return CONTROL_GROUP;
81:         }
82:
83:         /**
84:          * {@inheritDoc}
85:          *
86:          * @see org.eclipse.emf.ecp.view.spi.core.swt.ContainerSWTRenderer#getChildren()
87:          */
88:
89:         @Override
90:         protected Collection<VContainedElement> getChildren() {
91:                 return getVElement().getChildren();
92:         }
93:
94:         /**
95:          * {@inheritDoc}
96:          *
97:          * @see org.eclipse.emf.ecp.view.spi.core.swt.ContainerSWTRenderer#getComposite(org.eclipse.swt.widgets.Composite)
98:          */
99:         @Override
100:         protected Composite getComposite(Composite parent) {
101:                 final Group group = new Group(parent, SWT.TITLE);
102:                 final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(getVElement());
103:                 final IObservableValue modelLabelValue = EMFEditObservables.observeValue(
104:                         editingDomain,
105:                         getVElement(),
106:                         VViewPackage.eINSTANCE.getElement_Label());
107:                 final IObservableValue targetLabelValue = new GroupTextProperty().observe(group);
108:                 // FIXME fixed with JFace-Databinding 4.5
109:                 // final IObservableValue targetValue = SWTObservables.observeText(group);
110:                 dbc.bindValue(targetLabelValue, modelLabelValue);
111:
112:                 final IObservableValue modelTooltipValue = EMFEditObservables.observeValue(
113:                         editingDomain,
114:                         getVElement(),
115:                         VViewPackage.eINSTANCE.getHasTooltip_Tooltip());
116:                 final ISWTObservableValue targetTooltipValue = WidgetProperties.tooltipText().observe(group);
117:                 dbc.bindValue(targetTooltipValue, modelTooltipValue);
118:
119:                 return group;
120:         }
121:
122:         @Override
123:         protected Layout getLayout(int numControls, boolean equalWidth) {
124:                 return LayoutProviderHelper.getColumnLayout(numControls, equalWidth, new Point(5, 5));
125:         }
126:
127:         @Override
128:         public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
129:•                if (rendererGridDescription == null) {
130:                         rendererGridDescription = GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 1, this);
131:                         final SWTGridCell swtGridCell = rendererGridDescription.getGrid().get(0);
132:                         swtGridCell.setVerticalFill(false);
133:                         swtGridCell.setVerticalGrab(false);
134:                 }
135:                 return rendererGridDescription;
136:         }
137:
138:         /**
139:          * {@inheritDoc}
140:          *
141:          * @see org.eclipse.emf.ecp.view.spi.core.swt.ContainerSWTRenderer#dispose()
142:          */
143:         @Override
144:         protected void dispose() {
145:                 dbc.dispose();
146:                 super.dispose();
147:         }
148:
149: }