Skip to content

Package: TableViewerSWTBuilder

TableViewerSWTBuilder

nameinstructionbranchcomplexitylinemethod
TableViewerSWTBuilder(Composite, int, Object, IObservableValue, IObservableValue)
M: 0 C: 29
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
addColumn(ColumnConfiguration)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
build()
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
columnRegexFilter(boolean)
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
columnSubstringFilter(boolean)
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
configureTable(TableConfiguration)
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%
customizeActionBar(ActionBar)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
customizeActionConfiguration(ActionConfiguration)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
customizeComparator(ViewerComparator)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
customizeCompositeStructure(TableViewerCompositeBuilder)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
customizeContentProvider(IContentProvider)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
customizeDragAndDrop(DNDProvider)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
customizeTableViewerCreation(TableViewerCreator)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getComposite()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getCustomization()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getEnabledFeatures()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getInput()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSupportedFeatures()
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%
getSwtStyleBits()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getTitle()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getTooltip()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
showHideColumns(boolean)
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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: * Alexandra Buzila - initial API and implementation
13: * Johannes Faltermeier - initial API and implementation
14: * Mat Hansen - builder refactoring
15: * Christian W. Damus - bugs 534829, 530314
16: ******************************************************************************/
17: package org.eclipse.emfforms.spi.swt.table;
18:
19: import java.util.LinkedHashSet;
20: import java.util.Set;
21:
22: import org.eclipse.core.databinding.observable.value.IObservableValue;
23: import org.eclipse.emfforms.common.Feature;
24: import org.eclipse.emfforms.internal.swt.table.DefaultTableControlSWTCustomization;
25: import org.eclipse.emfforms.spi.swt.table.action.ActionBar;
26: import org.eclipse.emfforms.spi.swt.table.action.ActionConfiguration;
27: import org.eclipse.jface.viewers.AbstractTableViewer;
28: import org.eclipse.jface.viewers.IContentProvider;
29: import org.eclipse.jface.viewers.Viewer;
30: import org.eclipse.jface.viewers.ViewerComparator;
31: import org.eclipse.swt.widgets.Composite;
32:
33: /**
34: * Builder class for creating a {@link TableViewerComposite}.
35: *
36: * @author Alexandra Buzila
37: * @author Johannes Faltermeier
38: * @author Mat Hansen
39: *
40: */
41: @SuppressWarnings("deprecation")
42: public class TableViewerSWTBuilder extends AbstractFeatureAwareBuilder<TableViewerSWTBuilder> {
43:
44:         private boolean tableConfigured;
45:
46:         /** The parent composite. */
47:         private final Composite composite;
48:         /** The style bits. */
49:         private final int swtStyleBits;
50:         /** The input object. */
51:         private final Object input;
52:         /** The table control customization. */
53:         private final DefaultTableControlSWTCustomization customization;
54:         /** The title. */
55:         private final IObservableValue title;
56:         /** The tooltip. */
57:         private final IObservableValue tooltip;
58:
59:         private final Set<Feature> features = new LinkedHashSet<Feature>();
60:
61:         /**
62:          * @param composite the parent {@link Composite}
63:          * @param swtStyleBits the swt style bits
64:          * @param input the input object
65:          * @param title the title
66:          * @param tooltip the tooltip
67:          */
68:         @SuppressWarnings("rawtypes")
69:         protected TableViewerSWTBuilder(Composite composite, int swtStyleBits, Object input, IObservableValue title,
70:                 IObservableValue tooltip) {
71:
72:                 this.composite = composite;
73:                 this.swtStyleBits = swtStyleBits;
74:                 this.input = input;
75:                 this.title = title;
76:                 this.tooltip = tooltip;
77:                 customization = new DefaultTableControlSWTCustomization() {
78:
79:                         @Override
80:                         public TableConfiguration getTableConfiguration() {
81:                                 // if the table hasn't been configured, do it now (using defaults)
82:                                 if (!tableConfigured) {
83:                                         configureTable(TableConfigurationBuilder.withFeatures(features).build());
84:                                 }
85:                                 return super.getTableConfiguration();
86:                         }
87:
88:                 };
89:         }
90:
91:         /**
92:          * @return the composite
93:          */
94:         protected Composite getComposite() {
95:                 return composite;
96:         }
97:
98:         /**
99:          * @return the swtStyleBits
100:          */
101:         protected int getSwtStyleBits() {
102:                 return swtStyleBits;
103:         }
104:
105:         /**
106:          * @return the input
107:          */
108:         protected Object getInput() {
109:                 return input;
110:         }
111:
112:         /**
113:          * @return the customization
114:          */
115:         public TableViewerSWTCustomization<?> getCustomization() {
116:                 return customization;
117:         }
118:
119:         /**
120:          * @return the title
121:          */
122:         protected IObservableValue getTitle() {
123:                 return title;
124:         }
125:
126:         /**
127:          * @return the tooltip
128:          */
129:         protected IObservableValue getTooltip() {
130:                 return tooltip;
131:         }
132:
133:         /**
134:          * <p>
135:          * Use this method to customize the way title, validation, buttons and the tableviewer are arranged.
136:          * </p>
137:          * <p>
138:          * The default implementation will create a title bar with title to left, a validation label in the middle and a
139:          * button bar on the right. Below the title bar the viewer will be created
140:          * </p>
141:          *
142:          * @param builder the {@link TableViewerCompositeBuilder}
143:          * @return self
144:          */
145:         public TableViewerSWTBuilder customizeCompositeStructure(TableViewerCompositeBuilder builder) {
146:                 customization.setTableViewerCompositeBuilder(builder);
147:                 return this;
148:         }
149:
150:         /**
151:          * <p>
152:          * Use this method to create the actual TableViewer.
153:          * </p>
154:          * <p>
155:          * The default implementation will create a viewer with the SWT#MULTI, SWT#V_SCROLL,
156:          * FULL_SELECTION and SWT#BORDER style bits. The table will show the
157:          * {@link org.eclipse.swt.widgets.Table#setHeaderVisible(boolean) header} and will show
158:          * {@link org.eclipse.swt.widgets.Table#setLinesVisible(boolean) lines}.
159:          * </p>
160:          *
161:          * @param creator the {@link TableViewerCreator}
162:          * @return self
163:          */
164:         @SuppressWarnings("unchecked")
165:         public TableViewerSWTBuilder customizeTableViewerCreation(
166:                 TableViewerCreator<? extends AbstractTableViewer> creator) {
167:                 customization.setTableViewerCreator(creator);
168:                 return this;
169:         }
170:
171:         /**
172:          * <p>
173:          * Use this method to set a {@link ViewerComparator} on the table.
174:          * </p>
175:          * <p>
176:          * The default implementation does not add a comparator.
177:          * </p>
178:          *
179:          * @param comparator the {@link ViewerComparator}
180:          * @return self
181:          */
182:         public TableViewerSWTBuilder customizeComparator(ViewerComparator comparator) {
183:                 customization.setViewerComparator(comparator);
184:                 return this;
185:         }
186:
187:         /**
188:          * <p>
189:          * Use this method to set a different content provider on the viewer.
190:          * </p>
191:          * <p>
192:          * The default implementation uses a {@link org.eclipse.jface.databinding.viewers.ObservableListContentProvider
193:          * ObservableListContentProvider}.
194:          * </p>
195:          *
196:          * @param provider the {@link IContentProvider} to use
197:          * @return self
198:          */
199:         public TableViewerSWTBuilder customizeContentProvider(IContentProvider provider) {
200:                 customization.setContentProvider(provider);
201:                 return this;
202:         }
203:
204:         /**
205:          * <p>
206:          * Use this method to customize the way the button bar is filled.
207:          * </p>
208:          * <p>
209:          * The default behavior will not add any buttons.
210:          * </p>
211:          *
212:          * @param actionBar the {@link ActionBar}
213:          * @return self
214:          */
215:         @SuppressWarnings("unchecked")
216:         public TableViewerSWTBuilder customizeActionBar(ActionBar<? extends Viewer> actionBar) {
217:                 customization.setActionBar(actionBar);
218:                 return this;
219:         }
220:
221:         /**
222:          * <p>
223:          * Use this method to customize the key bindings for the table viewer.
224:          * </p>
225:          * <p>
226:          * The default behavior will not register any bindings.
227:          * </p>
228:          *
229:          * @param actionConfiguration the {@link ActionConfiguration}
230:          * @return self
231:          */
232:         public TableViewerSWTBuilder customizeActionConfiguration(ActionConfiguration actionConfiguration) {
233:                 customization.setActionConfiguration(actionConfiguration);
234:                 return this;
235:         }
236:
237:         /**
238:          * <p>
239:          * Use this method to customize drag&drop.
240:          * </p>
241:          * <p>
242:          * The default behaviour disables drag&drop.
243:          * </p>
244:          *
245:          * @param provider the provider
246:          * @return self
247:          */
248:         public TableViewerSWTBuilder customizeDragAndDrop(DNDProvider provider) {
249:                 customization.setDND(provider);
250:                 return this;
251:         }
252:
253:         /**
254:          * Configures the current table instance using the given configuration.
255:          *
256:          * @param tableConfiguration the {@link TableConfiguration} to add
257:          * @return self
258:          */
259:         public TableViewerSWTBuilder configureTable(TableConfiguration tableConfiguration) {
260:                 customization.configureTable(tableConfiguration);
261:                 tableConfigured = true;
262:                 return this;
263:         }
264:
265:         /**
266:          * Adds a new column.
267:          *
268:          * @param columnConfiguration the {@link ColumnConfiguration} to add
269:          * @return self
270:          */
271:         public TableViewerSWTBuilder addColumn(ColumnConfiguration columnConfiguration) {
272:                 customization.addColumn(columnConfiguration);
273:                 return this;
274:         }
275:
276:         /**
277:          * @deprecated Since 1.21, use the {@link #showHideColumns(boolean)} and similar
278:          * builder methods, instead
279:          * @see #showHideColumns(boolean)
280:          * @see #columnSubstringFilter(boolean)
281:          * @see #columnRegexFilter(boolean)
282:          */
283:         @Override
284:         @Deprecated
285:         public Set<Feature> getSupportedFeatures() {
286:                 return new LinkedHashSet<Feature>(TableConfiguration.ALL_FEATURES);
287:         }
288:
289:         /**
290:          * @deprecated Since 1.21, use the {@link #showHideColumns(boolean)} and similar
291:          * builder methods, instead
292:          * @see #showHideColumns(boolean)
293:          * @see #columnSubstringFilter(boolean)
294:          * @see #columnRegexFilter(boolean)
295:          */
296:         @Override
297:         @Deprecated
298:         public Set<Feature> getEnabledFeatures() {
299:                 return features;
300:         }
301:
302:         /**
303:          * Set whether support for users to show and hide columns is installed.
304:          *
305:          * @param showHideColumns {@code true} to enable showing and hiding of columns; {@code false} to disable it
306:          * @return this builder, for fluent chaining
307:          *
308:          * @since 1.21
309:          */
310:         public TableViewerSWTBuilder showHideColumns(boolean showHideColumns) {
311:•                return showHideColumns ? enableFeature(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW)
312:                         : disableFeature(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW);
313:         }
314:
315:         /**
316:          * Set whether support for users to show a simple substring-matching filter on columns
317:          * is installed.
318:          *
319:          * @param columnSubstringFilter {@code true} to enable the substring filter; {@code false} to disable it
320:          * @return this builder, for fluent chaining
321:          *
322:          * @since 1.21
323:          */
324:         public TableViewerSWTBuilder columnSubstringFilter(boolean columnSubstringFilter) {
325:•                return columnSubstringFilter ? enableFeature(TableConfiguration.FEATURE_COLUMN_FILTER)
326:                         : disableFeature(TableConfiguration.FEATURE_COLUMN_FILTER);
327:         }
328:
329:         /**
330:          * Set whether support for users to show a regular expression filter on columns
331:          * is installed.
332:          *
333:          * @param columnRegexFilter {@code true} to enable the regex filter; {@code false} to disable it
334:          * @return this builder, for fluent chaining
335:          *
336:          * @since 1.21
337:          */
338:         public TableViewerSWTBuilder columnRegexFilter(boolean columnRegexFilter) {
339:•                return columnRegexFilter ? enableFeature(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER)
340:                         : disableFeature(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER);
341:         }
342:
343:         /**
344:          * Call this method after all desired customizations have been passed to the builder. The will create a new
345:          * {@link TableViewerComposite} with the desired customizations.
346:          *
347:          * @return the {@link TableViewerComposite}
348:          */
349:         public AbstractTableViewerComposite<? extends AbstractTableViewer> build() {
350:
351:                 final AbstractTableViewerComposite<? extends AbstractTableViewer> viewerComposite = //
352:                         new TableViewerComposite(composite, swtStyleBits, input, customization, title, tooltip);
353:
354:                 viewerComposite.setData(TableConfiguration.ID, customization.getTableConfiguration());
355:
356:                 return viewerComposite;
357:         }
358:
359: }