package eu.etaxonomy.taxeditor.bulkeditor.e4;
import java.io.File;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import javax.inject.Inject;
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
-import org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
import org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter;
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
import org.eclipse.nebula.widgets.nattable.edit.action.MouseEditAction;
import org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration;
import org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor;
+import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
import org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter;
-import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel;
-import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
//propagate selection
- selectionChangedListener = (event -> selService.setSelection(getSelection()));
- RowSelectionProvider<CdmBase> selectionProvider = new RowSelectionProvider<CdmBase>(bodyLayer.getSelectionLayer(), bodyDataProvider, true);
- selectionProvider.addSelectionChangedListener(selectionChangedListener);
+ // selection listener
+ E4SelectionListener<CdmBase> selectionListener = new CellSelectionListener(selService, bodyLayer.getSelectionLayer(), bodyDataProvider, this);
+ bodyLayer.getSelectionLayer().addLayerListener(selectionListener);
+ selectionListener.setFullySelectedRowsOnly(false);
bottomComposite.layout();
rowHeaderLayer, cornerLayer, false);//set autoconfigure to false to get rid of the single click editing
natTable = new NatTable(bottomComposite, gridLayer, false);
- //full row selection
- bodyLayer.getSelectionLayer().setSelectionModel(new RowSelectionModel<CdmBase>(bodyLayer.getSelectionLayer(), bodyDataProvider, new IRowIdAccessor<CdmBase>() {
- @Override
- public Serializable getRowId(CdmBase rowObject) {
- return bulkEditor.getEditorInput().getModel().indexOf(rowObject);
- }
- }));
-
dataLayer.setConfigLabelAccumulator(new BulkEditorConfigLabelAccumulator(bodyDataProvider, colHeaderDataProvider,
bulkEditor.getEditorInput()));
}
public IStructuredSelection getSelection(){
- List<CdmBase> selection = new ArrayList<>();
- int[] fullySelectedRowPositions = bodyLayer.getSelectionLayer().getFullySelectedRowPositions();
- for (int i : fullySelectedRowPositions) {
- if(i<0){
- continue;
- }
- Object rowObject = bodyDataProvider.getRowObject(i);
- if(rowObject instanceof CdmBase){
- selection.add((CdmBase) rowObject);
+ Set<Range> selectedRowPositions = bodyLayer.getSelectionLayer().getSelectedRowPositions();
+ List<Object> selectedObjects = new ArrayList<>();
+ for (Range range : selectedRowPositions) {
+ for(int i=range.start;i<range.end;i++){
+ selectedObjects.add(bodyDataProvider.getRowObject(i));
}
}
- return new StructuredSelection(selection);
+ return new StructuredSelection(selectedObjects);
}
public void setSelection(IStructuredSelection selection){
}
}
+ ListDataProvider<CdmBase> getBodyDataProvider() {
+ return bodyDataProvider;
+ }
+
+ ESelectionService getSelService() {
+ return selService;
+ }
+
NatTable getNatTable() {
return natTable;
}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.bulkeditor.e4;
+
+import java.util.Collection;
+
+import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
+import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
+import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
+import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
+import org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
+
+/**
+ * @author pplitzner
+ * @date 09.07.2018
+ *
+ */
+final class CellSelectionListener extends E4SelectionListener<CdmBase> {
+
+ private BulkEditorE4Composite bulkEditor;
+
+ public CellSelectionListener(
+ ESelectionService service,
+ SelectionLayer selectionLayer,
+ IRowDataProvider<CdmBase> rowDataProvider,
+ BulkEditorE4Composite bulkEditor) {
+ super(service, selectionLayer, rowDataProvider);
+ this.bulkEditor = bulkEditor;
+ }
+
+ @Override
+ public void handleLayerEvent(ILayerEvent event) {
+ if(event instanceof CellSelectionEvent){
+ CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
+ Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
+ if(selectedCells.size()==1){
+ Object rowObject = bulkEditor.getBodyDataProvider().getRowObject(cellSelectionEvent.getRowPosition());
+ bulkEditor.getSelService().setSelection(new StructuredSelection(rowObject));
+ return;
+ }
+ }
+ else if(event instanceof RowSelectionEvent){
+ RowSelectionEvent rowSelectionEvent = (RowSelectionEvent) event;
+ int[] fullySelectedRowPositions = rowSelectionEvent.getSelectionLayer().getFullySelectedRowPositions();
+ if(fullySelectedRowPositions.length==1){
+ Object rowObject = bulkEditor.getBodyDataProvider().getRowObject(fullySelectedRowPositions[0]);
+ bulkEditor.getSelService().setSelection(new StructuredSelection(rowObject));
+ return;
+ }
+ }
+ bulkEditor.getSelService().setSelection(new StructuredSelection());
+ }
+}