Skip to content

Package: ColumnConfigurationBuilder

ColumnConfigurationBuilder

nameinstructionbranchcomplexitylinemethod
ColumnConfigurationBuilder()
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%
ColumnConfigurationBuilder(ColumnConfiguration)
M: 51 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
ColumnConfigurationBuilder(Set)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
build()
M: 0 C: 41
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
callback(ConfigurationCallback)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
dataMap(Map)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
dataMapEntry(String, Object)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
editingSupportCreator(EditingSupportCreator)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
from(TableViewerSWTBuilder)
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%
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%
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%
image(Image)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
labelProvider(CellLabelProvider)
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%
labelProviderFactory(CellLabelProviderFactory)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
minWidth(int)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
moveable(boolean)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
regexFilter(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%
resizable(boolean)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
showHide(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%
styleBits(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
substringFilter(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%
text(IObservableValue)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
text(String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
tooltip(IObservableValue)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
tooltip(String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
usingConfiguration(ColumnConfiguration)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
usingDefaults()
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%
weight(int)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
withFeatures(Collection)
M: 0 C: 11
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-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: * Mat Hansen - initial API and implementation
13: * Christian W. Damus - bugs 534829, 530314
14: ******************************************************************************/
15: package org.eclipse.emfforms.spi.swt.table;
16:
17: import java.util.ArrayList;
18: import java.util.Collection;
19: import java.util.LinkedHashMap;
20: import java.util.LinkedHashSet;
21: import java.util.List;
22: import java.util.Map;
23: import java.util.Set;
24:
25: import org.eclipse.core.databinding.observable.Observables;
26: import org.eclipse.core.databinding.observable.value.IObservableValue;
27: import org.eclipse.emfforms.common.Feature;
28: import org.eclipse.emfforms.internal.swt.table.util.StaticCellLabelProviderFactory;
29: import org.eclipse.jface.viewers.AbstractTableViewer;
30: import org.eclipse.jface.viewers.CellLabelProvider;
31: import org.eclipse.jface.viewers.ViewerColumn;
32: import org.eclipse.swt.SWT;
33: import org.eclipse.swt.graphics.Image;
34:
35: /**
36: * Builder for {@link ColumnConfiguration}s.
37: *
38: * @author Mat Hansen <mhansen@eclipsesource.com>
39: *
40: */
41: @SuppressWarnings("deprecation")
42: public final class ColumnConfigurationBuilder extends AbstractFeatureAwareBuilder<ColumnConfigurationBuilder> {
43:
44:         private final Set<Feature> features;
45:
46:         private boolean resizeable = true;
47:         private boolean moveable; // not movable
48:         private int styleBits = SWT.NONE;
49:         private int weight = ColumnConfiguration.NO_WEIGHT;
50:         private int minWidth;
51:
52:         @SuppressWarnings("rawtypes")
53:         private IObservableValue textObservable;
54:         @SuppressWarnings("rawtypes")
55:         private IObservableValue tooltipObservable;
56:
57:         private CellLabelProviderFactory labelProviderFactory;
58:         private EditingSupportCreator editingSupportCreator;
59:
60:         private Image image;
61:         private Map<String, Object> data = new LinkedHashMap<String, Object>();
62:         private List<ConfigurationCallback<AbstractTableViewer, ViewerColumn>> configurationCallbacks;
63:
64:         /**
65:          * The default constructor.
66:          */
67:         private ColumnConfigurationBuilder() {
68:                 this(new LinkedHashSet<Feature>());
69:         }
70:
71:         /**
72:          * Initializes me with enabled {@code features}.
73:          *
74:          * @param features initially enabled features
75:          */
76:         private ColumnConfigurationBuilder(Set<Feature> features) {
77:                 super();
78:
79:                 this.features = features;
80:         }
81:
82:         /**
83:          * Returns a new {@link ColumnConfigurationBuilder} initialized using default values.
84:          *
85:          * @return self
86:          */
87:         public static ColumnConfigurationBuilder usingDefaults() {
88:                 return new ColumnConfigurationBuilder();
89:         }
90:
91:         /**
92:          * Returns a new {@link TableConfigurationBuilder} initialized using default values
93:          * with inherited {@code features}.
94:          *
95:          * @param features initially enabled features
96:          * @return a new builder initialized with the inherited {@code features}
97:          *
98:          * @since 1.21
99:          */
100:         static ColumnConfigurationBuilder withFeatures(Collection<Feature> features) {
101:                 return new ColumnConfigurationBuilder(Feature.inherit(features, ColumnConfiguration.ALL_FEATURES::contains));
102:         }
103:
104:         /**
105:          * Returns a new {@link ColumnConfigurationBuilder} initialized using an existing configuration.
106:          *
107:          * @param columnConfiguration a {@link ColumnConfiguration} to use
108:          * @return self
109:          */
110:         public static ColumnConfigurationBuilder usingConfiguration(ColumnConfiguration columnConfiguration) {
111:                 return new ColumnConfigurationBuilder(columnConfiguration);
112:         }
113:
114:         /**
115:          * Returns a new {@link TableConfigurationBuilder} initialized using an existing viewer builder.
116:          *
117:          * @param viewerBuilder a {@link TableViewerSWTBuilder} to transform to a configuration builder
118:          * @return the new configuration builder
119:          *
120:          * @since 1.21
121:          */
122:         public static ColumnConfigurationBuilder from(TableViewerSWTBuilder viewerBuilder) {
123:                 return withFeatures(viewerBuilder.getEnabledFeatures());
124:         }
125:
126:         /**
127:          * Constructor which allows to inherit an existing configuration.
128:          *
129:          * @param columnConfiguration the {@link ColumnConfiguration} to inherit.
130:          */
131:         private ColumnConfigurationBuilder(ColumnConfiguration columnConfiguration) {
132:                 this();
133:
134:                 final ColumnConfigurationImpl config = (ColumnConfigurationImpl) columnConfiguration;
135:                 resizable(config.isResizeable());
136:                 moveable(config.isMoveable());
137:                 styleBits(config.getStyleBits());
138:                 weight(config.getWeight());
139:                 minWidth(config.getMinWidth());
140:                 // skip: text, tooltip
141:                 labelProviderFactory(config.getLabelProviderFactory());
142:•                if (config.getEditingSupportCreator().isPresent()) {
143:                         editingSupportCreator(config.getEditingSupportCreator().get());
144:                 }
145:                 // skip: image, data
146:                 configurationCallbacks = config.getConfigurationCallbacks();
147:         }
148:
149:         /**
150:          * @deprecated Since 1.21, use the {@link #showHide(boolean)} and similar
151:          * builder methods, instead
152:          * @see #showHide(boolean)
153:          * @see #substringFilter(boolean)
154:          * @see #regexFilter(boolean)
155:          */
156:         @Override
157:         @Deprecated
158:         public Set<Feature> getSupportedFeatures() {
159:                 return new LinkedHashSet<Feature>(ColumnConfiguration.ALL_FEATURES);
160:         }
161:
162:         /**
163:          * @deprecated Since 1.21, use the {@link #showHide(boolean)} and similar
164:          * builder methods, instead
165:          * @see #showHide(boolean)
166:          * @see #substringFilter(boolean)
167:          * @see #regexFilter(boolean)
168:          */
169:         @Override
170:         @Deprecated
171:         protected Set<Feature> getEnabledFeatures() {
172:                 return features;
173:         }
174:
175:         /**
176:          * Set whether support for users to show and hide the column is installed.
177:          *
178:          * @param showHide {@code true} to enable showing and hiding; {@code false} to disable it
179:          * @return this builder, for fluent chaining
180:          *
181:          * @since 1.21
182:          */
183:         public ColumnConfigurationBuilder showHide(boolean showHide) {
184:•                return showHide ? enableFeature(ColumnConfiguration.FEATURE_COLUMN_HIDE_SHOW)
185:                         : disableFeature(ColumnConfiguration.FEATURE_COLUMN_HIDE_SHOW);
186:         }
187:
188:         /**
189:          * Set whether support for users to show a simple substring-matching filter
190:          * is installed.
191:          *
192:          * @param substringFilter {@code true} to enable the substring filter; {@code false} to disable it
193:          * @return this builder, for fluent chaining
194:          *
195:          * @since 1.21
196:          */
197:         public ColumnConfigurationBuilder substringFilter(boolean substringFilter) {
198:•                return substringFilter ? enableFeature(ColumnConfiguration.FEATURE_COLUMN_FILTER)
199:                         : disableFeature(ColumnConfiguration.FEATURE_COLUMN_FILTER);
200:         }
201:
202:         /**
203:          * Set whether support for users to show a regular expression filter
204:          * is installed.
205:          *
206:          * @param regexFilter {@code true} to enable the regex filter; {@code false} to disable it
207:          * @return this builder, for fluent chaining
208:          *
209:          * @since 1.21
210:          */
211:         public ColumnConfigurationBuilder regexFilter(boolean regexFilter) {
212:•                return regexFilter ? enableFeature(ColumnConfiguration.FEATURE_COLUMN_REGEX_FILTER)
213:                         : disableFeature(ColumnConfiguration.FEATURE_COLUMN_REGEX_FILTER);
214:         }
215:
216:         /**
217:          * Makes the column resizable.
218:          *
219:          * @param resizable true for resizable columns
220:          * @return self
221:          */
222:         public ColumnConfigurationBuilder resizable(boolean resizable) {
223:                 resizeable = resizable;
224:                 return this;
225:         }
226:
227:         /**
228:          * Makes the column moveable.
229:          *
230:          * @param moveable true for movable columns
231:          * @return self
232:          */
233:         public ColumnConfigurationBuilder moveable(boolean moveable) {
234:                 this.moveable = moveable;
235:                 return this;
236:         }
237:
238:         /**
239:          * Add SWT style bits.
240:          *
241:          * @param styleBits the SWT style bits
242:          * @return self
243:          */
244:         public ColumnConfigurationBuilder styleBits(int styleBits) {
245:                 this.styleBits = styleBits;
246:                 return this;
247:         }
248:
249:         /**
250:          * Add column weight.
251:          *
252:          * @param weight the weight
253:          * @return self
254:          */
255:         public ColumnConfigurationBuilder weight(int weight) {
256:                 this.weight = weight;
257:                 return this;
258:         }
259:
260:         /**
261:          * Add a minimal width.
262:          *
263:          * @param minWidth the minimal width
264:          * @return self
265:          */
266:         public ColumnConfigurationBuilder minWidth(int minWidth) {
267:                 this.minWidth = minWidth;
268:                 return this;
269:         }
270:
271:         /**
272:          * Add a text observable.
273:          *
274:          * @param textObservable the column text observable
275:          * @return self
276:          */
277:         @SuppressWarnings("rawtypes")
278:         public ColumnConfigurationBuilder text(IObservableValue textObservable) {
279:                 this.textObservable = textObservable;
280:                 return this;
281:         }
282:
283:         /**
284:          * Add a static text.
285:          *
286:          * @param text the column text
287:          * @return self
288:          */
289:         public ColumnConfigurationBuilder text(String text) {
290:                 return text(Observables.constantObservableValue(text, String.class));
291:         }
292:
293:         /**
294:          * Add a tooltip observable.
295:          *
296:          * @param tooltipObservable the tooltip observable
297:          * @return self
298:          */
299:         @SuppressWarnings("rawtypes")
300:         public ColumnConfigurationBuilder tooltip(IObservableValue tooltipObservable) {
301:                 this.tooltipObservable = tooltipObservable;
302:                 return this;
303:         }
304:
305:         /**
306:          * Add a static tooltip.
307:          *
308:          * @param tooltip the tooltip
309:          * @return self
310:          */
311:         public ColumnConfigurationBuilder tooltip(String tooltip) {
312:                 return tooltip(Observables.constantObservableValue(tooltip, String.class));
313:         }
314:
315:         /**
316:          * Add a label provider factory.
317:          *
318:          * @param labelProviderFactory the label provider factory
319:          * @return self
320:          */
321:         public ColumnConfigurationBuilder labelProviderFactory(CellLabelProviderFactory labelProviderFactory) {
322:                 this.labelProviderFactory = labelProviderFactory;
323:                 return this;
324:         }
325:
326:         /**
327:          * Add a label provider.
328:          *
329:          * @param labelProvider the label provider
330:          * @return self
331:          */
332:         public ColumnConfigurationBuilder labelProvider(CellLabelProvider labelProvider) {
333:                 return labelProviderFactory(new StaticCellLabelProviderFactory(labelProvider));
334:         }
335:
336:         /**
337:          * Add an editing support creator.
338:          *
339:          * @param editingSupportCreator the editing support creator
340:          * @return self
341:          */
342:         public ColumnConfigurationBuilder editingSupportCreator(EditingSupportCreator editingSupportCreator) {
343:                 this.editingSupportCreator = editingSupportCreator;
344:                 return this;
345:         }
346:
347:         /**
348:          * Add a column image.
349:          *
350:          * @param image the image
351:          * @return self
352:          */
353:         public ColumnConfigurationBuilder image(Image image) {
354:                 this.image = image;
355:                 return this;
356:         }
357:
358:         /**
359:          * Add a pre-initialized data map.
360:          *
361:          * @param data the data map
362:          * @return self
363:          */
364:         public ColumnConfigurationBuilder dataMap(Map<String, Object> data) {
365:•                if (!this.data.isEmpty()) {
366:                         throw new IllegalArgumentException("Data map values have already been set"); //$NON-NLS-1$
367:                 }
368:•                if (data == null) {
369:                         throw new NullPointerException("Data map cannot be null"); //$NON-NLS-1$
370:                 }
371:                 this.data = data;
372:                 return this;
373:         }
374:
375:         /**
376:          * Add a data map entry.
377:          *
378:          * @param key the data map key
379:          * @param value the data map value
380:          * @return self
381:          */
382:         public ColumnConfigurationBuilder dataMapEntry(String key, Object value) {
383:                 data.put(key, value);
384:                 return this;
385:         }
386:
387:         /**
388:          * Add a column configuration callback.
389:          *
390:          * @param callback the callback
391:          * @return self
392:          */
393:         public ColumnConfigurationBuilder callback(ConfigurationCallback<AbstractTableViewer, ViewerColumn> callback) {
394:•                if (configurationCallbacks == null) {
395:                         configurationCallbacks = //
396:                                 new ArrayList<ConfigurationCallback<AbstractTableViewer, ViewerColumn>>();
397:                 }
398:                 configurationCallbacks.add(callback);
399:                 return this;
400:         }
401:
402:         /**
403:          * Create a new {@link ColumnConfiguration} using the current builder state.
404:          *
405:          * @return the {@link ColumnConfiguration}
406:          */
407:         public ColumnConfiguration build() {
408:                 final ColumnConfiguration config = new ColumnConfigurationImpl(
409:                         features,
410:                         resizeable,
411:                         moveable,
412:                         styleBits,
413:•                        minWidth == 0 && weight == ColumnConfiguration.NO_WEIGHT ? 100 : weight,
414:                         minWidth,
415:                         textObservable,
416:                         tooltipObservable,
417:                         labelProviderFactory,
418:                         editingSupportCreator,
419:                         image,
420:                         data,
421:                         configurationCallbacks);
422:
423:                 return config;
424:         }
425:
426: }