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%2Factions%2FTestContribution.java;h=e20f8e6709ebca037a9ce9db4414de2a0dc4a876;hp=a9e02eb2ea76046738fbd4468da862bb730766ab;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/actions/TestContribution.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/actions/TestContribution.java index a9e02eb2e..e20f8e670 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/actions/TestContribution.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/actions/TestContribution.java @@ -1,74 +1,74 @@ -/******************************************************************************* - * Copyright (c) 2015 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: - * Semantum Oy - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.model.actions; - -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.model.nodetypes.NodeType; -import org.simantics.browsing.ui.model.nodetypes.NodeTypeMultiMap; -import org.simantics.browsing.ui.model.tests.Test; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.Logger; -import org.simantics.db.exception.DatabaseException; -import org.simantics.viewpoint.ontology.ViewpointResource; - -/** - * Encapsulation of a browse context {@link NodeType} and input tester. Consists - * of a node type, a priority and a possible {@link Test} that returns whether - * the action related to this test is enabled or not. If there is no test - * defined, the test is considered to return true. - * - * @author Tuukka Lehtonen - */ -public class TestContribution implements Comparable { - - NodeType nodeType; - Test test; - double priority; - - public TestContribution(NodeType nodeType, Test test, double priority) { - super(); - this.nodeType = nodeType; - this.test = test; - this.priority = priority; - } - - public static void load(ReadGraph g, Resource r, NodeTypeMultiMap contributions) throws DatabaseException { - ViewpointResource VR = ViewpointResource.getInstance(g); - - NodeType nodeType = g.adapt(g.getSingleObject(r, VR.TestContribution_HasNodeType), NodeType.class); - - Resource testResource = g.getPossibleObject(r, VR.TestContribution_HasTest); - Test test = testResource == null ? null : g.adapt(testResource, Test.class); - - Double mpriority = g.getPossibleRelatedValue(r, VR.DropActionContribution_HasPriority); - double priority = mpriority == null ? 0.0 : mpriority.doubleValue(); - - contributions.put(nodeType, new TestContribution(nodeType, test, priority)); - } - - public boolean test(ReadGraph graph, NodeContext context) { - try { - return test == null || test.test(graph, context.getConstant(BuiltinKeys.INPUT)); - } catch (DatabaseException e) { - Logger.defaultLogError(e); - return false; - } - } - - @Override - public int compareTo(TestContribution o) { - return Double.compare(o.priority, priority); - } - -} +/******************************************************************************* + * Copyright (c) 2015 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: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.model.actions; + +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.model.nodetypes.NodeType; +import org.simantics.browsing.ui.model.nodetypes.NodeTypeMultiMap; +import org.simantics.browsing.ui.model.tests.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; +import org.simantics.viewpoint.ontology.ViewpointResource; + +/** + * Encapsulation of a browse context {@link NodeType} and input tester. Consists + * of a node type, a priority and a possible {@link Test} that returns whether + * the action related to this test is enabled or not. If there is no test + * defined, the test is considered to return true. + * + * @author Tuukka Lehtonen + */ +public class TestContribution implements Comparable { + + NodeType nodeType; + Test test; + double priority; + + public TestContribution(NodeType nodeType, Test test, double priority) { + super(); + this.nodeType = nodeType; + this.test = test; + this.priority = priority; + } + + public static void load(ReadGraph g, Resource r, NodeTypeMultiMap contributions) throws DatabaseException { + ViewpointResource VR = ViewpointResource.getInstance(g); + + NodeType nodeType = g.adapt(g.getSingleObject(r, VR.TestContribution_HasNodeType), NodeType.class); + + Resource testResource = g.getPossibleObject(r, VR.TestContribution_HasTest); + Test test = testResource == null ? null : g.adapt(testResource, Test.class); + + Double mpriority = g.getPossibleRelatedValue(r, VR.DropActionContribution_HasPriority); + double priority = mpriority == null ? 0.0 : mpriority.doubleValue(); + + contributions.put(nodeType, new TestContribution(nodeType, test, priority)); + } + + public boolean test(ReadGraph graph, NodeContext context) { + try { + return test == null || test.test(graph, context.getConstant(BuiltinKeys.INPUT)); + } catch (DatabaseException e) { + Logger.defaultLogError(e); + return false; + } + } + + @Override + public int compareTo(TestContribution o) { + return Double.compare(o.priority, priority); + } + +}