X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.nattable%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fnattable%2FNatTableSelectionAdaptor.java;fp=bundles%2Forg.simantics.browsing.ui.nattable%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fnattable%2FNatTableSelectionAdaptor.java;h=03588ae76736ecafa64cb054f0fc12d41c629ed2;hp=4302cdeacf74d4d69bca07c6de6bfdd7ff476772;hb=145a2884933f2ffdd48d6835729e58f1152d274e;hpb=bd5bc6e45f700e755b61bd112631796631330ecb diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableSelectionAdaptor.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableSelectionAdaptor.java index 4302cdeac..03588ae76 100644 --- a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableSelectionAdaptor.java +++ b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableSelectionAdaptor.java @@ -1,6 +1,7 @@ package org.simantics.browsing.ui.nattable; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.eclipse.jface.viewers.IPostSelectionProvider; @@ -21,6 +22,7 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Event; import org.simantics.utils.datastructures.MapList; +import org.simantics.utils.ui.AdaptionUtils; public class NatTableSelectionAdaptor implements ISelectionProvider, IPostSelectionProvider, ILayerListener { NatTable natTable; @@ -76,9 +78,41 @@ public class NatTableSelectionAdaptor implements ISelectionProvider, IPostSelect public void setSelection(ISelection selection) { if (!(selection instanceof StructuredSelection)) throw new IllegalArgumentException("Selection must be structured selection"); + if (selection.isEmpty()) { + selectionLayer.clear(false); + natTable.redraw(); + return; + } + List rowItems = new ArrayList<>(AdaptionUtils.adaptToCollection(selection, RowSelectionItem.class)); + if (rowItems.size() > 0) { + + setSelectionExternal(rowItems); + return; + } + Collection nodes = AdaptionUtils.adaptToCollection(selection, TreeNode.class); + if (nodes.size() > 0) { + List selected = new ArrayList<>(); + int allCols[] = new int[selectionLayer.getColumnCount()]; + for (int i = 0; i < allCols.length; i++) + allCols[i] = i; + for (TreeNode n : nodes) { + selected.add(new RowSelectionItem(n, n.listIndex, allCols)); + } + setSelectionExternal(selected); + return; + } } + private void setSelectionExternal(List items) { + selectionLayer.clear(true); + for (RowSelectionItem item : items) { + for (int c : item.columnIndex) + selectionLayer.selectCell(c, item.rowIndex, false, true); + } + selection = new StructuredSelection(items); + fireEvents(); + } private List selectedCells = new ArrayList();