1 package org.simantics.browsing.ui.model.tooltips;
3 import java.util.HashMap;
6 import org.simantics.browsing.ui.BuiltinKeys;
7 import org.simantics.browsing.ui.NodeContext;
8 import org.simantics.browsing.ui.model.InvalidContribution;
9 import org.simantics.browsing.ui.model.nodetypes.NodeType;
10 import org.simantics.browsing.ui.model.tests.Test;
11 import org.simantics.browsing.ui.model.visuals.VisualsContribution;
12 import org.simantics.db.ReadGraph;
13 import org.simantics.db.exception.DatabaseException;
15 public class TooltipContribution extends VisualsContribution {
16 TooltipRule tooltipRule;
18 private Map<Object, Object> auxiliary = new HashMap<>();
20 public TooltipContribution(NodeType nodeType, Test test, TooltipRule tooltipRule, double priority) throws InvalidContribution {
21 super(nodeType, test, priority);
22 if(!tooltipRule.isCompatible(nodeType.getContentType()))
23 throw new InvalidContribution("Tooltip rule is not compatible with the content type.");
24 this.tooltipRule = tooltipRule;
27 public Object getTooltip(Object event, Object parent, NodeContext context) {
29 return tooltipRule.createTooltip(event, parent, context, auxiliary);
36 public boolean shouldCreateToolTip(ReadGraph graph, NodeContext context) throws DatabaseException {
37 Object content = context.getConstant(BuiltinKeys.INPUT);
38 if(test != null && !test.test(graph, content))
41 return tooltipRule.shouldCreateToolTip(graph, context, auxiliary);