]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerToolTip.java
Sync git svn branch with SVN repository r33219.
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / GraphExplorerToolTip.java
1 package org.simantics.browsing.ui.swt;\r
2 \r
3 import org.eclipse.jface.window.ToolTip;\r
4 import org.eclipse.swt.graphics.Point;\r
5 import org.eclipse.swt.widgets.Composite;\r
6 import org.eclipse.swt.widgets.Event;\r
7 import org.eclipse.swt.widgets.Tree;\r
8 import org.eclipse.swt.widgets.TreeItem;\r
9 import org.simantics.browsing.ui.BuiltinKeys;\r
10 import org.simantics.browsing.ui.NodeContext;\r
11 import org.simantics.browsing.ui.common.internal.GENodeQueryManager;\r
12 import org.simantics.browsing.ui.common.labelers.LabelerStub;\r
13 import org.simantics.browsing.ui.content.Labeler;\r
14 import org.simantics.browsing.ui.swt.GraphExplorerImpl.GraphExplorerContext;\r
15 \r
16 public class GraphExplorerToolTip extends ToolTip {\r
17 \r
18     private boolean DEBUG = false;\r
19     \r
20     private Tree parent;\r
21     private NodeContext nodeContext;\r
22     private Labeler labeler;\r
23 \r
24     private GraphExplorerContext explorerContext;\r
25     \r
26     public GraphExplorerToolTip(GraphExplorerContext explorerContext, Tree parent) {\r
27         super(parent, NO_RECREATE, false);\r
28         setHideOnMouseDown(false);\r
29         setPopupDelay(400);\r
30         this.explorerContext = explorerContext;\r
31         this.parent = parent;\r
32         this.nodeContext = null;\r
33         if (DEBUG)\r
34             System.out.println("GraphExplorerToolTip constructor called for parent : " + parent + ", class : " + parent.getClass().toString());\r
35     }\r
36 \r
37     @Override\r
38     protected Composite createToolTipContentArea(Event event, Composite parent) {\r
39         return ((LabelerStub) labeler).createToolTipContentArea(event, parent, nodeContext);\r
40     }\r
41     \r
42     @Override\r
43     protected boolean shouldCreateToolTip(Event event) {\r
44         TreeItem treeItem = parent.getItem(new Point(event.x, event.y));\r
45         if (treeItem == null)\r
46             return false;\r
47         GENodeQueryManager manager = new GENodeQueryManager(explorerContext, null, null, TreeItemReference.create(treeItem.getParentItem()));\r
48         nodeContext = (NodeContext) treeItem.getData();\r
49         if (nodeContext != null)\r
50             labeler = manager.query(nodeContext, BuiltinKeys.SELECTED_LABELER);\r
51         if (nodeContext == null || !(labeler instanceof LabelerStub))\r
52             return false;\r
53         return ((LabelerStub) labeler).shouldCreateToolTip(event, nodeContext);\r
54     }\r
55 \r
56     public void setGraphExplorerContext(GraphExplorerContext explorerContext) {\r
57         this.explorerContext = explorerContext;\r
58     }\r
59 \r
60 }\r