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