Skip to content

Package: GridDescriptionFactory

GridDescriptionFactory

nameinstructionbranchcomplexitylinemethod
createCompactGrid(boolean, boolean, AbstractSWTRenderer)
M: 1 C: 55
98%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 0 C: 9
100%
M: 0 C: 1
100%
createDefaultCompactLabelCell(int, AbstractSWTRenderer)
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
createDefaultCompactMainCell(int, AbstractSWTRenderer)
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
createDefaultCompactValidationCell(int, AbstractSWTRenderer)
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
createEmptyGridDescription()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createSimpleGrid(int, int, AbstractSWTRenderer)
M: 0 C: 37
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
static {...}
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%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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 - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.core.layout;
15:
16: import java.util.ArrayList;
17: import java.util.LinkedList;
18: import java.util.List;
19:
20: import org.eclipse.emf.ecp.view.spi.model.VElement;
21: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
22: import org.eclipse.swt.graphics.Point;
23:
24: /**
25: * A Factory to create {@link SWTGridDescription GridDescriptions}.
26: *
27: * @author Eugen Neufeld
28: * @since 1.3
29: *
30: */
31: public final class GridDescriptionFactory {
32:
33:         /**
34:          * The static Instance of the Factory.
35:          */
36:         public static final GridDescriptionFactory INSTANCE = new GridDescriptionFactory();
37:
38:         private GridDescriptionFactory() {
39:
40:         }
41:
42:         /**
43:          * Creates an empty grid description.
44:          *
45:          * @return the {@link SWTGridDescription}
46:          */
47:         public SWTGridDescription createEmptyGridDescription() {
48:                 return new SWTGridDescription();
49:         }
50:
51:         /**
52:          * Creates a simple grid based on the number of rows and columns provided.
53:          *
54:          * @param rows the number of rows in this grid
55:          * @param columns the number of columns in this grid
56:          * @param renderer the {@link AbstractSWTRenderer}
57:          * @return the {@link SWTGridDescription}
58:          */
59:         public SWTGridDescription createSimpleGrid(int rows, int columns,
60:                 AbstractSWTRenderer<? extends VElement> renderer) {
61:                 final List<SWTGridCell> gridCells = new ArrayList<SWTGridCell>(rows * columns);
62:•                for (int row = 0; row < rows; row++) {
63:•                        for (int column = 0; column < columns; column++) {
64:                                 gridCells.add(new SWTGridCell(row, column, renderer));
65:                         }
66:                 }
67:                 return new SWTGridDescription(rows, columns, gridCells);
68:         }
69:
70:         /**
71:          * Creates the default compact grid.
72:          *
73:          * @param label indicates whether a label cell shall be added
74:          * @param validation indicates whether a validation cell shall be added
75:          * @param renderer the {@link AbstractSWTRenderer}
76:          * @return the {@link SWTGridDescription}
77:          *
78:          * @since 1.17
79:          */
80:         public SWTGridDescription createCompactGrid(boolean label, boolean validation,
81:                 AbstractSWTRenderer<? extends VElement> renderer) {
82:                 final List<SWTGridCell> gridCells = new LinkedList<SWTGridCell>();
83:•                if (label) {
84:                         gridCells.add(createDefaultCompactLabelCell(0, renderer));
85:                 }
86:•                if (validation) {
87:•                        final int validationColumn = label ? 1 : 0;
88:                         gridCells.add(createDefaultCompactValidationCell(validationColumn, renderer));
89:                 }
90:•                final int mainColumn = (label ? 1 : 0) + (validation ? 1 : 0);
91:                 gridCells.add(createDefaultCompactMainCell(mainColumn, renderer));
92:                 return new SWTGridDescription(1, mainColumn + 1, gridCells);
93:         }
94:
95:         private SWTGridCell createDefaultCompactLabelCell(int column, AbstractSWTRenderer<? extends VElement> renderer) {
96:                 final SWTGridCell labelCell = new SWTGridCell(0, column, renderer);
97:                 labelCell.setHorizontalGrab(false);
98:                 labelCell.setVerticalGrab(false);
99:                 labelCell.setHorizontalFill(false);
100:                 labelCell.setHorizontalAlignment(SWTGridCell.Alignment.BEGINNING);
101:                 labelCell.setVerticalFill(false);
102:                 labelCell.setVerticalAlignment(SWTGridCell.Alignment.BEGINNING);
103:                 labelCell.setPreferredSize(null);
104:                 return labelCell;
105:         }
106:
107:         private SWTGridCell createDefaultCompactValidationCell(int column,
108:                 AbstractSWTRenderer<? extends VElement> renderer) {
109:                 final SWTGridCell validationCell = new SWTGridCell(0, column, renderer);
110:                 validationCell.setHorizontalGrab(false);
111:                 validationCell.setVerticalGrab(false);
112:                 validationCell.setHorizontalFill(false);
113:                 validationCell.setHorizontalAlignment(SWTGridCell.Alignment.CENTER);
114:                 validationCell.setVerticalFill(false);
115:                 validationCell.setVerticalAlignment(SWTGridCell.Alignment.BEGINNING);
116:                 validationCell.setPreferredSize(new Point(16, 17));
117:                 return validationCell;
118:         }
119:
120:         private SWTGridCell createDefaultCompactMainCell(int column,
121:                 AbstractSWTRenderer<? extends VElement> renderer) {
122:                 final SWTGridCell mainCell = new SWTGridCell(0, column, renderer);
123:                 mainCell.setHorizontalGrab(true);
124:                 mainCell.setVerticalGrab(true);
125:                 mainCell.setHorizontalFill(true);
126:                 mainCell.setHorizontalAlignment(SWTGridCell.Alignment.CENTER);
127:                 mainCell.setVerticalFill(true);
128:                 mainCell.setVerticalAlignment(SWTGridCell.Alignment.CENTER);
129:                 mainCell.setPreferredSize(null);
130:                 return mainCell;
131:         }
132: }