Skip to content

Package: TableViewerComposite$2

TableViewerComposite$2

nameinstructionbranchcomplexitylinemethod
widgetSelected(SelectionEvent)
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%
{...}
M: 0 C: 9
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.spi.swt.table;
16:
17: import java.util.List;
18:
19: import org.eclipse.core.databinding.observable.value.IObservableValue;
20: import org.eclipse.emf.databinding.EMFDataBindingContext;
21: import org.eclipse.jface.layout.AbstractColumnLayout;
22: import org.eclipse.jface.layout.TableColumnLayout;
23: import org.eclipse.jface.viewers.TableViewer;
24: import org.eclipse.jface.viewers.ViewerColumn;
25: import org.eclipse.swt.events.ControlListener;
26: import org.eclipse.swt.events.SelectionAdapter;
27: import org.eclipse.swt.events.SelectionEvent;
28: import org.eclipse.swt.widgets.Composite;
29: import org.eclipse.swt.widgets.TableColumn;
30: import org.eclipse.swt.widgets.Widget;
31:
32: /**
33: * A {@link Composite} containing a {@link TableViewer}.
34: *
35: * @author Alexandra Buzila
36: * @author Johannes Faltermeier
37: *
38: */
39: public class TableViewerComposite extends AbstractTableViewerComposite<TableViewer> {
40:
41:         private TableViewer tableViewer;
42:         private TableViewerComparator comparator;
43:
44:         /**
45:          * Default constructor.
46:          *
47:          * @param parent the parent {@link Composite}
48:          * @param style the style bits
49:          * @param inputObject the input object
50:          * @param customization the {@link TableViewerSWTCustomization}
51:          * @param title the title
52:          * @param tooltip the tooltip
53:          */
54:         TableViewerComposite(Composite parent, int style, Object inputObject,
55:                 TableViewerSWTCustomization customization,
56:                 IObservableValue title, IObservableValue tooltip) {
57:                 super(parent, style, inputObject, customization, title, tooltip);
58:         }
59:
60:         /**
61:          * @return the {@link TableViewer}
62:          */
63:         @Override
64:         public TableViewer getTableViewer() {
65:                 return tableViewer;
66:         }
67:
68:         /**
69:          * {@inheritDoc}
70:          *
71:          * @see org.eclipse.emfforms.spi.swt.table.AbstractTableViewerComposite#createTableViewer(org.eclipse.emfforms.spi.swt.table.TableViewerSWTCustomization,
72:          * org.eclipse.swt.widgets.Composite)
73:          */
74:         @Override
75:         protected TableViewer createTableViewer(TableViewerSWTCustomization<TableViewer> customization,
76:                 Composite viewerComposite) {
77:                 tableViewer = customization.createTableViewer(viewerComposite);
78:                 return tableViewer;
79:         }
80:
81:         @Override
82:         protected AbstractColumnLayout createLayout(Composite viewerComposite) {
83:                 final TableColumnLayout layout = new TableColumnLayout();
84:                 viewerComposite.setLayout(layout);
85:                 return layout;
86:         }
87:
88:         @Override
89:         public Widget[] getColumns() {
90:                 return tableViewer.getTable().getColumns();
91:         }
92:
93:         @Override
94:         public void addColumnListener(ControlListener columnlistener) {
95:                 for (int i = 0; i < tableViewer.getTable().getColumns().length; i++) {
96:                         final TableColumn tableColumn = tableViewer.getTable().getColumns()[i];
97:                         tableColumn.addControlListener(columnlistener);
98:                 }
99:         }
100:
101:         @Override
102:         public TableControl getTableControl() {
103:                 return new TableControl() {
104:                         @Override
105:                         public boolean isDisposed() {
106:                                 return getTableViewer().getTable().isDisposed();
107:                         }
108:
109:                         @Override
110:                         public int getItemHeight() {
111:                                 return getTableViewer().getTable().getItemHeight();
112:                         }
113:
114:                         @Override
115:                         public boolean getHeaderVisible() {
116:                                 return getTableViewer().getTable().getHeaderVisible();
117:                         }
118:
119:                         @Override
120:                         public int getHeaderHeight() {
121:                                 return getTableViewer().getTable().getHeaderHeight();
122:                         }
123:
124:                         @Override
125:                         public int getItemCount() {
126:                                 return getTableViewer().getTable().getItemCount();
127:                         }
128:                 };
129:         }
130:
131:         @Override
132:         protected ViewerColumn createColumn(ColumnConfiguration config,
133:                 EMFDataBindingContext emfDataBindingContext, TableViewer tableViewer) {
134:
135:                 return new DefaultTableViewerColumnBuilder(config)
136:                         .withDatabinding(emfDataBindingContext)
137:                         .build(tableViewer);
138:         }
139:
140:         @Override
141:         public void setComparator(final TableViewerComparator comparator, List<Integer> sortableColumns) {
142:                 this.comparator = comparator;
143:                 for (int i = 0; i < getTableViewer().getTable().getColumns().length; i++) {
144:                         if (!sortableColumns.contains(i)) {
145:                                 continue;
146:                         }
147:                         final int j = i;
148:                         final TableColumn tableColumn = getTableViewer().getTable().getColumns()[i];
149:                         final SelectionAdapter selectionAdapter = new SelectionAdapter() {
150:                                 @Override
151:                                 public void widgetSelected(SelectionEvent e) {
152:                                         setCompareColumn(j);
153:                                 }
154:                         };
155:                         tableColumn.addSelectionListener(selectionAdapter);
156:                 }
157:
158:         }
159:
160:         @Override
161:         public void dispose() {
162:                 tableViewer.getControl().dispose();
163:                 tableViewer = null;
164:                 super.dispose();
165:         }
166:
167:         @Override
168:         public void setCompareColumn(int column) {
169:                 final TableColumn tableColumn = getTableViewer().getTable().getColumns()[column];
170:                 comparator.setColumn(column);
171:                 tableViewer.getTable().setSortDirection(comparator.getDirection());
172:                 tableViewer.getTable().setSortColumn(tableColumn);
173:                 tableViewer.refresh();
174:         }
175:
176: }