]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerToolTip.java
Allow column specific tooltips in the GraphExplorer
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / GraphExplorerToolTip.java
index 1debee624e803ae51d95622c6c983c041fc16872..0cc2e71a8c768ddce6c08a2a85cb648794b0a4e5 100644 (file)
@@ -1,60 +1,74 @@
-package org.simantics.browsing.ui.swt;\r
-\r
-import org.eclipse.jface.window.ToolTip;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Event;\r
-import org.eclipse.swt.widgets.Tree;\r
-import org.eclipse.swt.widgets.TreeItem;\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.common.internal.GENodeQueryManager;\r
-import org.simantics.browsing.ui.common.labelers.LabelerStub;\r
-import org.simantics.browsing.ui.content.Labeler;\r
-import org.simantics.browsing.ui.swt.GraphExplorerImpl.GraphExplorerContext;\r
-\r
-public class GraphExplorerToolTip extends ToolTip {\r
-\r
-    private boolean DEBUG = false;\r
-    \r
-    private Tree parent;\r
-    private NodeContext nodeContext;\r
-    private Labeler labeler;\r
-\r
-    private GraphExplorerContext explorerContext;\r
-    \r
-    public GraphExplorerToolTip(GraphExplorerContext explorerContext, Tree parent) {\r
-        super(parent, NO_RECREATE, false);\r
-        setHideOnMouseDown(false);\r
-        setPopupDelay(400);\r
-        this.explorerContext = explorerContext;\r
-        this.parent = parent;\r
-        this.nodeContext = null;\r
-        if (DEBUG)\r
-            System.out.println("GraphExplorerToolTip constructor called for parent : " + parent + ", class : " + parent.getClass().toString());\r
-    }\r
-\r
-    @Override\r
-    protected Composite createToolTipContentArea(Event event, Composite parent) {\r
-        return ((LabelerStub) labeler).createToolTipContentArea(event, parent, nodeContext);\r
-    }\r
-    \r
-    @Override\r
-    protected boolean shouldCreateToolTip(Event event) {\r
-        TreeItem treeItem = parent.getItem(new Point(event.x, event.y));\r
-        if (treeItem == null)\r
-            return false;\r
-        GENodeQueryManager manager = new GENodeQueryManager(explorerContext, null, null, TreeItemReference.create(treeItem.getParentItem()));\r
-        nodeContext = (NodeContext) treeItem.getData();\r
-        if (nodeContext != null)\r
-            labeler = manager.query(nodeContext, BuiltinKeys.SELECTED_LABELER);\r
-        if (nodeContext == null || !(labeler instanceof LabelerStub))\r
-            return false;\r
-        return ((LabelerStub) labeler).shouldCreateToolTip(event, nodeContext);\r
-    }\r
-\r
-    public void setGraphExplorerContext(GraphExplorerContext explorerContext) {\r
-        this.explorerContext = explorerContext;\r
-    }\r
-\r
-}\r
+package org.simantics.browsing.ui.swt;
+
+import org.eclipse.jface.window.ToolTip;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.common.internal.GENodeQueryManager;
+import org.simantics.browsing.ui.common.labelers.LabelerStub;
+import org.simantics.browsing.ui.content.Labeler;
+import org.simantics.browsing.ui.swt.GraphExplorerImpl.GraphExplorerContext;
+
+public class GraphExplorerToolTip extends ToolTip {
+
+    private boolean DEBUG = false;
+    
+    private Tree parent;
+    private NodeContext nodeContext;
+    private Labeler labeler;
+
+    private GraphExplorerContext explorerContext;
+    
+    public GraphExplorerToolTip(GraphExplorerContext explorerContext, Tree parent) {
+        super(parent, NO_RECREATE, false);
+        setHideOnMouseDown(false);
+        setPopupDelay(400);
+        this.explorerContext = explorerContext;
+        this.parent = parent;
+        this.nodeContext = null;
+        if (DEBUG)
+            System.out.println("GraphExplorerToolTip constructor called for parent : " + parent + ", class : " + parent.getClass().toString());
+    }
+
+    @Override
+    protected Composite createToolTipContentArea(Event event, Composite parent) {
+        return ((LabelerStub) labeler).createToolTipContentArea(event, parent, nodeContext);
+    }
+    
+    @Override
+    protected boolean shouldCreateToolTip(Event event) {
+        TreeItem treeItem = parent.getItem(new Point(event.x, event.y));
+        if (treeItem == null)
+            return false;
+        // Locate the column, and add the column reference to Event object.
+        TreeColumn columns[] = parent.getColumns();
+        TreeColumn column = null;
+        int x = 0;
+        for (TreeColumn c : columns) {
+            int w = c.getWidth();
+            if (event.x >= x && event.x < (x+w)) {
+                column = c;
+                break;
+            }
+            x+=w;
+        }
+        event.data = column.getData();
+        GENodeQueryManager manager = new GENodeQueryManager(explorerContext, null, null, TreeItemReference.create(treeItem.getParentItem()));
+        nodeContext = (NodeContext) treeItem.getData();
+        if (nodeContext != null)
+            labeler = manager.query(nodeContext, BuiltinKeys.SELECTED_LABELER);
+        if (nodeContext == null || !(labeler instanceof LabelerStub))
+            return false;
+        return ((LabelerStub) labeler).shouldCreateToolTip(event, nodeContext);
+    }
+
+    public void setGraphExplorerContext(GraphExplorerContext explorerContext) {
+        this.explorerContext = explorerContext;
+    }
+
+}