Skip to content

Package: HorizontalLayoutSWTRenderer

HorizontalLayoutSWTRenderer

nameinstructionbranchcomplexitylinemethod
HorizontalLayoutSWTRenderer(VHorizontalLayout, ViewModelContext, ReportService, EMFFormsRendererFactory)
M: 0 C: 9
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%
getGridDescription(SWTGridDescription)
M: 0 C: 21
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
renderControl(SWTGridCell, Composite)
M: 34 C: 153
82%
M: 2 C: 10
83%
M: 2 C: 5
71%
M: 7 C: 29
81%
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: * Edagr Mueller - initial API and implementation
13: * Eugen Neufeld - Refactoring
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.view.spi.horizontal.swt;
16:
17: import java.util.LinkedHashMap;
18: import java.util.Map;
19:
20: import javax.inject.Inject;
21:
22: import org.eclipse.core.runtime.IStatus;
23: import org.eclipse.core.runtime.Status;
24: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
25: import org.eclipse.emf.ecp.view.spi.horizontal.model.VHorizontalLayout;
26: import org.eclipse.emf.ecp.view.spi.model.VContainedElement;
27: import org.eclipse.emf.ecp.view.spi.model.VElement;
28: import org.eclipse.emf.ecp.view.spi.model.reporting.StatusReport;
29: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
30: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
31: import org.eclipse.emf.ecp.view.spi.swt.layout.LayoutProviderHelper;
32: import org.eclipse.emf.ecp.view.spi.swt.reporting.RenderingFailedReport;
33: import org.eclipse.emfforms.spi.common.report.ReportService;
34: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
35: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
36: import org.eclipse.emfforms.spi.swt.core.EMFFormsRendererFactory;
37: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
38: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
39: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
40: import org.eclipse.swt.SWT;
41: import org.eclipse.swt.widgets.Composite;
42: import org.eclipse.swt.widgets.Control;
43:
44: /**
45: * The SWT Renderer for the {@link VHorizontalLayout}. It renders all elements next to each other.
46: *
47: * @author Eugen Neufeld
48: * @since 1.2
49: *
50: */
51: public class HorizontalLayoutSWTRenderer extends AbstractSWTRenderer<VHorizontalLayout> {
52:
53:         private final EMFFormsRendererFactory rendererFactory;
54:
55:         /**
56:          * Default Constructor.
57:          *
58:          * @param vElement the view element to be rendered
59:          * @param viewContext The view model context
60:          * @param reportService the ReportService to use
61:          * @param rendererFactory the EMFFormsRendererFactory to use
62:          * @since 1.6
63:          */
64:         @Inject
65:         public HorizontalLayoutSWTRenderer(final VHorizontalLayout vElement, final ViewModelContext viewContext,
66:                 ReportService reportService, EMFFormsRendererFactory rendererFactory) {
67:                 super(vElement, viewContext, reportService);
68:                 this.rendererFactory = rendererFactory;
69:         }
70:
71:         private static final String CONTROL_COLUMN_COMPOSITE = "org_eclipse_emf_ecp_ui_layout_horizontal"; //$NON-NLS-1$
72:         private SWTGridDescription rendererGridDescription;
73:
74:         /**
75:          * {@inheritDoc}
76:          *
77:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#dispose()
78:          */
79:         @Override
80:         protected void dispose() {
81:                 rendererGridDescription = null;
82:                 super.dispose();
83:         }
84:
85:         /**
86:          * {@inheritDoc}
87:          *
88:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#getGridDescription(SWTGridDescription)
89:          */
90:         @Override
91:         public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
92:•                if (rendererGridDescription == null) {
93:                         rendererGridDescription = GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 1, this);
94:                         rendererGridDescription.getGrid().get(0).setVerticalGrab(false);
95:                 }
96:                 return rendererGridDescription;
97:         }
98:
99:         /**
100:          * {@inheritDoc}
101:          *
102:          * @see org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer#renderControl(int, org.eclipse.swt.widgets.Composite,
103:          * org.eclipse.emf.ecp.view.spi.model.VElement, org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
104:          */
105:         @Override
106:         protected Control renderControl(SWTGridCell gridCell, Composite parent) throws NoRendererFoundException,
107:                 NoPropertyDescriptorFoundExeption {
108:•                if (gridCell.getColumn() != 0) {
109:                         return null;
110:                 }
111:                 final Composite columnComposite = new Composite(parent, SWT.NONE);
112:                 columnComposite.setBackground(parent.getBackground());
113:                 columnComposite.setData(CUSTOM_VARIANT, CONTROL_COLUMN_COMPOSITE);
114:
115:                 final Map<VContainedElement, AbstractSWTRenderer<VElement>> elementRendererMap = new LinkedHashMap<VContainedElement, AbstractSWTRenderer<VElement>>();
116:•                for (final VContainedElement child : getVElement().getChildren()) {
117:
118:                         AbstractSWTRenderer<VElement> renderer;
119:                         try {
120:                                 renderer = rendererFactory.getRendererInstance(child,
121:                                         getViewModelContext());
122:                         } catch (final EMFFormsNoRendererException ex) {
123:                                 getReportService().report(new StatusReport(
124:                                         new Status(IStatus.INFO, "org.eclipse.emf.ecp.view.horizontal.ui.swt", //$NON-NLS-1$
125:                                                 String.format("No Renderer for %s found.", child.eClass().getName())))); //$NON-NLS-1$
126:                                 continue;
127:                         }
128:                         elementRendererMap.put(child, renderer);
129:                 }
130:                 // Gridlayout does not have an overflow as other Layouts might have.
131:
132:                 columnComposite.setLayout(LayoutProviderHelper.getColumnLayout(elementRendererMap.size(), true));
133:•                for (final VContainedElement child : elementRendererMap.keySet()) {
134:                         final AbstractSWTRenderer<VElement> renderer = elementRendererMap.get(child);
135:                         final Composite column = new Composite(columnComposite, SWT.NONE);
136:                         column.setBackground(parent.getBackground());
137:
138:                         column.setLayoutData(LayoutProviderHelper.getSpanningLayoutData(1, 1));
139:
140:                         final SWTGridDescription gridDescription = renderer.getGridDescription(GridDescriptionFactory.INSTANCE
141:                                 .createEmptyGridDescription());
142:                         column.setLayout(LayoutProviderHelper.getColumnLayout(gridDescription.getColumns(), false));
143:
144:                         try {
145:•                                for (final SWTGridCell childGridCell : gridDescription.getGrid()) {
146:                                         final Control control = childGridCell.getRenderer().render(childGridCell, column);
147:•                                        if (control == null) {
148:                                                 continue;
149:                                         }
150:                                         // TODO who should apply the layout
151:                                         control.setLayoutData(LayoutProviderHelper.getLayoutData(childGridCell, gridDescription,
152:                                                 gridDescription, gridDescription, childGridCell.getRenderer().getVElement(),
153:                                                 getViewModelContext().getDomainModel(), control));
154:                                 }
155:•                                for (final SWTGridCell childGridCell : gridDescription.getGrid()) {
156:                                         childGridCell.getRenderer().finalizeRendering(column);
157:                                 }
158:                         } catch (final NoPropertyDescriptorFoundExeption e) {
159:                                 getReportService().report(new RenderingFailedReport(e));
160:                                 continue;
161:                         }
162:                 }
163:
164:                 return columnComposite;
165:         }
166:
167: }