-/*******************************************************************************\r
- * Copyright (c) 2015 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Semantum Oy - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.model.actions;\r
-\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.model.nodetypes.NodeType;\r
-import org.simantics.browsing.ui.model.nodetypes.NodeTypeMultiMap;\r
-import org.simantics.browsing.ui.model.tests.Test;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.viewpoint.ontology.ViewpointResource;\r
-\r
-/**\r
- * Encapsulation of a browse context {@link NodeType} and input tester. Consists\r
- * of a node type, a priority and a possible {@link Test} that returns whether\r
- * the action related to this test is enabled or not. If there is no test\r
- * defined, the test is considered to return <code>true</code>.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class TestContribution implements Comparable<TestContribution> {\r
-\r
- NodeType nodeType;\r
- Test test;\r
- double priority;\r
-\r
- public TestContribution(NodeType nodeType, Test test, double priority) {\r
- super();\r
- this.nodeType = nodeType;\r
- this.test = test;\r
- this.priority = priority;\r
- }\r
-\r
- public static void load(ReadGraph g, Resource r, NodeTypeMultiMap<TestContribution> contributions) throws DatabaseException {\r
- ViewpointResource VR = ViewpointResource.getInstance(g);\r
-\r
- NodeType nodeType = g.adapt(g.getSingleObject(r, VR.TestContribution_HasNodeType), NodeType.class);\r
-\r
- Resource testResource = g.getPossibleObject(r, VR.TestContribution_HasTest);\r
- Test test = testResource == null ? null : g.adapt(testResource, Test.class);\r
-\r
- Double mpriority = g.getPossibleRelatedValue(r, VR.DropActionContribution_HasPriority);\r
- double priority = mpriority == null ? 0.0 : mpriority.doubleValue();\r
-\r
- contributions.put(nodeType, new TestContribution(nodeType, test, priority));\r
- }\r
-\r
- public boolean test(ReadGraph graph, NodeContext context) {\r
- try {\r
- return test == null || test.test(graph, context.getConstant(BuiltinKeys.INPUT));\r
- } catch (DatabaseException e) {\r
- Logger.defaultLogError(e);\r
- return false;\r
- }\r
- }\r
-\r
- @Override\r
- public int compareTo(TestContribution o) {\r
- return Double.compare(o.priority, priority);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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 <code>true</code>.
+ *
+ * @author Tuukka Lehtonen
+ */
+public class TestContribution implements Comparable<TestContribution> {
+
+ 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<TestContribution> 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);
+ }
+
+}