]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.ui/src/org/simantics/ui/tester/CollectionResourcePropertyTester.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / tester / CollectionResourcePropertyTester.java
index 13cff7d32a6ebaa8bdd919e1d7520a8828b7b078..99d38138f60fe9a27634efff4fb4cd170563ef5a 100644 (file)
-/*******************************************************************************\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.ui.tester;\r
-\r
-import java.util.Arrays;\r
-\r
-import org.eclipse.core.expressions.PropertyTester;\r
-import org.simantics.DatabaseJob;\r
-import org.simantics.Simantics;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.common.utils.RequestUtil;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.ResourceNotFoundException;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.scl.reflection.OntologyVersions;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.ResourceAdaptionUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class CollectionResourcePropertyTester extends PropertyTester {\r
-\r
-    private static final boolean DEBUG = false;\r
-\r
-    /**\r
-     * Tests if the received resource is an instance of any of the URIs\r
-     * listed in the arguments.\r
-     */\r
-    protected static final String RESOURCE_TYPES = "resourceTypes";\r
-\r
-    private static final OntologyVersions VERSIONS = OntologyVersions.getInstance();\r
-    \r
-    @Override\r
-    public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {\r
-        if (DEBUG)\r
-            System.out.println("TEST: " + receiver + ", " + property + ", " + Arrays.toString(args) + ", " + expectedValue);\r
-\r
-        final Resource[] resources = ResourceAdaptionUtils.toResources(receiver);\r
-        if (resources == null)\r
-            return false;\r
-\r
-        ISessionContext ctx = Simantics.getSessionContext();\r
-        if (ctx == null)\r
-            return false;\r
-\r
-        if (DatabaseJob.inProgress())\r
-            return false;\r
-\r
-        try {\r
-            return RequestUtil.trySyncRequest(\r
-                    ctx.getSession(),\r
-                    SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,\r
-                    SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT,\r
-                    false,\r
-                    new UniqueRead<Boolean>() {\r
-                @Override\r
-                public Boolean perform(ReadGraph g) throws DatabaseException {\r
-                    return Boolean.valueOf(doTest(g, resources, property, args, expectedValue));\r
-                }\r
-            });\r
-        } catch (DatabaseException | InterruptedException e) {\r
-            // Purposefully not logging these exceptions, there might be way too\r
-            // many even under normal circumstances.\r
-            // TODO: add debug tracing options controlling the printing of these exceptions\r
-            return false;\r
-        }\r
-    }\r
-\r
-    protected boolean doTest(ReadGraph g, Resource[] resources, String property, Object[] args, Object expectedValue) throws DatabaseException {\r
-        if (RESOURCE_TYPES.equals(property)) {\r
-               loop: for(Resource r : resources) {\r
-                       if (DEBUG)\r
-                               System.out.println("** " + NameUtils.getSafeName(g, r));\r
-                       try {\r
-                               for (int i = 0; i < args.length; i++) {\r
-                                       if (g.isInstanceOf(r, g.getResource(VERSIONS.currentVersion((String) args[i])))) {\r
-                                               if (DEBUG)\r
-                                                       System.out.println("IS INSTANCE OF " + args[i]);\r
-                                               continue loop;\r
-                                       }\r
-                               }\r
-                       } catch (ResourceNotFoundException e) {\r
-                               /* This is a natural situation (database does not contain all resources\r
-                   referred in plugins). No error reporting.\r
-                                */\r
-                               return false;\r
-                       }\r
-                       if (DEBUG)\r
-                               System.out.println("NOT AN INSTANCE OF ANY OF: " + Arrays.toString(args));\r
-                       return false;\r
-               }\r
-            return true;\r
-        }\r
-        return false;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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.ui.tester;
+
+import java.util.Arrays;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.common.utils.RequestUtil;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ResourceNotFoundException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.scl.reflection.OntologyVersions;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.ui.utils.ResourceAdaptionUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class CollectionResourcePropertyTester extends PropertyTester {
+
+    private static final boolean DEBUG = false;
+
+    /**
+     * Tests if the received resource is an instance of any of the URIs
+     * listed in the arguments.
+     */
+    protected static final String RESOURCE_TYPES = "resourceTypes";
+
+    private static final OntologyVersions VERSIONS = OntologyVersions.getInstance();
+    
+    @Override
+    public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
+        if (DEBUG)
+            System.out.println("TEST: " + receiver + ", " + property + ", " + Arrays.toString(args) + ", " + expectedValue);
+
+        final Resource[] resources = ResourceAdaptionUtils.toResources(receiver);
+        if (resources == null)
+            return false;
+
+        ISessionContext ctx = Simantics.getSessionContext();
+        if (ctx == null)
+            return false;
+
+        if (DatabaseJob.inProgress())
+            return false;
+
+        try {
+            return RequestUtil.trySyncRequest(
+                    ctx.getSession(),
+                    SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,
+                    SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT,
+                    false,
+                    new UniqueRead<Boolean>() {
+                @Override
+                public Boolean perform(ReadGraph g) throws DatabaseException {
+                    return Boolean.valueOf(doTest(g, resources, property, args, expectedValue));
+                }
+            });
+        } catch (DatabaseException | InterruptedException e) {
+            // Purposefully not logging these exceptions, there might be way too
+            // many even under normal circumstances.
+            // TODO: add debug tracing options controlling the printing of these exceptions
+            return false;
+        }
+    }
+
+    protected boolean doTest(ReadGraph g, Resource[] resources, String property, Object[] args, Object expectedValue) throws DatabaseException {
+        if (RESOURCE_TYPES.equals(property)) {
+               loop: for(Resource r : resources) {
+                       if (DEBUG)
+                               System.out.println("** " + NameUtils.getSafeName(g, r));
+                       try {
+                               for (int i = 0; i < args.length; i++) {
+                                       if (g.isInstanceOf(r, g.getResource(VERSIONS.currentVersion((String) args[i])))) {
+                                               if (DEBUG)
+                                                       System.out.println("IS INSTANCE OF " + args[i]);
+                                               continue loop;
+                                       }
+                               }
+                       } catch (ResourceNotFoundException e) {
+                               /* This is a natural situation (database does not contain all resources
+                   referred in plugins). No error reporting.
+                                */
+                               return false;
+                       }
+                       if (DEBUG)
+                               System.out.println("NOT AN INSTANCE OF ANY OF: " + Arrays.toString(args));
+                       return false;
+               }
+            return true;
+        }
+        return false;
+    }
+
+}