Skip to content

Package: SimpleControlSWTRendererUtil

SimpleControlSWTRendererUtil

nameinstructionbranchcomplexitylinemethod
createControlCell(int, AbstractSWTRenderer)
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
createLabelCell(int, AbstractSWTRenderer, Optional)
M: 0 C: 40
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
createValidationCell(int, AbstractSWTRenderer)
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
showLabel(VControl, ReportService, String)
M: 0 C: 35
100%
M: 0 C: 3
100%
M: 0 C: 3
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 7
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-2018 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.core.swt;
15:
16: import java.text.MessageFormat;
17:
18: import org.eclipse.core.runtime.IStatus;
19: import org.eclipse.emf.ecp.view.spi.model.LabelAlignment;
20: import org.eclipse.emf.ecp.view.spi.model.VControl;
21: import org.eclipse.emf.ecp.view.spi.model.VElement;
22: import org.eclipse.emfforms.common.Optional;
23: import org.eclipse.emfforms.spi.common.report.AbstractReport;
24: import org.eclipse.emfforms.spi.common.report.ReportService;
25: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
26: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
27: import org.eclipse.swt.SWT;
28: import org.eclipse.swt.graphics.Point;
29:
30: /**
31: * Holds some Util methods for the {@link SimpleControlSWTRenderer} which may be reused by renderers which cannot
32: * inherit from {@link SimpleControlSWTRenderer} but want to reuse functionality.
33: *
34: * @author Johannes Faltermeier
35: * @since 1.17
36: *
37: */
38: public final class SimpleControlSWTRendererUtil {
39:
40:         private static final Point VALIDATION_PREFERRED_SIZE = new Point(16, 17);
41:
42:         private SimpleControlSWTRendererUtil() {
43:                 /* util */
44:         }
45:
46:         /**
47:          * Whether to create a label cell on the left in the same row.
48:          *
49:          * @param control the rendered {@link VControl}
50:          * @param reportService the {@link ReportService}
51:          * @param rendererName the name of the current renderer for logging
52:          * @return <code>true</code> if label grid cell should be created, <code>false</code> otherwise
53:          */
54:         public static boolean showLabel(VControl control, ReportService reportService, String rendererName) {
55:•                switch (control.getLabelAlignment()) {
56:                 case DEFAULT:
57:                 case LEFT:
58:                         return true;
59:                 case NONE:
60:                         return false;
61:                 default:
62:                         reportService.report(new AbstractReport(MessageFormat.format(
63:                                 "Label alignment {0} is not supported by renderer {1}. Label alignment set to default.", //$NON-NLS-1$
64:                                 control.getLabelAlignment().getLiteral(), rendererName), IStatus.INFO));
65:                         control.setLabelAlignment(LabelAlignment.DEFAULT);
66:                         return true;
67:                 }
68:         }
69:
70:         /**
71:          * Creates the cell for the label.
72:          *
73:          * @param column the column index
74:          * @param renderer the renderer
75:          * @param labelWidth the width for the label
76:          * @return the grid cell
77:          */
78:         public static SWTGridCell createLabelCell(
79:                 int column,
80:                 AbstractSWTRenderer<? extends VElement> renderer,
81:                 Optional<Integer> labelWidth) {
82:
83:                 final SWTGridCell labelCell = new SWTGridCell(0, column, renderer);
84:                 labelCell.setHorizontalGrab(false);
85:                 labelCell.setVerticalGrab(false);
86:                 labelCell.setHorizontalFill(false);
87:                 labelCell.setHorizontalAlignment(SWTGridCell.Alignment.BEGINNING);
88:                 labelCell.setVerticalFill(false);
89:                 labelCell.setVerticalAlignment(SWTGridCell.Alignment.CENTER);
90:                 labelCell.setRenderer(renderer);
91:•                if (labelWidth.isPresent()) {
92:                         labelCell.setPreferredSize(labelWidth.get(), SWT.DEFAULT);
93:                 }
94:                 return labelCell;
95:         }
96:
97:         /**
98:          * Creates the validation cell.
99:          *
100:          * @param column the column index.
101:          * @param renderer the renderer
102:          * @return the grid cell
103:          */
104:         public static SWTGridCell createValidationCell(int column, AbstractSWTRenderer<? extends VElement> renderer) {
105:                 final SWTGridCell validationCell = new SWTGridCell(0, column, renderer);
106:                 validationCell.setHorizontalGrab(false);
107:                 validationCell.setVerticalGrab(false);
108:                 validationCell.setHorizontalFill(false);
109:                 validationCell.setHorizontalAlignment(SWTGridCell.Alignment.CENTER);
110:                 validationCell.setVerticalFill(false);
111:                 validationCell.setVerticalAlignment(SWTGridCell.Alignment.CENTER);
112:                 validationCell.setRenderer(renderer);
113:                 validationCell.setPreferredSize(VALIDATION_PREFERRED_SIZE);
114:                 return validationCell;
115:         }
116:
117:         /**
118:          * Creates the control cell.
119:          *
120:          * @param column the column index
121:          * @param renderer the renderer
122:          * @return the grid cell
123:          */
124:         public static SWTGridCell createControlCell(int column, AbstractSWTRenderer<? extends VElement> renderer) {
125:                 final SWTGridCell controlCell = new SWTGridCell(0, column, renderer);
126:                 controlCell.setHorizontalGrab(true);
127:                 controlCell.setVerticalGrab(false);
128:                 controlCell.setHorizontalFill(true);
129:                 controlCell.setVerticalFill(true);
130:                 controlCell.setVerticalAlignment(SWTGridCell.Alignment.CENTER);
131:                 controlCell.setRenderer(renderer);
132:                 return controlCell;
133:         }
134: }