X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.model%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fmodel%2Fvisuals%2FVisualsContribution.java;h=824ab862d3a6b490311d26083658a5195e3bef40;hp=01d2078ce752fb55eaa2d289cba77c8a58056605;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/visuals/VisualsContribution.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/visuals/VisualsContribution.java index 01d2078ce..824ab862d 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/visuals/VisualsContribution.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/visuals/VisualsContribution.java @@ -1,127 +1,127 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.model.visuals; - -import org.simantics.browsing.ui.model.InvalidContribution; -import org.simantics.browsing.ui.model.check.CheckedStateContribution; -import org.simantics.browsing.ui.model.check.CheckedStateRule; -import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationContribution; -import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationRule; -import org.simantics.browsing.ui.model.images.ImageContribution; -import org.simantics.browsing.ui.model.images.ImageRule; -import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationContribution; -import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; -import org.simantics.browsing.ui.model.labels.LabelContribution; -import org.simantics.browsing.ui.model.labels.LabelRule; -import org.simantics.browsing.ui.model.modifiers.ModifierContribution; -import org.simantics.browsing.ui.model.modifiers.ModifierRule; -import org.simantics.browsing.ui.model.nodetypes.NodeType; -import org.simantics.browsing.ui.model.nodetypes.OrderedNodeTypeMultiMap; -import org.simantics.browsing.ui.model.sorters.SorterContribution; -import org.simantics.browsing.ui.model.sorters.SorterRule; -import org.simantics.browsing.ui.model.tests.Test; -import org.simantics.browsing.ui.model.tooltips.TooltipContribution; -import org.simantics.browsing.ui.model.tooltips.TooltipRule; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.AdaptionException; -import org.simantics.db.exception.DatabaseException; -import org.simantics.viewpoint.ontology.ViewpointResource; - -/** - * Produces labels for nodes of given node type. - * @author Hannu Niemistö - */ -public class VisualsContribution implements Comparable { - protected NodeType nodeType; - protected Test test; - protected double priority; - - public VisualsContribution(NodeType nodeType, Test test, double priority) throws InvalidContribution { - if(test != null && !test.isCompatible( - nodeType.getContentType() - )) - throw new InvalidContribution("Test is not compatible with the content type."); - this.nodeType = nodeType; - this.test = test; - this.priority = priority; - } - - public static void load(ReadGraph g, Resource visualsContributionResource, - OrderedNodeTypeMultiMap labelContributions, - OrderedNodeTypeMultiMap imageContributions, - OrderedNodeTypeMultiMap checkedStateContributions, - OrderedNodeTypeMultiMap labelDecorationContributions, - OrderedNodeTypeMultiMap imageDecorationContributions, - OrderedNodeTypeMultiMap modifierContributions, - OrderedNodeTypeMultiMap sorterContributions, - OrderedNodeTypeMultiMap flatNodeContributions, - OrderedNodeTypeMultiMap tooltipContributions) - throws DatabaseException, InvalidContribution { - ViewpointResource vr = ViewpointResource.getInstance(g); - - Resource testResource = g.getPossibleObject(visualsContributionResource, vr.VisualsContribution_HasCondition); - Test test = testResource == null ? null : g.adapt(testResource, Test.class); - - Double mpriority = g.getPossibleRelatedValue(visualsContributionResource, vr.VisualsContribution_HasPriority); - double priority = mpriority == null ? 0.0 : mpriority.doubleValue(); - - for(Resource nodeTypeResource : g.getObjects(visualsContributionResource, vr.VisualsContribution_HasNodeType)) { - NodeType nodeType = g.adapt(nodeTypeResource, NodeType.class); - - for(Resource ruleResource : g.getObjects(visualsContributionResource, vr.VisualsContribution_HasRule)) { - if(ruleResource.equals(vr.FlatNodeRule)) - flatNodeContributions.put(nodeType, FlatNodeContribution.INSTANCE); - else { - VisualsRule rule; - try { - rule = g.adapt(ruleResource, VisualsRule.class); - } catch(AdaptionException e) { - e.printStackTrace(); - continue; - } - try { - // Note: the rule may be an instance of multiple interfaces - if(rule instanceof LabelRule) - labelContributions.put(nodeType, new LabelContribution(nodeType, test, (LabelRule)rule, priority)); - if(rule instanceof ModifierRule) - modifierContributions.put(nodeType, new ModifierContribution(nodeType, test, (ModifierRule)rule, priority)); - if(rule instanceof ImageRule) - imageContributions.put(nodeType, new ImageContribution(nodeType, test, (ImageRule)rule, priority)); - if(rule instanceof CheckedStateRule) - checkedStateContributions.put(nodeType, new CheckedStateContribution(nodeType, test, (CheckedStateRule)rule, priority)); - if(rule instanceof LabelDecorationRule) - labelDecorationContributions.put(nodeType, new LabelDecorationContribution(nodeType, test, (LabelDecorationRule)rule, priority)); - if(rule instanceof ImageDecorationRule) - imageDecorationContributions.put(nodeType, new ImageDecorationContribution(nodeType, test, (ImageDecorationRule)rule, priority)); - if(rule instanceof SorterRule) - sorterContributions.put(nodeType, new SorterContribution(nodeType, test, (SorterRule)rule, priority)); - if(rule instanceof TooltipRule) - tooltipContributions.put(nodeType, new TooltipContribution(nodeType, test, (TooltipRule)rule, priority)); - } catch(InvalidContribution e) { - e.printStackTrace(); - continue; - } - } - } - } - } - - public NodeType getNodeType() { - return nodeType; - } - - @Override - public int compareTo(VisualsContribution o) { - return Double.compare(o.priority, priority); - } -} +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.model.visuals; + +import org.simantics.browsing.ui.model.InvalidContribution; +import org.simantics.browsing.ui.model.check.CheckedStateContribution; +import org.simantics.browsing.ui.model.check.CheckedStateRule; +import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationContribution; +import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationRule; +import org.simantics.browsing.ui.model.images.ImageContribution; +import org.simantics.browsing.ui.model.images.ImageRule; +import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationContribution; +import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; +import org.simantics.browsing.ui.model.labels.LabelContribution; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.browsing.ui.model.modifiers.ModifierContribution; +import org.simantics.browsing.ui.model.modifiers.ModifierRule; +import org.simantics.browsing.ui.model.nodetypes.NodeType; +import org.simantics.browsing.ui.model.nodetypes.OrderedNodeTypeMultiMap; +import org.simantics.browsing.ui.model.sorters.SorterContribution; +import org.simantics.browsing.ui.model.sorters.SorterRule; +import org.simantics.browsing.ui.model.tests.Test; +import org.simantics.browsing.ui.model.tooltips.TooltipContribution; +import org.simantics.browsing.ui.model.tooltips.TooltipRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.viewpoint.ontology.ViewpointResource; + +/** + * Produces labels for nodes of given node type. + * @author Hannu Niemistö + */ +public class VisualsContribution implements Comparable { + protected NodeType nodeType; + protected Test test; + protected double priority; + + public VisualsContribution(NodeType nodeType, Test test, double priority) throws InvalidContribution { + if(test != null && !test.isCompatible( + nodeType.getContentType() + )) + throw new InvalidContribution("Test is not compatible with the content type."); + this.nodeType = nodeType; + this.test = test; + this.priority = priority; + } + + public static void load(ReadGraph g, Resource visualsContributionResource, + OrderedNodeTypeMultiMap labelContributions, + OrderedNodeTypeMultiMap imageContributions, + OrderedNodeTypeMultiMap checkedStateContributions, + OrderedNodeTypeMultiMap labelDecorationContributions, + OrderedNodeTypeMultiMap imageDecorationContributions, + OrderedNodeTypeMultiMap modifierContributions, + OrderedNodeTypeMultiMap sorterContributions, + OrderedNodeTypeMultiMap flatNodeContributions, + OrderedNodeTypeMultiMap tooltipContributions) + throws DatabaseException, InvalidContribution { + ViewpointResource vr = ViewpointResource.getInstance(g); + + Resource testResource = g.getPossibleObject(visualsContributionResource, vr.VisualsContribution_HasCondition); + Test test = testResource == null ? null : g.adapt(testResource, Test.class); + + Double mpriority = g.getPossibleRelatedValue(visualsContributionResource, vr.VisualsContribution_HasPriority); + double priority = mpriority == null ? 0.0 : mpriority.doubleValue(); + + for(Resource nodeTypeResource : g.getObjects(visualsContributionResource, vr.VisualsContribution_HasNodeType)) { + NodeType nodeType = g.adapt(nodeTypeResource, NodeType.class); + + for(Resource ruleResource : g.getObjects(visualsContributionResource, vr.VisualsContribution_HasRule)) { + if(ruleResource.equals(vr.FlatNodeRule)) + flatNodeContributions.put(nodeType, FlatNodeContribution.INSTANCE); + else { + VisualsRule rule; + try { + rule = g.adapt(ruleResource, VisualsRule.class); + } catch(AdaptionException e) { + e.printStackTrace(); + continue; + } + try { + // Note: the rule may be an instance of multiple interfaces + if(rule instanceof LabelRule) + labelContributions.put(nodeType, new LabelContribution(nodeType, test, (LabelRule)rule, priority)); + if(rule instanceof ModifierRule) + modifierContributions.put(nodeType, new ModifierContribution(nodeType, test, (ModifierRule)rule, priority)); + if(rule instanceof ImageRule) + imageContributions.put(nodeType, new ImageContribution(nodeType, test, (ImageRule)rule, priority)); + if(rule instanceof CheckedStateRule) + checkedStateContributions.put(nodeType, new CheckedStateContribution(nodeType, test, (CheckedStateRule)rule, priority)); + if(rule instanceof LabelDecorationRule) + labelDecorationContributions.put(nodeType, new LabelDecorationContribution(nodeType, test, (LabelDecorationRule)rule, priority)); + if(rule instanceof ImageDecorationRule) + imageDecorationContributions.put(nodeType, new ImageDecorationContribution(nodeType, test, (ImageDecorationRule)rule, priority)); + if(rule instanceof SorterRule) + sorterContributions.put(nodeType, new SorterContribution(nodeType, test, (SorterRule)rule, priority)); + if(rule instanceof TooltipRule) + tooltipContributions.put(nodeType, new TooltipContribution(nodeType, test, (TooltipRule)rule, priority)); + } catch(InvalidContribution e) { + e.printStackTrace(); + continue; + } + } + } + } + } + + public NodeType getNodeType() { + return nodeType; + } + + @Override + public int compareTo(VisualsContribution o) { + return Double.compare(o.priority, priority); + } +}