X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FGraphExplorerToolTip.java;h=0cc2e71a8c768ddce6c08a2a85cb648794b0a4e5;hp=71e9dd113a17d7bbcfb43b738a42a37c4d9704d7;hb=972fd5be2b27129dd53bbf885d9a95314e47ddc2;hpb=86e91ef31d25e4d5950cae130754846d15119c61 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 index 71e9dd113..0cc2e71a8 100644 --- 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 @@ -1,59 +1,74 @@ -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.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; - GENodeQueryManager manager = new GENodeQueryManager(explorerContext, null, null, TreeItemReference.create(treeItem.getParentItem())); - nodeContext = (NodeContext) treeItem.getData(); - 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; - } - -} +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; + } + +}