X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FGraphExplorerToolTip.java;fp=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FGraphExplorerToolTip.java;h=26e4431038d3b43da160aad78d74b9884ef572fc;hb=96bb7ef9cbe42d82eb58306d8f9b62392cc29ba8;hp=0000000000000000000000000000000000000000;hpb=ae5bb63c5c88f6569518fed2a24df86fbd0570ff;p=simantics%2Fplatform.git 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 index 000000000..26e443103 --- /dev/null +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerToolTip.java @@ -0,0 +1,57 @@ +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)); + 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; + } + +}