]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tooltips/TooltipContribution.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.model / src / org / simantics / browsing / ui / model / tooltips / TooltipContribution.java
1 package org.simantics.browsing.ui.model.tooltips;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
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;
14
15 public class TooltipContribution extends VisualsContribution {
16     TooltipRule tooltipRule;
17     
18     private Map<Object, Object> auxiliary = new HashMap<>();
19     
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;
25     }
26
27     public Object getTooltip(Object event, Object parent, NodeContext context) {
28         try {
29             return tooltipRule.createTooltip(event, parent, context, auxiliary);
30         } finally {
31             auxiliary.clear();
32         }
33         
34     }    
35     
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))
39             return false;
40         
41         return tooltipRule.shouldCreateToolTip(graph, context, auxiliary);
42     }
43     
44 }