Skip to content

Package: CompactVerticallyTableViewerCompositeBuilder

CompactVerticallyTableViewerCompositeBuilder

nameinstructionbranchcomplexitylinemethod
CompactVerticallyTableViewerCompositeBuilder(boolean, boolean)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
createButtonComposite(Composite)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
createCompositeLayout(Composite)
M: 93 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
createTitleLabel(Composite, Color)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
createValidationLabel(Composite)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
createViewerComposite(Composite)
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getButtonComposite()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTitleLabel()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValidationControls()
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getViewerComposite()
M: 3 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-2015 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: * Stefan Dirix - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.table;
15:
16: import java.util.Collections;
17: import java.util.List;
18:
19: import org.eclipse.emfforms.common.Optional;
20: import org.eclipse.jface.layout.GridDataFactory;
21: import org.eclipse.jface.layout.GridLayoutFactory;
22: import org.eclipse.swt.SWT;
23: import org.eclipse.swt.graphics.Color;
24: import org.eclipse.swt.widgets.Composite;
25: import org.eclipse.swt.widgets.Control;
26: import org.eclipse.swt.widgets.Label;
27:
28: /**
29: * Vertically Compact implementation of the {@link TableViewerCompositeBuilder}.
30: *
31: * @author Stefan Dirix
32: * @since 1.14
33: *
34: */
35: public class CompactVerticallyTableViewerCompositeBuilder implements TableViewerCompositeBuilder {
36:
37:         private Label titleLabel;
38:         private Label validationLabel;
39:         private Composite buttonComposite;
40:         private Composite viewerComposite;
41:         private final boolean createTitleLabel;
42:         private final boolean createValidationLabel;
43:
44:         /**
45:          * Constructor.
46:          *
47:          * @param createTitleLabel indicates whether to create a title label.
48:          * @param createValidationLabel indicates whether to create a validation label.
49:          */
50:         public CompactVerticallyTableViewerCompositeBuilder(boolean createTitleLabel, boolean createValidationLabel) {
51:                 this.createTitleLabel = createTitleLabel;
52:                 this.createValidationLabel = createValidationLabel;
53:         }
54:
55:         @Override
56:         public void createCompositeLayout(Composite parent) {
57:                 GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent);
58:
59:                 /* Overall Layout */
60:                 final Composite composite = new Composite(parent, SWT.NONE);
61:                 GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
62:
63:•                final int numberOfColumns = createTitleLabel || createValidationLabel ? 3 : 2;
64:                 GridLayoutFactory.fillDefaults().numColumns(numberOfColumns).applyTo(composite);
65:
66:                 /* Title + Validation Composite */
67:•                if (createTitleLabel || createValidationLabel) {
68:                         final Composite frontComposite = new Composite(composite, SWT.NONE);
69:                         GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.BEGINNING)
70:                                 .applyTo(frontComposite);
71:•                        final int numberOfFrontColumns = createTitleLabel && createValidationLabel ? 2 : 1;
72:                         GridLayoutFactory.fillDefaults().numColumns(numberOfFrontColumns).equalWidth(false).applyTo(frontComposite);
73:                         titleLabel = createTitleLabel(frontComposite, parent.getBackground());
74:                         validationLabel = createValidationLabel(frontComposite);
75:                 }
76:
77:                 /* Viewer composite */
78:                 viewerComposite = createViewerComposite(composite);
79:
80:                 /* Button composite */
81:                 buttonComposite = createButtonComposite(composite);
82:         }
83:
84:         /**
85:          * Returns the {@link Label} displaying the table viewer's label. Can be overwritten to customize the label's
86:          * appearance.
87:          *
88:          * @param parentComposite The parent composite of the created label
89:          * @param background The background color of the label
90:          *
91:          * @return The title label
92:          */
93:         protected Label createTitleLabel(final Composite parentComposite, Color background) {
94:                 final Label titleLabel = new Label(parentComposite, SWT.NONE);
95:                 titleLabel.setBackground(background);
96:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).applyTo(titleLabel);
97:                 return titleLabel;
98:         }
99:
100:         /**
101:          * Creates and returns the button composite used by this table viewer. Can be overwritten to customize the
102:          * composite's appearance and placement.
103:          *
104:          * @param parentComposite The composite that will contain the button composite
105:          * @return The button composite
106:          */
107:         protected Composite createButtonComposite(final Composite parentComposite) {
108:                 final Composite buttonComposite = new Composite(parentComposite, SWT.NONE);
109:                 buttonComposite.setBackground(parentComposite.getBackground());
110:                 GridDataFactory.fillDefaults().align(SWT.END, SWT.BEGINNING).grab(false, false)
111:                         .applyTo(buttonComposite);
112:                 return buttonComposite;
113:         }
114:
115:         /**
116:          * Called to create the composite for the table viewer.
117:          *
118:          * @param composite the parent
119:          * @return the composite
120:          */
121:         protected Composite createViewerComposite(final Composite composite) {
122:                 final Composite viewerComposite = new Composite(composite, SWT.NONE);
123:                 GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).hint(1, 200)
124:                         .applyTo(viewerComposite);
125:                 GridLayoutFactory.fillDefaults().numColumns(1).applyTo(viewerComposite);
126:                 return viewerComposite;
127:         }
128:
129:         /**
130:          * Called to create the validation label.
131:          *
132:          * @param topComposite the parent
133:          * @return the label
134:          */
135:         protected Label createValidationLabel(final Composite topComposite) {
136:                 final Label validationLabel = new Label(topComposite, SWT.NONE);
137:                 validationLabel.setBackground(topComposite.getBackground());
138:                 GridDataFactory.fillDefaults().hint(16, 17).grab(false, false).applyTo(validationLabel);
139:                 return validationLabel;
140:         }
141:
142:         @Override
143:         public Optional<Label> getTitleLabel() {
144:                 return Optional.ofNullable(titleLabel);
145:         }
146:
147:         @Override
148:         public Optional<List<Control>> getValidationControls() {
149:•                if (validationLabel != null) {
150:                         return Optional.of(Collections.<Control> singletonList(validationLabel));
151:                 }
152:                 return Optional.empty();
153:         }
154:
155:         @Override
156:         public Optional<Composite> getButtonComposite() {
157:                 return Optional.ofNullable(buttonComposite);
158:         }
159:
160:         @Override
161:         public Composite getViewerComposite() {
162:                 return viewerComposite;
163:         }
164:
165: }