-/*******************************************************************************\r
- * Copyright (c) 2013 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.modeling.ui.modelBrowser2.contributions;\r
-\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.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public enum IsUserDefinedComponentTest implements Test {\r
-\r
- INSTANCE;\r
-\r
- public static IsUserDefinedComponentTest get() {\r
- return INSTANCE;\r
- }\r
-\r
- @Override\r
- public boolean isCompatible(Class<?> contentType) {\r
- return Variable.class.equals(contentType) ||\r
- Resource.class.equals(contentType);\r
- }\r
-\r
- @Override\r
- public boolean test(ReadGraph graph, Object content) throws DatabaseException {\r
- if (content instanceof Variable) {\r
- Variable v = (Variable) content;\r
- //System.out.println("Test variable: " + v.getURI(graph));\r
- StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
- Resource type = v.getPossibleType(graph, STR.Component);\r
- //System.out.println("variable component type: " + NameUtils.getURIOrSafeNameInternal(graph, type));\r
- return isUserComponentType(graph, type, STR);\r
- } else if (content instanceof Resource) {\r
- Resource r = (Resource) content;\r
- //System.out.println("Test resource: " + NameUtils.getURIOrSafeNameInternal(graph, r));\r
- StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
- Resource type = graph.getPossibleType(r, STR.Component);\r
- //System.out.println("resource component type: " + NameUtils.getURIOrSafeNameInternal(graph, type));\r
- return isUserComponentType(graph, type, STR);\r
- }\r
- return false;\r
- }\r
-\r
- private static boolean isUserComponentType(ReadGraph graph, Resource type, StructuralResource2 STR) throws DatabaseException {\r
- if (type == null)\r
- return false;\r
- Resource definedBy = graph.getPossibleObject(type, STR.IsDefinedBy);\r
- if (definedBy != null)\r
- return true;\r
- boolean procedural = graph.isInstanceOf(type, STR.ProceduralComponentType);\r
- return procedural;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2013 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.modeling.ui.modelBrowser2.contributions;
+
+import org.simantics.browsing.ui.model.tests.Test;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.structural.stubs.StructuralResource2;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public enum IsUserDefinedComponentTest implements Test {
+
+ INSTANCE;
+
+ public static IsUserDefinedComponentTest get() {
+ return INSTANCE;
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ return Variable.class.equals(contentType) ||
+ Resource.class.equals(contentType);
+ }
+
+ @Override
+ public boolean test(ReadGraph graph, Object content) throws DatabaseException {
+ if (content instanceof Variable) {
+ Variable v = (Variable) content;
+ //System.out.println("Test variable: " + v.getURI(graph));
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource type = v.getPossibleType(graph, STR.Component);
+ //System.out.println("variable component type: " + NameUtils.getURIOrSafeNameInternal(graph, type));
+ return isUserComponentType(graph, type, STR);
+ } else if (content instanceof Resource) {
+ Resource r = (Resource) content;
+ //System.out.println("Test resource: " + NameUtils.getURIOrSafeNameInternal(graph, r));
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource type = graph.getPossibleType(r, STR.Component);
+ //System.out.println("resource component type: " + NameUtils.getURIOrSafeNameInternal(graph, type));
+ return isUserComponentType(graph, type, STR);
+ }
+ return false;
+ }
+
+ private static boolean isUserComponentType(ReadGraph graph, Resource type, StructuralResource2 STR) throws DatabaseException {
+ if (type == null)
+ return false;
+ Resource definedBy = graph.getPossibleObject(type, STR.IsDefinedBy);
+ if (definedBy != null)
+ return true;
+ boolean procedural = graph.isInstanceOf(type, STR.ProceduralComponentType);
+ return procedural;
+ }
+
+}