]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/property/ModelPropertyTester.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / property / ModelPropertyTester.java
index 5a4d485aa008691a85f5bd832e3d21a5b5517c0d..a03d7dd62c972926a4b25b27729b55ab7db170a4 100644 (file)
@@ -1,82 +1,82 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 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.modeling.ui.property;\r
-\r
-import java.util.Collection;\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.Session;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.common.utils.RequestUtil;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.ActiveModels;\r
-import org.simantics.scl.reflection.OntologyVersions;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ModelPropertyTester extends PropertyTester {\r
-\r
-    /**\r
-     * Tests if the received object within the model browser tree node is an\r
-     * instance of the class specified as the argument.\r
-     */\r
-    private static final String HAS_ACTIVE_MODELS_OF_TYPE = "hasActiveModelsOfType";\r
-\r
-    @Override\r
-    public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {\r
-        try {\r
-            if (HAS_ACTIVE_MODELS_OF_TYPE.equals(property)) {\r
-                if (args.length == 0)\r
-                    return false;\r
-\r
-                Session session = Simantics.peekSession();\r
-                final Resource project = Simantics.peekProjectResource();\r
-                if (session != null && project != null) {\r
-                    if (DatabaseJob.inProgress())\r
-                        return false;\r
-\r
-                    return RequestUtil.trySyncRequest(\r
-                            session,\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 graph)\r
-                                throws DatabaseException {\r
-                            Resource type = graph.getPossibleResource( OntologyVersions.getInstance().currentVersion((String) args[0]) );\r
-                            if (type == null)\r
-                                return false;\r
-\r
-                            Collection<Resource> activeModels = graph.syncRequest(new ActiveModels(project));\r
-                            for (Resource activeModel : activeModels)\r
-                                if (graph.isInstanceOf(activeModel, type))\r
-                                    return true;\r
-                            return false;\r
-                        }\r
-                    });\r
-                }\r
-            }\r
-        } catch (DatabaseException | InterruptedException e) {\r
-            ErrorLogger.defaultLogError(e);\r
-        }\r
-        return false;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 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.modeling.ui.property;
+
+import java.util.Collection;
+
+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.Session;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.common.utils.RequestUtil;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.ActiveModels;
+import org.simantics.scl.reflection.OntologyVersions;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.utils.ui.ErrorLogger;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class ModelPropertyTester extends PropertyTester {
+
+    /**
+     * Tests if the received object within the model browser tree node is an
+     * instance of the class specified as the argument.
+     */
+    private static final String HAS_ACTIVE_MODELS_OF_TYPE = "hasActiveModelsOfType";
+
+    @Override
+    public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
+        try {
+            if (HAS_ACTIVE_MODELS_OF_TYPE.equals(property)) {
+                if (args.length == 0)
+                    return false;
+
+                Session session = Simantics.peekSession();
+                final Resource project = Simantics.peekProjectResource();
+                if (session != null && project != null) {
+                    if (DatabaseJob.inProgress())
+                        return false;
+
+                    return RequestUtil.trySyncRequest(
+                            session,
+                            SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,
+                            SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT,
+                            false,
+                            new UniqueRead<Boolean>() {
+                        @Override
+                        public Boolean perform(ReadGraph graph)
+                                throws DatabaseException {
+                            Resource type = graph.getPossibleResource( OntologyVersions.getInstance().currentVersion((String) args[0]) );
+                            if (type == null)
+                                return false;
+
+                            Collection<Resource> activeModels = graph.syncRequest(new ActiveModels(project));
+                            for (Resource activeModel : activeModels)
+                                if (graph.isInstanceOf(activeModel, type))
+                                    return true;
+                            return false;
+                        }
+                    });
+                }
+            }
+        } catch (DatabaseException | InterruptedException e) {
+            ErrorLogger.defaultLogError(e);
+        }
+        return false;
+    }
+
+}