Skip to content

Package: SectionLeafSWTRenderer

SectionLeafSWTRenderer

nameinstructionbranchcomplexitylinemethod
SectionLeafSWTRenderer(VSection, ViewModelContext, ReportService, VTViewTemplateProvider)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createFirstColumn(Composite)
M: 0 C: 70
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 20
100%
M: 0 C: 1
100%
getGridDescription(SWTGridDescription)
M: 0 C: 39
100%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 8
100%
M: 0 C: 1
100%
getLabelStyleBits()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
initCollapseState()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.section.swt;
15:
16: import javax.inject.Inject;
17:
18: import org.eclipse.core.databinding.observable.value.IObservableValue;
19: import org.eclipse.emf.databinding.edit.EMFEditObservables;
20: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
21: import org.eclipse.emf.ecp.view.spi.core.swt.AbstractControlSWTRendererUtil;
22: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
23: import org.eclipse.emf.ecp.view.spi.section.model.VSection;
24: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
25: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
26: import org.eclipse.emf.edit.domain.EditingDomain;
27: import org.eclipse.emfforms.common.Optional;
28: import org.eclipse.emfforms.spi.common.report.ReportService;
29: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
30: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
31: import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
32: import org.eclipse.jface.layout.GridDataFactory;
33: import org.eclipse.jface.layout.GridLayoutFactory;
34: import org.eclipse.swt.SWT;
35: import org.eclipse.swt.widgets.Composite;
36: import org.eclipse.swt.widgets.Control;
37: import org.eclipse.swt.widgets.Label;
38:
39: /**
40: * Renderer for {@link org.eclipse.emf.ecp.view.spi.section.model.VSection VSection} without child items.
41: *
42: * @author jfaltermeier
43: *
44: */
45: public class SectionLeafSWTRenderer extends AbstractSectionSWTRenderer {
46:
47:         /**
48:          * @param vElement the view model element to be rendered
49:          * @param viewContext the view context
50:          * @param reportService the {@link ReportService}
51:          * @param viewTemplateProvider the {@link VTViewTemplateProvider}
52:          * @since 1.18
53:          */
54:         @Inject
55:         public SectionLeafSWTRenderer(VSection vElement, ViewModelContext viewContext, ReportService reportService,
56:                 VTViewTemplateProvider viewTemplateProvider) {
57:                 super(vElement, viewContext, reportService, viewTemplateProvider);
58:         }
59:
60:         private SWTGridDescription rendererGridDescription;
61:
62:         @Override
63:         public SWTGridDescription getGridDescription(
64:                 SWTGridDescription gridDescription) {
65:                 /* +1 because of label */
66:                 final int columns = getVElement().getChildren().size() + 1;
67:•                if (rendererGridDescription == null) {
68:                         rendererGridDescription = GridDescriptionFactory.INSTANCE
69:                                 .createSimpleGrid(1, columns, this);
70:                         final Optional<Integer> labelWidth = getLabelWidth();
71:•                        if (labelWidth.isPresent()) {
72:                                 rendererGridDescription.getGrid().get(0).setPreferredSize(labelWidth.get(), SWT.DEFAULT);
73:                         }
74:                 }
75:                 return rendererGridDescription;
76:         }
77:
78:         @Override
79:         protected Control createFirstColumn(Composite parent) {
80:                 final Composite composite = new Composite(parent, SWT.NONE);
81:                 GridLayoutFactory.fillDefaults().numColumns(1)
82:                         .extendedMargins(computeLeftMargin(), 0, 0, 0)
83:                         .applyTo(composite);
84:
85:                 final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(getVElement());
86:                 final Label label = new Label(composite, getLabelStyleBits());
87:
88:                 final IObservableValue modelLabelValue = EMFEditObservables.observeValue(
89:                         editingDomain,
90:                         getVElement(),
91:                         VViewPackage.eINSTANCE.getElement_Label());
92:
93:                 final IObservableValue textObservable = WidgetProperties.text().observe(label);
94:
95:                 getDataBindingContext().bindValue(textObservable, modelLabelValue);
96:
97:                 GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
98:
99:                 final IObservableValue modelTooltipValue = EMFEditObservables.observeValue(
100:                         editingDomain,
101:                         getVElement(),
102:                         VViewPackage.eINSTANCE.getHasTooltip_Tooltip());
103:                 final IObservableValue targetTooltipValue = WidgetProperties.tooltipText().observe(label);
104:                 getDataBindingContext().bindValue(targetTooltipValue, modelTooltipValue);
105:
106:                 return composite;
107:         }
108:
109:         /**
110:          * Returns the style bits that are set on the label in the first column.
111:          *
112:          * @return the style bits
113:          *
114:          * @since 1.18
115:          */
116:         protected int getLabelStyleBits() {
117:                 return AbstractControlSWTRendererUtil.getLabelStyleBits(getViewTemplateProvider(), getVElement(),
118:                         getViewModelContext());
119:         }
120:
121:         /**
122:          * {@inheritDoc}
123:          *
124:          * @see org.eclipse.emf.ecp.view.spi.section.swt.AbstractSectionSWTRenderer#initCollapseState()
125:          * @since 1.6
126:          */
127:         @Override
128:         protected void initCollapseState() {
129:                 // no children -> empty
130:         }
131:
132: }