1 package org.simantics.browsing.ui.graph.impl;
5 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.swt.widgets.Event;
8 import org.simantics.Simantics;
9 import org.simantics.browsing.ui.NodeContext;
10 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
11 import org.simantics.browsing.ui.graph.impl.contribution.LabelerContributionImpl;
12 import org.simantics.browsing.ui.model.browsecontexts.BrowseContext;
13 import org.simantics.browsing.ui.model.tooltips.TooltipContribution;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.UndoContext;
16 import org.simantics.db.common.request.UniqueRead;
17 import org.simantics.db.common.utils.RequestUtil;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.ui.SimanticsUI;
21 public class EvaluatorLabeler extends LabelerContributionImpl {
23 final BrowseContext browseContext;
24 final boolean useNodeBrowseContexts;
26 private TooltipContribution currentTooltipContribution;
28 public EvaluatorLabeler(PrimitiveQueryUpdater updater, NodeContext context,
30 BrowseContext browseContext, boolean useNodeBrowseContexts) {
31 super(updater, context, key);
32 this.browseContext = browseContext;
33 this.useNodeBrowseContexts = useNodeBrowseContexts;
37 public Map<String, String> labels(
40 throws DatabaseException {
41 boolean oldSynchronous = graph.setSynchronous(false);
43 return BrowseContext.get(graph,context,browseContext,useNodeBrowseContexts).getLabel(graph, context);
45 graph.setSynchronous(oldSynchronous);
50 public int category(ReadGraph graph,
52 throws DatabaseException {
57 getModifier(ReadGraph graph, UndoContext undoContext,
58 NodeContext context, String columnKey) throws DatabaseException {
59 return BrowseContext.get(graph,context,browseContext,useNodeBrowseContexts).getModifier(graph, context, columnKey);
62 public String toString() {
63 return "EvaluatorLabeler[" + browseContext + "] " + context;
68 public boolean shouldCreateToolTip(Event event, NodeContext context) {
70 currentTooltipContribution = RequestUtil.trySyncRequest(
71 Simantics.getSession(),
72 SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,
73 SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT,
75 new UniqueRead<TooltipContribution>() {
77 public TooltipContribution perform(ReadGraph graph) throws DatabaseException {
78 return BrowseContext.get(graph,context,browseContext,useNodeBrowseContexts).shouldCreateToolTip(graph, event, context);
81 if (currentTooltipContribution != null)
83 } catch (DatabaseException | InterruptedException e) {
90 public Composite createToolTipContentArea(Event event, Composite parent, NodeContext nodeContext) {
91 return (Composite) currentTooltipContribution.getTooltip(event, parent, nodeContext);