import org.simantics.layer0.Layer0;
public class DescriptionTooltipRule implements TooltipRule {
-
+
public static final DescriptionTooltipRule INSTANCE = new DescriptionTooltipRule();
-
+
public DescriptionTooltipRule() {
}
public boolean isCompatible(Class<?> contentType) {
return (contentType == Resource.class || contentType == Variable.class);
}
-
+
private static String getToolTipContent(ReadGraph graph, NodeContext nodeContext) throws DatabaseException {
Object input = nodeContext.getConstant(BuiltinKeys.INPUT);
- String content = null;
if (input instanceof Variable) {
Variable var = (Variable) input;
- Resource res = var.getPredicateResource(graph);
- Layer0 L0 = Layer0.getInstance(graph);
- String description = graph.getPossibleRelatedValue2(res, L0.HasDescription);
- return description;
+ Resource res = var.getPossiblePredicateResource(graph);
+ if (res != null) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ return graph.getPossibleRelatedValue2(res, L0.HasDescription);
+ }
} else if (input instanceof Resource) {
Resource res = (Resource) input;
-
Layer0 L0 = Layer0.getInstance(graph);
- String description = graph.getPossibleRelatedValue2(res, L0.HasDescription);
- return description;
+ return graph.getPossibleRelatedValue2(res, L0.HasDescription);
}
- return content;
+ return null;
}
@Override
- public boolean shouldCreateToolTip(ReadGraph graph , NodeContext context, Map<Object, Object> auxiliary) throws DatabaseException {
+ public boolean shouldCreateToolTip(ReadGraph graph, NodeContext context, Map<Object, Object> auxiliary) throws DatabaseException {
String content = getToolTipContent(graph, context);
if (content == null || content.isEmpty())
return false;