]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph/src/org/simantics/browsing/ui/graph/tester/GraphTesters.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph / src / org / simantics / browsing / ui / graph / tester / GraphTesters.java
diff --git a/bundles/org.simantics.browsing.ui.graph/src/org/simantics/browsing/ui/graph/tester/GraphTesters.java b/bundles/org.simantics.browsing.ui.graph/src/org/simantics/browsing/ui/graph/tester/GraphTesters.java
new file mode 100644 (file)
index 0000000..2990b29
--- /dev/null
@@ -0,0 +1,140 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in 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
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui.graph.tester;\r
+\r
+import org.simantics.Simantics;\r
+import org.simantics.browsing.ui.Tester;\r
+import org.simantics.browsing.ui.common.Testers;\r
+import org.simantics.db.RequestProcessor;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+\r
+/**\r
+ * A facade class for constructing new {@link Tester} instances for standard\r
+ * graph based testing activities. Please use this class instead of directly\r
+ * referring to <code>org.simantics.browsing.ui.graph.tester</code> package\r
+ * classes.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public final class GraphTesters {\r
+\r
+    public static Tester pass() {\r
+        return Testers.PASS;\r
+    }\r
+\r
+    public static Tester fail() {\r
+        return Testers.FAIL;\r
+    }\r
+\r
+    /**\r
+     * @param clazz\r
+     * @return\r
+     * \r
+     * TODO: throw exceptions, don't catch.\r
+     */\r
+    public static Tester type(final String uri) {\r
+        try {\r
+            return type(Simantics.getSession(), uri);\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+            return fail();\r
+        }\r
+    }\r
+\r
+    public static Tester standardContextType(final String uri) {\r
+        try {\r
+            return standardContextType(Simantics.getSession(), uri);\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+            return fail();\r
+        }\r
+    }\r
+\r
+    public static Tester standardContextType(Session s, final String uri) throws DatabaseException {\r
+        return new StandardContextHasSomeTypeTester(s, uri);\r
+    }\r
+\r
+    public static Tester type(Session s, final String uri) throws DatabaseException {\r
+        return new HasSomeTypeTester(s, uri);\r
+    }\r
+\r
+    public static Tester type(Resource resource) {\r
+        return new HasSomeTypeTester(resource);\r
+    }\r
+\r
+    /**\r
+     * @param uri\r
+     * @return\r
+     * \r
+     * TODO: throw exceptions, don't catch.\r
+     */\r
+    public static Tester resource(final String uri) {\r
+        try {\r
+            return resource(Simantics.getSession(), uri);\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+            return fail();\r
+        }\r
+    }\r
+\r
+    public static Tester resource(Session s, final String uri) throws DatabaseException {\r
+        return new EqualsResourceTester(s, uri);\r
+    }\r
+\r
+    public static Tester resource(Resource resource) {\r
+        return new EqualsResourceTester(resource);\r
+    }\r
+\r
+    public static Tester inherits(Resource resource) {\r
+        return new InheritsSomeTypeTester(resource);\r
+    }\r
+\r
+    public static Tester model() throws DatabaseException {\r
+        Session s = Simantics.getSession();\r
+        SimulationResource SIMU = SimulationResource.getInstance(s);\r
+        return new HasSomeTypeTester(SIMU.Model);\r
+    }\r
+\r
+    public static Tester type() {\r
+        return new HasSomeTypeTester(Simantics.getSession().getService(Layer0.class).Type);\r
+    }\r
+\r
+    public static Tester orderedSet() {\r
+        return new OrderedSetTester(Simantics.getSession());\r
+    }\r
+\r
+    public static Tester orderedSet(Session s) {\r
+        return new OrderedSetTester(s);\r
+    }\r
+\r
+    public static Tester hasRelatedObjects(Resource relation) {\r
+        return new HasRelatedObjectsTester(relation);\r
+    }\r
+\r
+    public static Tester hasRelatedObjects(RequestProcessor processor, String relationUri) throws DatabaseException {\r
+        return new HasRelatedObjectsTester(processor, relationUri);\r
+    }\r
+\r
+    public static Tester hasRelatedObjects(String relationUri) {\r
+        try {\r
+            return hasRelatedObjects(Simantics.getSession(), relationUri);\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+            return fail();\r
+        }\r
+    }\r
+\r
+}\r