Project

General

Profile

« Previous | Next » 

Revision 3bb757a5

Added by Patrick Plitzner about 5 years ago

ref #8026 Changed selection to cell selection in bulk editor

  • Fix empty details view in some cases

View differences:

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
    }

Also available in: Unified diff