1 package org.simantics.browsing.ui.swt;
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.TreeColumn;
9 import org.eclipse.swt.widgets.TreeItem;
10 import org.simantics.browsing.ui.BuiltinKeys;
11 import org.simantics.browsing.ui.NodeContext;
12 import org.simantics.browsing.ui.common.internal.GENodeQueryManager;
13 import org.simantics.browsing.ui.common.labelers.LabelerStub;
14 import org.simantics.browsing.ui.content.Labeler;
15 import org.simantics.browsing.ui.swt.GraphExplorerImpl.GraphExplorerContext;
17 public class GraphExplorerToolTip extends ToolTip {
19 private boolean DEBUG = false;
22 private NodeContext nodeContext;
23 private Labeler labeler;
25 private GraphExplorerContext explorerContext;
27 public GraphExplorerToolTip(GraphExplorerContext explorerContext, Tree parent) {
28 super(parent, NO_RECREATE, false);
29 setHideOnMouseDown(false);
31 this.explorerContext = explorerContext;
33 this.nodeContext = null;
35 System.out.println("GraphExplorerToolTip constructor called for parent : " + parent + ", class : " + parent.getClass().toString());
39 protected Composite createToolTipContentArea(Event event, Composite parent) {
40 return ((LabelerStub) labeler).createToolTipContentArea(event, parent, nodeContext);
44 protected boolean shouldCreateToolTip(Event event) {
45 TreeItem treeItem = parent.getItem(new Point(event.x, event.y));
48 // Locate the column, and add the column reference to Event object.
49 TreeColumn columns[] = parent.getColumns();
50 TreeColumn column = null;
52 for (TreeColumn c : columns) {
54 if (event.x >= x && event.x < (x+w)) {
61 event.data = column.getData();
63 GENodeQueryManager manager = new GENodeQueryManager(explorerContext, null, null, TreeItemReference.create(treeItem.getParentItem()));
64 nodeContext = (NodeContext) treeItem.getData();
65 if (nodeContext != null)
66 labeler = manager.query(nodeContext, BuiltinKeys.SELECTED_LABELER);
67 if (nodeContext == null || !(labeler instanceof LabelerStub))
69 return ((LabelerStub) labeler).shouldCreateToolTip(event, nodeContext);
72 public void setGraphExplorerContext(GraphExplorerContext explorerContext) {
73 this.explorerContext = explorerContext;