Skip to content

Package: SWTCategorizationRenderer

SWTCategorizationRenderer

nameinstructionbranchcomplexitylinemethod
SWTCategorizationRenderer(VCategorization, ViewModelContext, ReportService)
M: 0 C: 11
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: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getGridDescription(SWTGridDescription)
M: 0 C: 13
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
renderControl(SWTGridCell, Composite)
M: 0 C: 91
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 26
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: * Edgar Mueller - initial API and implementation
13: * Eugen Neufeld - Refactoring
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.view.spi.categorization.swt;
16:
17: import javax.inject.Inject;
18:
19: import org.eclipse.core.databinding.observable.value.IObservableValue;
20: import org.eclipse.emf.databinding.EMFDataBindingContext;
21: import org.eclipse.emf.databinding.edit.EMFEditObservables;
22: import org.eclipse.emf.ecp.view.internal.categorization.swt.MessageKeys;
23: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorization;
24: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
25: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
26: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
27: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
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.spi.common.report.ReportService;
32: import org.eclipse.emfforms.spi.localization.LocalizationServiceHelper;
33: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
34: import org.eclipse.emfforms.spi.swt.core.SWTDataElementIdHelper;
35: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
36: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
37: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
38: import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
39: import org.eclipse.swt.SWT;
40: import org.eclipse.swt.widgets.Composite;
41: import org.eclipse.swt.widgets.Control;
42: import org.eclipse.swt.widgets.Label;
43:
44: /**
45: * SWT categorization renderer.
46: *
47: * @author emueller
48: * @author Eugen Neufeld
49: *
50: */
51: public class SWTCategorizationRenderer extends AbstractSWTRenderer<VCategorization> {
52:         private final EMFDataBindingContext dataBindingContext;
53:
54:         /**
55:          * Default constructor.
56:          *
57:          * @param vElement the view model element to be rendered
58:          * @param viewContext the view context
59:          * @param reportService the {@link ReportService}
60:          * @since 1.6
61:          */
62:         @Inject
63:         public SWTCategorizationRenderer(VCategorization vElement, ViewModelContext viewContext,
64:                 ReportService reportService) {
65:                 super(vElement, viewContext, reportService);
66:                 dataBindingContext = new EMFDataBindingContext();
67:         }
68:
69:         private SWTGridDescription rendererGridDescription;
70:
71:         /**
72:          * @param vElement the view model element to be rendered
73:          * @param viewContext the view context
74:          * @param factory the {@link SWTRendererFactory}
75:          */
76:
77:         /**
78:          * {@inheritDoc}
79:          *
80:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#dispose()
81:          */
82:         @Override
83:         protected void dispose() {
84:                 rendererGridDescription = null;
85:                 dataBindingContext.dispose();
86:                 super.dispose();
87:         }
88:
89:         /**
90:          * {@inheritDoc}
91:          *
92:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#getGridDescription(SWTGridDescription)
93:          */
94:         @Override
95:         public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
96:•                if (rendererGridDescription == null) {
97:                         rendererGridDescription = GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 1, this);
98:                 }
99:                 return rendererGridDescription;
100:         }
101:
102:         /**
103:          * {@inheritDoc}
104:          *
105:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#renderControl(int, org.eclipse.swt.widgets.Composite,
106:          * org.eclipse.emf.ecp.view.spi.model.VElement, org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
107:          */
108:         @Override
109:         protected Control renderControl(SWTGridCell cell, Composite parent) throws NoRendererFoundException,
110:                 NoPropertyDescriptorFoundExeption {
111:                 final Composite categoryComposite = new Composite(parent, SWT.NONE);
112:                 categoryComposite.setBackground(parent.getBackground());
113:                 categoryComposite.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_categorization"); //$NON-NLS-1$
114:
115:                 categoryComposite.setLayout(LayoutProviderHelper.getColumnLayout(1, false));
116:
117:                 final Label headingLbl = new Label(categoryComposite, SWT.NONE);
118:                 headingLbl.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_categorization_title"); //$NON-NLS-1$
119:                 final Label whatToDoLbl = new Label(categoryComposite, SWT.NONE);
120:                 whatToDoLbl.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_categorization_message"); //$NON-NLS-1$
121:
122:                 final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(getVElement());
123:                 final IObservableValue modelLabelValue = EMFEditObservables.observeValue(
124:                         editingDomain,
125:                         getVElement(),
126:                         VViewPackage.eINSTANCE.getElement_Label());
127:                 final IObservableValue targetLabelValue = WidgetProperties.text().observe(headingLbl);
128:                 dataBindingContext.bindValue(targetLabelValue, modelLabelValue);
129:
130:                 final IObservableValue modelTooltipValue = EMFEditObservables.observeValue(
131:                         editingDomain,
132:                         getVElement(),
133:                         VViewPackage.eINSTANCE.getHasTooltip_Tooltip());
134:                 final IObservableValue targetTooltipValue = WidgetProperties.tooltipText().observe(headingLbl);
135:
136:                 dataBindingContext.bindValue(targetTooltipValue, modelTooltipValue);
137:
138:                 whatToDoLbl.setText(
139:                         LocalizationServiceHelper.getString(SWTCategorizationRenderer.class, MessageKeys.Categorization_Selection));
140:                 SWTDataElementIdHelper.setElementIdDataWithSubId(categoryComposite, getVElement(), "category", //$NON-NLS-1$
141:                         getViewModelContext());
142:                 return categoryComposite;
143:         }
144:
145: }