Project

General

Profile

Revision f6f03fa3

IDf6f03fa33526f43dda6397e7848b20efd4e3bedc
Parent 39363db1
Child 378fbb8a

Added by Patrick Plitzner over 2 years ago

ref #7439 Show titleCache in NatTable in bulk editors

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.bulkeditor.e4;
11 11

  
12
import java.util.EventObject;
12
import java.util.HashMap;
13 13
import java.util.List;
14
import java.util.Map;
14 15

  
15 16
import javax.annotation.PostConstruct;
16 17
import javax.annotation.PreDestroy;
......
27 28
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
28 29
import org.eclipse.jface.dialogs.MessageDialog;
29 30
import org.eclipse.jface.layout.GridDataFactory;
30
import org.eclipse.jface.viewers.ArrayContentProvider;
31
import org.eclipse.jface.viewers.CellEditor;
32
import org.eclipse.jface.viewers.ColumnViewerEditor;
33
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
34
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
35
import org.eclipse.jface.viewers.ICellModifier;
36 31
import org.eclipse.jface.viewers.ISelection;
37 32
import org.eclipse.jface.viewers.ISelectionChangedListener;
38 33
import org.eclipse.jface.viewers.IStructuredSelection;
39
import org.eclipse.jface.viewers.ITableLabelProvider;
40 34
import org.eclipse.jface.viewers.TableViewer;
41
import org.eclipse.jface.viewers.TableViewerColumn;
42
import org.eclipse.jface.viewers.TableViewerEditor;
43
import org.eclipse.jface.viewers.TableViewerFocusCellManager;
44
import org.eclipse.jface.viewers.TextCellEditor;
45 35
import org.eclipse.nebula.widgets.nattable.NatTable;
46 36
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
47 37
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
......
52 42
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
53 43
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
54 44
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
55
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
56 45
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
46
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
47
import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
48
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
57 49
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
58
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
59 50
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
51
import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
52
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
53
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
60 54
import org.eclipse.swt.SWT;
61
import org.eclipse.swt.events.MouseEvent;
62
import org.eclipse.swt.layout.FillLayout;
63 55
import org.eclipse.swt.layout.GridData;
64 56
import org.eclipse.swt.layout.GridLayout;
65 57
import org.eclipse.swt.widgets.Composite;
66
import org.eclipse.swt.widgets.Table;
67 58

  
68 59
import ca.odell.glazedlists.BasicEventList;
69 60
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
......
131 122
    public BulkEditorE4() {
132 123
	}
133 124

  
134
	public void init(AbstractBulkEditorInput<?> input){
125
	@SuppressWarnings("unused")
126
    public void init(AbstractBulkEditorInput<?> input){
135 127
	    this.input = input;
136 128
	    this.conversation = input.getConversation();
137 129

  
138
	    BulkEditorSearchE4 searchBar = new BulkEditorSearchE4(this, topComposite, SWT.NONE);
130
	    new BulkEditorSearchE4(this, topComposite, SWT.NONE);
139 131
	    //layout needed because the search bar is added after @PostConstuct method
140 132
	    topComposite.getParent().layout();
141 133

  
142 134
	    thisPart.setLabel(input.getEditorName());
143 135

  
144
	    //create columns
145
	    Table table = viewer.getTable();
146
	    String[] titles = {input.getName(), "Type"};
147
	    int[] bounds = {500, 100};
148

  
149
	    ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(viewer) {
150
            @Override
151
            protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
152
                // Enable editor only with mouse double click
153
                if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION) {
154
                    EventObject source = event.sourceEvent;
155
                    if (source instanceof MouseEvent && ((MouseEvent)source).button == 3) {
156
                        return false;
157
                    }
158

  
159
                    return true;
160
                }
161

  
162
                return false;
163
            }
164
        };
165
        TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new BulkEditorFocusCellOwnerDrawHighLighter(viewer));
166

  
167
        TableViewerEditor.create(viewer, focusCellManager, activationSupport, ColumnViewerEditor.TABBING_HORIZONTAL |
168
                ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
169
                ColumnViewerEditor.TABBING_VERTICAL |
170
                ColumnViewerEditor.KEYBOARD_ACTIVATION );
171

  
172
	    CellEditor[] editors = new CellEditor[titles.length];
173
	    for (int i = 0; i < titles.length; i++) {
174
	        TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
175
	        editors[i] = new TextCellEditor(table);
176

  
177
	        column.getColumn().setText(titles[i]);
178
	        column.getColumn().setWidth(bounds[i]);
179
	        column.getColumn().setResizable(true);
180
	        column.getColumn().setMoveable(true);
181

  
182
	    }
183

  
184
	    table.setHeaderVisible(true);
185
	    table.setLinesVisible(true);
186

  
187
	    viewer.setCellEditors(editors);
188
	    viewer.setColumnProperties(titles);
189

  
190
	    //content and label provider (NOTE: has to be set AFTER creating cell editors
191
	    viewer.setContentProvider(new ArrayContentProvider());
192
        BulkEditorLabelProvider labelProvider = new BulkEditorLabelProvider(this);
193
        viewer.setLabelProvider(labelProvider);
194

  
195

  
196
        //allow text selection
197
        viewer.setCellModifier(new ICellModifier() {
198
            @Override
199
            public void modify(Object element, String property, Object value) {
200
            }
201
            @Override
202
            public Object getValue(Object element, String property) {
203
                ITableLabelProvider tableLabelProvider = null;
204
                if(viewer.getLabelProvider() instanceof ITableLabelProvider){
205
                    tableLabelProvider = (ITableLabelProvider) viewer.getLabelProvider();
206
                }
207
                Object[] columnProperties = viewer.getColumnProperties();
208
                for (int i=0;i<columnProperties.length;i++) {
209
                    if(columnProperties[i].equals(property) && tableLabelProvider!=null){
210
                        return tableLabelProvider.getColumnText(element, i);
211
                    }
212
                }
213
                return "";
214
            }
215
            @Override
216
            public boolean canModify(Object element, String property) {
217
                return true;
218
            }
219
        });
136
//	    //create columns
137
//	    Table table = viewer.getTable();
138
//	    String[] titles = {input.getName(), "Type"};
139
//	    int[] bounds = {500, 100};
140
//
141
//	    ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(viewer) {
142
//            @Override
143
//            protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
144
//                // Enable editor only with mouse double click
145
//                if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION) {
146
//                    EventObject source = event.sourceEvent;
147
//                    if (source instanceof MouseEvent && ((MouseEvent)source).button == 3) {
148
//                        return false;
149
//                    }
150
//
151
//                    return true;
152
//                }
153
//
154
//                return false;
155
//            }
156
//        };
157
//        TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new BulkEditorFocusCellOwnerDrawHighLighter(viewer));
158
//
159
//        TableViewerEditor.create(viewer, focusCellManager, activationSupport, ColumnViewerEditor.TABBING_HORIZONTAL |
160
//                ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
161
//                ColumnViewerEditor.TABBING_VERTICAL |
162
//                ColumnViewerEditor.KEYBOARD_ACTIVATION );
163
//
164
//	    CellEditor[] editors = new CellEditor[titles.length];
165
//	    for (int i = 0; i < titles.length; i++) {
166
//	        TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
167
//	        editors[i] = new TextCellEditor(table);
168
//
169
//	        column.getColumn().setText(titles[i]);
170
//	        column.getColumn().setWidth(bounds[i]);
171
//	        column.getColumn().setResizable(true);
172
//	        column.getColumn().setMoveable(true);
173
//
174
//	    }
175
//
176
//	    table.setHeaderVisible(true);
177
//	    table.setLinesVisible(true);
178
//
179
//	    viewer.setCellEditors(editors);
180
//	    viewer.setColumnProperties(titles);
181
//
182
//	    //content and label provider (NOTE: has to be set AFTER creating cell editors
183
//	    viewer.setContentProvider(new ArrayContentProvider());
184
//        BulkEditorLabelProvider labelProvider = new BulkEditorLabelProvider(this);
185
//        viewer.setLabelProvider(labelProvider);
186
//
187
//
188
//        //allow text selection
189
//        viewer.setCellModifier(new ICellModifier() {
190
//            @Override
191
//            public void modify(Object element, String property, Object value) {
192
//            }
193
//            @Override
194
//            public Object getValue(Object element, String property) {
195
//                ITableLabelProvider tableLabelProvider = null;
196
//                if(viewer.getLabelProvider() instanceof ITableLabelProvider){
197
//                    tableLabelProvider = (ITableLabelProvider) viewer.getLabelProvider();
198
//                }
199
//                Object[] columnProperties = viewer.getColumnProperties();
200
//                for (int i=0;i<columnProperties.length;i++) {
201
//                    if(columnProperties[i].equals(property) && tableLabelProvider!=null){
202
//                        return tableLabelProvider.getColumnText(element, i);
203
//                    }
204
//                }
205
//                return "";
206
//            }
207
//            @Override
208
//            public boolean canModify(Object element, String property) {
209
//                return true;
210
//            }
211
//        });
220 212

  
221 213

  
222 214

  
......
238 230

  
239 231
		Composite bottomComposite = new Composite(parent, SWT.NONE);
240 232
		bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
241
		bottomComposite.setLayout(new FillLayout());
233
		bottomComposite.setLayout(new GridLayout());
242 234

  
243 235

  
244 236
		//++++NatTable++++
245
		natTable = new NatTable(parent, false);
246
		list = new BasicEventList<>();
247
        ListDataProvider<Object> dataProvider = new ListDataProvider<>(list, new ReflectiveColumnPropertyAccessor<>("titleCache"));
248
        DataLayer dataLayer = new DataLayer(dataProvider);
249
        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
250
        DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(eventLayer);
237
		natTable = createExampleControl(bottomComposite);
238
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
251 239

  
252
        /**
253
         * column header layer
254
         */
255
        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(new String[] {"titleCache"});
256
        DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
257
        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
258 240

  
259
        /**
260
         * row header layer
261
         */
262
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(dataProvider);
263
        DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
264 241

  
265 242

  
266
        /**
267
         * corner layer
268
         */
269
        ILayer cornerLayer = new CornerLayer(
270
                new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
271
                rowHeaderDataLayer, rowHeaderDataLayer);
272 243

  
273 244

  
274
        /**
275
         * GRID layer (composition of all other layers)
276
         */
277
        GridLayer gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer, rowHeaderDataLayer, cornerLayer);
278 245

  
279
        natTable.setLayer(gridLayer);
280 246

  
281
        natTable.configure();
282 247

  
283
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
284 248

  
285 249

  
286 250

  
287 251

  
252
//		viewer = new TableViewer(bottomComposite, SWT.MULTI | SWT.FULL_SELECTION);
288 253

  
254
//		createColumns(viewer);
289 255

  
256
        //propagate selection
257
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
258
//        viewer.addSelectionChangedListener(selectionChangedListener);
290 259

  
260
        //create context menu
261
//        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
291 262

  
263
	}
264
    private IDataProvider bodyDataProvider;
265
    private String[] propertyNames;
266
    private Map<String, String> propertyToLabels;
267

  
268
    public NatTable createExampleControl(Composite parent) {
269
        this.bodyDataProvider = setupBodyDataProvider();
270
        DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(
271
                this.propertyNames, this.propertyToLabels);
272
        DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
273
                this.bodyDataProvider);
274

  
275
        DataLayer dataLayer = new DataLayer(bodyDataProvider);
276
        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
277
        DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(eventLayer);
292 278

  
279
        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(
280
                new DataLayer(colHeaderDataProvider),
281
                bodyLayer, bodyLayer.getSelectionLayer());
293 282

  
283
        RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 50, 20),
284
                bodyLayer, bodyLayer.getSelectionLayer());
294 285

  
286
        DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(
287
                colHeaderDataProvider, rowHeaderDataProvider);
288
        CornerLayer cornerLayer = new CornerLayer(new DataLayer(
289
                cornerDataProvider), rowHeaderLayer, columnHeaderLayer);
295 290

  
291
        GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer,
292
                rowHeaderLayer, cornerLayer);
293
        NatTable natTable = new NatTable(parent, gridLayer);
296 294

  
297
		viewer = new TableViewer(bottomComposite, SWT.MULTI | SWT.FULL_SELECTION);
295
        return natTable;
296
    }
298 297

  
299
//		createColumns(viewer);
298
    private IDataProvider setupBodyDataProvider() {
299
        list = new BasicEventList<>();
300 300

  
301
        //propagate selection
302
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
303
        viewer.addSelectionChangedListener(selectionChangedListener);
301
        this.propertyToLabels = new HashMap<>();
302
        this.propertyToLabels.put("titleCache", "Title Cache");
303
        this.propertyNames = new String[] { "titleCache" };
304
        return new ListDataProvider(list,
305
                new ReflectiveColumnPropertyAccessor(this.propertyNames));
304 306

  
305
        //create context menu
306
        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
307
    }
307 308

  
308
	}
309
    public class BodyLayerStack extends AbstractLayerTransform {
310

  
311
        private SelectionLayer selectionLayer;
312

  
313
        public BodyLayerStack(IDataProvider dataProvider) {
314
            DataLayer bodyDataLayer = new DataLayer(dataProvider);
315
            ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(
316
                    bodyDataLayer);
317
            ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(
318
                    columnReorderLayer);
319
            this.selectionLayer = new SelectionLayer(columnHideShowLayer);
320
            ViewportLayer viewportLayer = new ViewportLayer(this.selectionLayer);
321
            setUnderlyingLayer(viewportLayer);
322
        }
323

  
324
        public SelectionLayer getSelectionLayer() {
325
            return this.selectionLayer;
326
        }
327
    }
309 328

  
310 329
	@Override
311 330
	@Persist
......
349 368
            performSearch(lastQuery);
350 369
            getViewer().setSelection(selection, true);
351 370
        }
352
        viewer.refresh();
371
//        viewer.refresh();
353 372

  
354 373

  
355 374
	}
......
375 394
            getEditorInput().performSearch(query);
376 395
            lastQuery = query;
377 396
            List model = getEditorInput().getModel();
378
            viewer.setInput(model);
397
//            viewer.setInput(model);
379 398
            list.clear();
380 399
            list.addAll(model);
381 400

  
......
389 408

  
390 409
    public void refresh(boolean resetInput) {
391 410
        if(resetInput){
392
            viewer.setInput(getEditorInput().getModel());
411
//            viewer.setInput(getEditorInput().getModel());
393 412
        }
394
        viewer.refresh();
413
//        viewer.refresh();
395 414
    }
396 415

  
397 416
    public TableViewer getViewer() {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)