]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerToolTip.java
Sync git svn branch with SVN repository r33144.
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / GraphExplorerToolTip.java
diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerToolTip.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerToolTip.java
new file mode 100644 (file)
index 0000000..26e4431
--- /dev/null
@@ -0,0 +1,57 @@
+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
+        GENodeQueryManager manager = new GENodeQueryManager(explorerContext, null, null, TreeItemReference.create(treeItem.getParentItem()));\r
+        nodeContext = (NodeContext) treeItem.getData();\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