Skip to content

Package: DefaultTableControlSWTCustomization$1

DefaultTableControlSWTCustomization$1

nameinstructionbranchcomplexitylinemethod
createTableViewer(Composite)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
{...}
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%

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: * Alexandra Buzila - initial API and implementation
13: * Johannes Faltermeier - initial API and implementation
14: ******************************************************************************/
15: package org.eclipse.emfforms.internal.swt.table;
16:
17: import java.util.ArrayList;
18: import java.util.List;
19:
20: import org.eclipse.emfforms.common.Optional;
21: import org.eclipse.emfforms.spi.swt.table.ColumnConfiguration;
22: import org.eclipse.emfforms.spi.swt.table.DNDProvider;
23: import org.eclipse.emfforms.spi.swt.table.DefaultTableViewerCompositeBuilder;
24: import org.eclipse.emfforms.spi.swt.table.TableConfiguration;
25: import org.eclipse.emfforms.spi.swt.table.TableViewerCompositeBuilder;
26: import org.eclipse.emfforms.spi.swt.table.TableViewerCreator;
27: import org.eclipse.emfforms.spi.swt.table.TableViewerSWTCustomization;
28: import org.eclipse.emfforms.spi.swt.table.action.ActionBar;
29: import org.eclipse.emfforms.spi.swt.table.action.ActionConfiguration;
30: import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
31: import org.eclipse.jface.viewers.AbstractTableViewer;
32: import org.eclipse.jface.viewers.IContentProvider;
33: import org.eclipse.jface.viewers.TableViewer;
34: import org.eclipse.jface.viewers.ViewerComparator;
35: import org.eclipse.swt.SWT;
36: import org.eclipse.swt.dnd.DragSourceListener;
37: import org.eclipse.swt.dnd.DropTargetListener;
38: import org.eclipse.swt.dnd.Transfer;
39: import org.eclipse.swt.widgets.Composite;
40: import org.eclipse.swt.widgets.Control;
41: import org.eclipse.swt.widgets.Label;
42:
43: /**
44: * The default implementation of the {@link TableViewerSWTCustomization}.
45: *
46: * @param <T> the concrete table viewer implementation to use
47: *
48: * @author Alexandra Buzila
49: * @author Johannes Faltermeier
50: *
51: */
52: public class DefaultTableControlSWTCustomization<T extends AbstractTableViewer>
53:         implements TableViewerSWTCustomization<T> {
54:
55:         private TableConfiguration tableConfiguration;
56:         private final List<ColumnConfiguration> configuredColumns = new ArrayList<ColumnConfiguration>();
57:
58:         private TableViewerCompositeBuilder tableViewerCompositeBuilder = new DefaultTableViewerCompositeBuilder();
59:
60:         private TableViewerCreator<T> tableViewerCreator = new TableViewerCreator<T>() {
61:
62:                 @Override
63:                 @SuppressWarnings("unchecked")
64:                 public T createTableViewer(Composite parent) {
65:                         final TableViewer tableViewer = new TableViewer(parent,
66:                                 SWT.MULTI | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
67:                         tableViewer.getTable().setHeaderVisible(true);
68:                         tableViewer.getTable().setLinesVisible(true);
69:                         return (T) tableViewer;
70:                 }
71:         };
72:
73:         private DNDProvider dndProvider = new NoOpDNDProvider();
74:
75:         private ViewerComparator viewerComparator;
76:
77:         private IContentProvider contentProvider = new ObservableListContentProvider();
78:
79:         private ActionBar<T> actionBar;
80:
81:         private ActionConfiguration actionConfiguration;
82:
83:         @Override
84:         public void createCompositeLayout(Composite parent) {
85:                 tableViewerCompositeBuilder.createCompositeLayout(parent);
86:         }
87:
88:         @Override
89:         public Optional<Label> getTitleLabel() {
90:                 return tableViewerCompositeBuilder.getTitleLabel();
91:         }
92:
93:         @Override
94:         public Optional<List<Control>> getValidationControls() {
95:                 return tableViewerCompositeBuilder.getValidationControls();
96:         }
97:
98:         @Override
99:         public Optional<Composite> getButtonComposite() {
100:                 return tableViewerCompositeBuilder.getButtonComposite();
101:         }
102:
103:         @Override
104:         public Composite getViewerComposite() {
105:                 return tableViewerCompositeBuilder.getViewerComposite();
106:         }
107:
108:         @Override
109:         public T createTableViewer(Composite parent) {
110:                 return tableViewerCreator.createTableViewer(parent);
111:         }
112:
113:         @Override
114:         public Optional<ViewerComparator> getComparator() {
115:                 return Optional.ofNullable(viewerComparator);
116:         }
117:
118:         @Override
119:         public IContentProvider createContentProvider() {
120:                 return contentProvider;
121:         }
122:
123:         @Override
124:         public TableConfiguration getTableConfiguration() {
125:                 return tableConfiguration;
126:         }
127:
128:         @Override
129:         public List<ColumnConfiguration> getColumnConfigurations() {
130:                 return configuredColumns;
131:         }
132:
133:         /**
134:          * Allows the exchange the default {@link TableViewerCompositeBuilder}.
135:          *
136:          * @param builder the {@link TableViewerCompositeBuilder}
137:          */
138:         public void setTableViewerCompositeBuilder(TableViewerCompositeBuilder builder) {
139:                 tableViewerCompositeBuilder = builder;
140:         }
141:
142:         /**
143:          * Allows the exchange the default {@link TableViewerCreator}.
144:          *
145:          * @param creator the {@link TableViewerCreator}
146:          */
147:         public void setTableViewerCreator(TableViewerCreator<T> creator) {
148:                 tableViewerCreator = creator;
149:         }
150:
151:         /**
152:          * Allows the exchange the default {@link ViewerComparator}.
153:          *
154:          * @param comparator the {@link ViewerComparator}
155:          */
156:         public void setViewerComparator(ViewerComparator comparator) {
157:                 viewerComparator = comparator;
158:         }
159:
160:         /**
161:          * Allows the exchange the default {@link IContentProvider}.
162:          *
163:          * @param provider the {@link IContentProvider}
164:          */
165:         public void setContentProvider(IContentProvider provider) {
166:                 contentProvider = provider;
167:         }
168:
169:         /**
170:          * Allows the customize the {@link ActionBar}.
171:          *
172:          * @param actionBar the {@link ActionBar}
173:          */
174:         public void setActionBar(ActionBar<T> actionBar) {
175:                 this.actionBar = actionBar;
176:         }
177:
178:         /**
179:          * Get the action bar instance (if it exists).
180:          *
181:          * @return the actionBar
182:          */
183:         @Override
184:         public Optional<ActionBar<T>> getActionBar() {
185:                 return Optional.ofNullable(actionBar);
186:         }
187:
188:         /**
189:          * Sets the table configuration.
190:          *
191:          * @param tableConfiguration the {@link TableConfiguration}
192:          */
193:         public void configureTable(TableConfiguration tableConfiguration) {
194:                 this.tableConfiguration = tableConfiguration;
195:         }
196:
197:         /**
198:          * Adds a column to the table.
199:          *
200:          * @param columnConfiguration the
201:          * {@link org.eclipse.emfforms.spi.swt.table.ColumnConfiguration
202:          * ColumnDescription}
203:          */
204:         public void addColumn(ColumnConfiguration columnConfiguration) {
205:                 configuredColumns.add(columnConfiguration);
206:         }
207:
208:         @Override
209:         public Optional<ActionConfiguration> getActionConfiguration() {
210:                 return Optional.ofNullable(actionConfiguration);
211:         }
212:
213:         /**
214:          * Allows to customize the {@link ActionConfiguration}.
215:          *
216:          * @param actionConfiguration The {@link ActionConfiguration}
217:          * @see #getActionConfiguration()
218:          */
219:         public void setActionConfiguration(ActionConfiguration actionConfiguration) {
220:                 this.actionConfiguration = actionConfiguration;
221:         }
222:
223:         /**
224:          * Allows the exchange the default {@link DNDProvider}.
225:          *
226:          * @param provider the {@link DNDProvider}
227:          */
228:         public void setDND(DNDProvider provider) {
229:                 dndProvider = provider;
230:         }
231:
232:         @Override
233:         public boolean hasDND() {
234:                 return dndProvider.hasDND();
235:         }
236:
237:         @Override
238:         public int getDragOperations() {
239:                 return dndProvider.getDragOperations();
240:         }
241:
242:         @Override
243:         public Transfer[] getDragTransferTypes() {
244:                 return dndProvider.getDragTransferTypes();
245:         }
246:
247:         @Override
248:         public DragSourceListener getDragListener(AbstractTableViewer tableViewer) {
249:                 return dndProvider.getDragListener(tableViewer);
250:         }
251:
252:         @Override
253:         public int getDropOperations() {
254:                 return dndProvider.getDropOperations();
255:         }
256:
257:         @Override
258:         public Transfer[] getDropTransferTypes() {
259:                 return dndProvider.getDropTransferTypes();
260:         }
261:
262:         @Override
263:         public DropTargetListener getDropListener(AbstractTableViewer tableViewer) {
264:                 return dndProvider.getDropListener(tableViewer);
265:         }
266:
267:         /**
268:          * {@link DNDProvider} for NO D&D support.
269:          *
270:          * @author Johannes Faltermeier
271:          *
272:          */
273:         private final class NoOpDNDProvider implements DNDProvider {
274:                 @Override
275:                 public boolean hasDND() {
276:                         return false;
277:                 }
278:
279:                 @Override
280:                 public Transfer[] getDropTransferTypes() {
281:                         throw new UnsupportedOperationException();
282:                 }
283:
284:                 @Override
285:                 public int getDropOperations() {
286:                         throw new UnsupportedOperationException();
287:                 }
288:
289:                 @Override
290:                 public DropTargetListener getDropListener(AbstractTableViewer tableViewer) {
291:                         throw new UnsupportedOperationException();
292:                 }
293:
294:                 @Override
295:                 public Transfer[] getDragTransferTypes() {
296:                         throw new UnsupportedOperationException();
297:                 }
298:
299:                 @Override
300:                 public int getDragOperations() {
301:                         throw new UnsupportedOperationException();
302:                 }
303:
304:                 @Override
305:                 public DragSourceListener getDragListener(AbstractTableViewer tableViewer) {
306:                         throw new UnsupportedOperationException();
307:                 }
308:         }
309:
310: }