Revision 3bb757a5
Added by Patrick Plitzner about 5 years ago
eu.etaxonomy.taxeditor.bulkeditor/META-INF/MANIFEST.MF | ||
---|---|---|
29 | 29 |
org.eclipse.nebula.widgets.nattable.core, |
30 | 30 |
ca.odell.glazedlists, |
31 | 31 |
org.eclipse.nebula.widgets.nattable.extension.glazedlists, |
32 |
org.eclipse.e4.core.di |
|
32 |
org.eclipse.e4.core.di, |
|
33 |
org.eclipse.nebula.widgets.nattable.extension.e4 |
|
33 | 34 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 |
34 | 35 |
Import-Package: eu.etaxonomy.taxeditor.editor, |
35 | 36 |
org.eclipse.core.runtime, |
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4Composite.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.taxeditor.bulkeditor.e4; |
11 | 11 |
|
12 | 12 |
import java.io.File; |
13 |
import java.io.Serializable; |
|
14 | 13 |
import java.util.ArrayList; |
15 | 14 |
import java.util.HashMap; |
16 | 15 |
import java.util.List; |
17 | 16 |
import java.util.Map; |
18 | 17 |
import java.util.Properties; |
18 |
import java.util.Set; |
|
19 | 19 |
|
20 | 20 |
import javax.inject.Inject; |
21 | 21 |
|
... | ... | |
35 | 35 |
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration; |
36 | 36 |
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; |
37 | 37 |
import org.eclipse.nebula.widgets.nattable.config.IEditableRule; |
38 |
import org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor;
|
|
38 |
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
|
|
39 | 39 |
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider; |
40 | 40 |
import org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter; |
41 | 41 |
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; |
42 | 42 |
import org.eclipse.nebula.widgets.nattable.edit.action.MouseEditAction; |
43 | 43 |
import org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration; |
44 | 44 |
import org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor; |
45 |
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener; |
|
45 | 46 |
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer; |
46 | 47 |
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel; |
47 | 48 |
import org.eclipse.nebula.widgets.nattable.grid.GridRegion; |
... | ... | |
57 | 58 |
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack; |
58 | 59 |
import org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter; |
59 | 60 |
import org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter; |
60 |
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel; |
|
61 |
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider; |
|
62 | 61 |
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer; |
63 | 62 |
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration; |
64 | 63 |
import org.eclipse.nebula.widgets.nattable.style.DisplayMode; |
... | ... | |
164 | 163 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable); |
165 | 164 |
|
166 | 165 |
//propagate selection |
167 |
selectionChangedListener = (event -> selService.setSelection(getSelection())); |
|
168 |
RowSelectionProvider<CdmBase> selectionProvider = new RowSelectionProvider<CdmBase>(bodyLayer.getSelectionLayer(), bodyDataProvider, true); |
|
169 |
selectionProvider.addSelectionChangedListener(selectionChangedListener); |
|
166 |
// selection listener |
|
167 |
E4SelectionListener<CdmBase> selectionListener = new CellSelectionListener(selService, bodyLayer.getSelectionLayer(), bodyDataProvider, this); |
|
168 |
bodyLayer.getSelectionLayer().addLayerListener(selectionListener); |
|
169 |
selectionListener.setFullySelectedRowsOnly(false); |
|
170 | 170 |
|
171 | 171 |
bottomComposite.layout(); |
172 | 172 |
|
... | ... | |
239 | 239 |
rowHeaderLayer, cornerLayer, false);//set autoconfigure to false to get rid of the single click editing |
240 | 240 |
natTable = new NatTable(bottomComposite, gridLayer, false); |
241 | 241 |
|
242 |
//full row selection |
|
243 |
bodyLayer.getSelectionLayer().setSelectionModel(new RowSelectionModel<CdmBase>(bodyLayer.getSelectionLayer(), bodyDataProvider, new IRowIdAccessor<CdmBase>() { |
|
244 |
@Override |
|
245 |
public Serializable getRowId(CdmBase rowObject) { |
|
246 |
return bulkEditor.getEditorInput().getModel().indexOf(rowObject); |
|
247 |
} |
|
248 |
})); |
|
249 |
|
|
250 | 242 |
dataLayer.setConfigLabelAccumulator(new BulkEditorConfigLabelAccumulator(bodyDataProvider, colHeaderDataProvider, |
251 | 243 |
bulkEditor.getEditorInput())); |
252 | 244 |
|
... | ... | |
391 | 383 |
} |
392 | 384 |
|
393 | 385 |
public IStructuredSelection getSelection(){ |
394 |
List<CdmBase> selection = new ArrayList<>(); |
|
395 |
int[] fullySelectedRowPositions = bodyLayer.getSelectionLayer().getFullySelectedRowPositions(); |
|
396 |
for (int i : fullySelectedRowPositions) { |
|
397 |
if(i<0){ |
|
398 |
continue; |
|
399 |
} |
|
400 |
Object rowObject = bodyDataProvider.getRowObject(i); |
|
401 |
if(rowObject instanceof CdmBase){ |
|
402 |
selection.add((CdmBase) rowObject); |
|
386 |
Set<Range> selectedRowPositions = bodyLayer.getSelectionLayer().getSelectedRowPositions(); |
|
387 |
List<Object> selectedObjects = new ArrayList<>(); |
|
388 |
for (Range range : selectedRowPositions) { |
|
389 |
for(int i=range.start;i<range.end;i++){ |
|
390 |
selectedObjects.add(bodyDataProvider.getRowObject(i)); |
|
403 | 391 |
} |
404 | 392 |
} |
405 |
return new StructuredSelection(selection);
|
|
393 |
return new StructuredSelection(selectedObjects);
|
|
406 | 394 |
} |
407 | 395 |
|
408 | 396 |
public void setSelection(IStructuredSelection selection){ |
... | ... | |
434 | 422 |
} |
435 | 423 |
} |
436 | 424 |
|
425 |
ListDataProvider<CdmBase> getBodyDataProvider() { |
|
426 |
return bodyDataProvider; |
|
427 |
} |
|
428 |
|
|
429 |
ESelectionService getSelService() { |
|
430 |
return selService; |
|
431 |
} |
|
432 |
|
|
437 | 433 |
NatTable getNatTable() { |
438 | 434 |
return natTable; |
439 | 435 |
} |
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/CellSelectionListener.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2018 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.bulkeditor.e4; |
|
11 |
|
|
12 |
import java.util.Collection; |
|
13 |
|
|
14 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
|
15 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
16 |
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider; |
|
17 |
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener; |
|
18 |
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; |
|
19 |
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent; |
|
20 |
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; |
|
21 |
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent; |
|
22 |
import org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent; |
|
23 |
|
|
24 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author pplitzner |
|
28 |
* @date 09.07.2018 |
|
29 |
* |
|
30 |
*/ |
|
31 |
final class CellSelectionListener extends E4SelectionListener<CdmBase> { |
|
32 |
|
|
33 |
private BulkEditorE4Composite bulkEditor; |
|
34 |
|
|
35 |
public CellSelectionListener( |
|
36 |
ESelectionService service, |
|
37 |
SelectionLayer selectionLayer, |
|
38 |
IRowDataProvider<CdmBase> rowDataProvider, |
|
39 |
BulkEditorE4Composite bulkEditor) { |
|
40 |
super(service, selectionLayer, rowDataProvider); |
|
41 |
this.bulkEditor = bulkEditor; |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void handleLayerEvent(ILayerEvent event) { |
|
46 |
if(event instanceof CellSelectionEvent){ |
|
47 |
CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event; |
|
48 |
Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells(); |
|
49 |
if(selectedCells.size()==1){ |
|
50 |
Object rowObject = bulkEditor.getBodyDataProvider().getRowObject(cellSelectionEvent.getRowPosition()); |
|
51 |
bulkEditor.getSelService().setSelection(new StructuredSelection(rowObject)); |
|
52 |
return; |
|
53 |
} |
|
54 |
} |
|
55 |
else if(event instanceof RowSelectionEvent){ |
|
56 |
RowSelectionEvent rowSelectionEvent = (RowSelectionEvent) event; |
|
57 |
int[] fullySelectedRowPositions = rowSelectionEvent.getSelectionLayer().getFullySelectedRowPositions(); |
|
58 |
if(fullySelectedRowPositions.length==1){ |
|
59 |
Object rowObject = bulkEditor.getBodyDataProvider().getRowObject(fullySelectedRowPositions[0]); |
|
60 |
bulkEditor.getSelService().setSelection(new StructuredSelection(rowObject)); |
|
61 |
return; |
|
62 |
} |
|
63 |
} |
|
64 |
bulkEditor.getSelService().setSelection(new StructuredSelection()); |
|
65 |
} |
|
66 |
} |
Also available in: Unified diff
ref #8026 Changed selection to cell selection in bulk editor