Skip to content

Package: TableConfigurationBuilder

TableConfigurationBuilder

nameinstructionbranchcomplexitylinemethod
TableConfigurationBuilder()
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%
TableConfigurationBuilder(Set)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
TableConfigurationBuilder(TableConfiguration)
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%
build()
M: 0 C: 10
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%
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%
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%
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%
usingConfiguration(TableConfiguration)
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%
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.Collection;
18: import java.util.LinkedHashMap;
19: import java.util.LinkedHashSet;
20: import java.util.Map;
21: import java.util.Set;
22:
23: import org.eclipse.emfforms.common.Feature;
24:
25: /**
26: * Builder for {@link TableConfiguration}s.
27: *
28: * @author Mat Hansen <mhansen@eclipsesource.com>
29: *
30: */
31: @SuppressWarnings("deprecation")
32: public final class TableConfigurationBuilder extends AbstractFeatureAwareBuilder<TableConfigurationBuilder> {
33:
34:         private final Set<Feature> features;
35:
36:         private final Map<String, Object> data = new LinkedHashMap<String, Object>();
37:
38:         /**
39:          * The default constructor.
40:          */
41:         private TableConfigurationBuilder() {
42:                 this(new LinkedHashSet<Feature>());
43:         }
44:
45:         /**
46:          * Initializes me with enabled {@code features}.
47:          *
48:          * @param features initially enabled features
49:          *
50:          * @since 1.21
51:          */
52:         private TableConfigurationBuilder(Set<Feature> features) {
53:                 super();
54:
55:                 this.features = features;
56:         }
57:
58:         /**
59:          * Returns a new {@link TableConfigurationBuilder} initialized using default values.
60:          *
61:          * @return self
62:          */
63:         public static TableConfigurationBuilder usingDefaults() {
64:                 return new TableConfigurationBuilder();
65:         }
66:
67:         /**
68:          * Returns a new {@link TableConfigurationBuilder} initialized using default values
69:          * with inherited {@code features}.
70:          *
71:          * @param features initially enabled features
72:          * @return a new builder initialized with the inherited {@code features}
73:          *
74:          * @since 1.21
75:          */
76:         static TableConfigurationBuilder withFeatures(Collection<Feature> features) {
77:                 return new TableConfigurationBuilder(Feature.inherit(features, TableConfiguration.ALL_FEATURES::contains));
78:         }
79:
80:         /**
81:          * Returns a new {@link TableConfigurationBuilder} initialized using an existing configuration.
82:          *
83:          * @param tableConfiguration a {@link TableConfiguration} to use
84:          * @return self
85:          */
86:         public static TableConfigurationBuilder usingConfiguration(TableConfiguration tableConfiguration) {
87:                 return new TableConfigurationBuilder(tableConfiguration);
88:         }
89:
90:         /**
91:          * Returns a new {@link TableConfigurationBuilder} initialized using an existing viewer builder.
92:          *
93:          * @param viewerBuilder a {@link TableViewerSWTBuilder} to transform to a configuration builder
94:          * @return the new configuration builder
95:          *
96:          * @since 1.21
97:          */
98:         public static TableConfigurationBuilder from(TableViewerSWTBuilder viewerBuilder) {
99:                 return withFeatures(viewerBuilder.getEnabledFeatures());
100:         }
101:
102:         /**
103:          * Constructor which allows to inherit an existing configuration.
104:          *
105:          * @param tableConfiguration the {@link TableConfiguration} to inherit.
106:          *
107:          * @since 1.21
108:          */
109:         private TableConfigurationBuilder(TableConfiguration tableConfiguration) {
110:                 this(tableConfiguration.getEnabledFeatures());
111:                 // skip: data
112:         }
113:
114:         /**
115:          * @deprecated Since 1.21, use the {@link #showHideColumns(boolean)} and similar
116:          * builder methods, instead
117:          * @see #showHideColumns(boolean)
118:          * @see #columnSubstringFilter(boolean)
119:          * @see #columnRegexFilter(boolean)
120:          */
121:         @Override
122:         @Deprecated
123:         public Set<Feature> getSupportedFeatures() {
124:                 return new LinkedHashSet<Feature>(TableConfiguration.ALL_FEATURES);
125:         }
126:
127:         /**
128:          * @deprecated Since 1.21, use the {@link #showHideColumns(boolean)} and similar
129:          * builder methods, instead
130:          * @see #showHideColumns(boolean)
131:          * @see #columnSubstringFilter(boolean)
132:          * @see #columnRegexFilter(boolean)
133:          */
134:         @Override
135:         @Deprecated
136:         protected Set<Feature> getEnabledFeatures() {
137:                 return features;
138:         }
139:
140:         /**
141:          * Set whether support for users to show and hide columns is installed.
142:          *
143:          * @param showHideColumns {@code true} to enable showing and hiding of columns; {@code false} to disable it
144:          * @return this builder, for fluent chaining
145:          *
146:          * @since 1.21
147:          */
148:         public TableConfigurationBuilder showHideColumns(boolean showHideColumns) {
149:•                return showHideColumns ? enableFeature(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW)
150:                         : disableFeature(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW);
151:         }
152:
153:         /**
154:          * Set whether support for users to show a simple substring-matching filter on columns
155:          * is installed.
156:          *
157:          * @param columnSubstringFilter {@code true} to enable the substring filter; {@code false} to disable it
158:          * @return this builder, for fluent chaining
159:          *
160:          * @since 1.21
161:          */
162:         public TableConfigurationBuilder columnSubstringFilter(boolean columnSubstringFilter) {
163:•                return columnSubstringFilter ? enableFeature(TableConfiguration.FEATURE_COLUMN_FILTER)
164:                         : disableFeature(TableConfiguration.FEATURE_COLUMN_FILTER);
165:         }
166:
167:         /**
168:          * Set whether support for users to show a regular expression filter on columns
169:          * is installed.
170:          *
171:          * @param columnRegexFilter {@code true} to enable the regex filter; {@code false} to disable it
172:          * @return this builder, for fluent chaining
173:          *
174:          * @since 1.21
175:          */
176:         public TableConfigurationBuilder columnRegexFilter(boolean columnRegexFilter) {
177:•                return columnRegexFilter ? enableFeature(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER)
178:                         : disableFeature(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER);
179:         }
180:
181:         /**
182:          * Add a data map entry.
183:          *
184:          * @param key the data map key
185:          * @param value the data map value
186:          * @return self
187:          */
188:         public TableConfigurationBuilder dataMapEntry(String key, Object value) {
189:                 data.put(key, value);
190:                 return this;
191:         }
192:
193:         /**
194:          * Creates a new {@link TableConfiguration} based on the current builder state.
195:          *
196:          * @return the {@link TableConfiguration}
197:          */
198:         public TableConfiguration build() {
199:                 final TableConfiguration config = new TableConfigurationImpl(
200:                         features,
201:                         data);
202:
203:                 return config;
204:         }
205:
206: }