Project

General

Profile

Revision 8309769f

ID8309769feee2912b0f4ccb9b22f97cd72fc38f5a
Parent bf128d5f
Child 97352439

Added by Patrick Plitzner about 1 year ago

ref #7439 Propagate row selection of nattable

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/e4/handler/NewObjectHandlerE4.java
18 18
import org.eclipse.jface.dialogs.IInputValidator;
19 19
import org.eclipse.jface.dialogs.InputDialog;
20 20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.IStructuredSelection;
21 22
import org.eclipse.jface.viewers.StructuredSelection;
22 23
import org.eclipse.jface.window.Window;
23 24
import org.eclipse.swt.widgets.Shell;
......
79 80
                if (createdEntity instanceof CdmBase){
80 81
                    bulkEditor.getEditorInput().addSaveCandidate((CdmBase)createdEntity);
81 82
                }
82
                ISelection selection = new StructuredSelection(createdEntity);
83

  
84
                ISelection prevSelection =bulkEditor.getViewer().getSelection();
85

  
83
                IStructuredSelection selection = new StructuredSelection(createdEntity);
86 84

  
87 85
                bulkEditor.refresh(true);
88 86
                bulkEditor.setDirty();
89 87
                bulkEditor.setFocus();
90 88

  
91
                bulkEditor.getViewer().setSelection(selection, true);
92
                bulkEditor.getViewer().refresh();
89
                bulkEditor.setSelection(selection);
93 90

  
94 91

  
95 92
            }
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
10 10
package eu.etaxonomy.taxeditor.bulkeditor.e4;
11 11

  
12 12
import java.io.Serializable;
13
import java.util.ArrayList;
13 14
import java.util.HashMap;
14 15
import java.util.List;
15 16
import java.util.Map;
......
32 33
import org.eclipse.jface.viewers.ISelection;
33 34
import org.eclipse.jface.viewers.ISelectionChangedListener;
34 35
import org.eclipse.jface.viewers.IStructuredSelection;
36
import org.eclipse.jface.viewers.StructuredSelection;
35 37
import org.eclipse.jface.viewers.TableViewer;
36 38
import org.eclipse.nebula.widgets.nattable.NatTable;
37 39
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
......
50 52
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
51 53
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
52 54
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel;
55
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
56
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
53 57
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
54 58
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
55 59
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
......
105 109

  
106 110
    private TableViewer viewer;
107 111

  
108
    private NatTable natTable;
109

  
110 112
    private ConversationHolder conversation;
111 113

  
112 114
    @Inject
......
129 131
    @Inject
130 132
    private EMenuService menuService;
131 133

  
134
    private NatTable natTable;
135

  
136
    private SelectionLayer selectionLayer;
137

  
138
    private ListDataProvider<CdmBase> bodyDataProvider;
139

  
132 140
    @Inject
133 141
    public BulkEditorE4() {
134 142
	}
......
233 241
        propertyToLabels.put(getEditorInput().getName(), getEditorInput().getName());
234 242
        propertyToLabels.put(TYPE_PROPERTY, TYPE_PROPERTY);
235 243
        String[] propertyNames = new String[] { getEditorInput().getName(), TYPE_PROPERTY };
236
        ListDataProvider bodyDataProvider = new ListDataProvider<CdmBase>(list,
244
        bodyDataProvider = new ListDataProvider<CdmBase>(list,
237 245
                new BulkEditorPropertyAccessor(getEditorInput()));
238 246

  
239 247

  
......
245 253
        DataLayer dataLayer = new DataLayer(bodyDataProvider);
246 254
        GlazedListsEventLayer<CdmBase> eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
247 255
        DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(eventLayer);
256
        selectionLayer = bodyLayer.getSelectionLayer();
248 257

  
249 258
        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(
250 259
                new DataLayer(colHeaderDataProvider),
......
307 316
            }
308 317

  
309 318
        }));
319

  
320
        //propagate selection
321
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
322
        RowSelectionProvider<CdmBase> selectionProvider = new RowSelectionProvider<CdmBase>(selectionLayer, bodyDataProvider, true);
323
        selectionProvider.addSelectionChangedListener(selectionChangedListener);
310 324
	}
311 325

  
312 326
	/** {@inheritDoc} */
......
366 380
	    input.saveModel(resetMerge);
367 381

  
368 382
	    List<CdmBase> saveCandidates = getEditorInput().getSaveCandidates();
369
	    ISelection selection = getViewer().getSelection();
383
	    IStructuredSelection selection = getSelection();
370 384

  
371 385
        dirty.setDirty(false);
372 386
        getEditorInput().resetSaveCandidates();
......
376 390

  
377 391
        if (lastQuery != null){
378 392
            performSearch(lastQuery);
379
            getViewer().setSelection(selection, true);
393
            setSelection(selection);
380 394
        }
381 395
//        viewer.refresh();
382 396

  
......
423 437
//        viewer.refresh();
424 438
    }
425 439

  
426
    public TableViewer getViewer() {
427
        return viewer;
440
//    public TableViewer getViewer() {
441
//        return viewer;
442
//    }
443

  
444
    public IStructuredSelection getSelection(){
445
        List<CdmBase> selection = new ArrayList<>();
446
        int[] fullySelectedRowPositions = selectionLayer.getFullySelectedRowPositions();
447
        for (int i : fullySelectedRowPositions) {
448
            Object rowObject = bodyDataProvider.getRowObject(i);
449
            if(rowObject instanceof CdmBase){
450
                selection.add((CdmBase) rowObject);
451
            }
452
        }
453
        return new StructuredSelection(selection);
454
    }
455

  
456
    public void setSelection(IStructuredSelection selection){
457
        Object[] objects = selection.toArray();
458
        for (Object object : objects) {
459
            if(object instanceof CdmBase){
460
                selectionLayer.selectRow(0, bodyDataProvider.indexOfRowObject((CdmBase) object), false, false);
461
            }
462
        }
428 463
    }
429 464

  
430 465
    public void setDirty(){
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/command/DynamicMarkerTypeEditingMenuE4.java
88 88
	    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
89 89
	            MHandledMenuItem menuItem){
90 90
	        boolean canExecute = false;
91
	        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
91
	        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
92 92
	        canExecute = !selection.isEmpty() && selection.getFirstElement() instanceof IAnnotatableEntity;
93 93
	        menuItem.setVisible(canExecute);
94 94
	        return canExecute;
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertPerson2TeamHandlerE4.java
75 75
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
76 76
            MHandledMenuItem menuItem){
77 77
        boolean canExecute = false;
78
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
78
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
79 79
        canExecute = ((BulkEditorE4)activePart.getObject()).getEditorInput().isConvertingEnabled() && selection.getFirstElement() instanceof Person && selection.size() == 1;
80 80
        menuItem.setVisible(canExecute);
81 81
        return canExecute;
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertTeam2PersonHandlerE4.java
77 77
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
78 78
            MHandledMenuItem menuItem){
79 79
        boolean canExecute = false;
80
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
80
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
81 81
        canExecute = ((BulkEditorE4)activePart.getObject()).getEditorInput().isConvertingEnabled() && selection.getFirstElement() instanceof Team && selection.size() == 1;
82 82
        menuItem.setVisible(canExecute);
83 83
        return canExecute;
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/DeleteHandlerE4.java
282 282
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
283 283
            MHandledMenuItem menuItem){
284 284
        boolean canExecute = false;
285
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
285
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
286 286
        canExecute = !selection.isEmpty();
287 287
        menuItem.setVisible(canExecute);
288 288
        return canExecute;
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/RemoveMergeCandidateHandlerE4.java
53 53
            MHandledMenuItem menuItem) {
54 54
        boolean canExecute = false;
55 55
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
56
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
56
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
57 57
        boolean selectedMergeCandidate = false;
58 58
        if (selection instanceof StructuredSelection){
59 59
            for(Object object: selection.toArray()){
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java
57 57
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
58 58
            MHandledMenuItem menuItem){
59 59
        boolean canExecute = false;
60
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
60
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
61 61
        canExecute = !selection.isEmpty() && selection.getFirstElement() instanceof IAnnotatableEntity;
62 62
        menuItem.setVisible(canExecute);
63 63
        return canExecute;
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeCandidateHandlerE4.java
56 56
        boolean canExecute = false;
57 57
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
58 58

  
59
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
59
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
60 60
        canExecute = !selection.isEmpty()
61 61
                && editor.getEditorInput().isMergingEnabled()
62 62
                && !editor.getEditorInput().getMergeCandidates().contains(selection.getFirstElement());
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeTargetHandlerE4.java
46 46
            MHandledMenuItem menuItem) {
47 47
        boolean canExecute = false;
48 48
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
49
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
49
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
50 50
        canExecute = !selection.isEmpty()
51 51
                && editor.getEditorInput().isMergingEnabled()
52 52
                && (editor.getEditorInput().getMergeTarget()==null
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/e4/handler/OpenRelatedConceptHandlerE4.java
18 18
import org.eclipse.e4.ui.services.IServiceConstants;
19 19
import org.eclipse.e4.ui.workbench.modeling.EModelService;
20 20
import org.eclipse.e4.ui.workbench.modeling.EPartService;
21
import org.eclipse.jface.viewers.ISelection;
22 21
import org.eclipse.jface.viewers.IStructuredSelection;
23 22

  
24 23
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
61 60
            relatedTaxon = getRelatedTaxon(taxonRelationship, editor.getTaxon());
62 61
        }
63 62
        else if(bulkEditor!=null){
64
            ISelection bulkSelection = bulkEditor.getViewer().getSelection();
65
            if(bulkSelection instanceof IStructuredSelection){
66
                Object firstElement = ((IStructuredSelection)bulkSelection).getFirstElement();
67
                if(firstElement instanceof Taxon){
68
                    relatedTaxon = getRelatedTaxon(taxonRelationship, (Taxon) firstElement);
69
                }
63
            IStructuredSelection bulkSelection = bulkEditor.getSelection();
64
            Object firstElement = bulkSelection.getFirstElement();
65
            if(firstElement instanceof Taxon){
66
                relatedTaxon = getRelatedTaxon(taxonRelationship, (Taxon) firstElement);
70 67
            }
71 68
        }
72 69

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)