]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java
Added some enforcement of immutability to structural user component UI's.
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / utils / StructuralUtils.java
index 0b0214e61ccf798be797d09c751282e6cbb4bc3a..d029f3ae7942db8592e2bc68241b30f5af17b2af 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.CommentMetadata;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.PossibleTypedParent;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.exception.MissingVariableException;\r
@@ -273,5 +274,17 @@ public class StructuralUtils {
        }\r
        return null;\r
     }\r
-    \r
+\r
+    public static boolean isImmutable(ReadGraph graph, Resource r) throws DatabaseException {\r
+        StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
+        Resource uc = graph.syncRequest(new PossibleTypedParent(r, STR.ComponentType));\r
+        return graph.isImmutable(r)\r
+                // Anything under a published or locked user component is published as well\r
+                || (uc != null && (Layer0Utils.isPublished(graph, uc)\r
+                         || graph.hasStatement(uc, STR.ComponentType_Locked)))\r
+                // Anything under a published container (shared library) is published as well\r
+                || Layer0Utils.isContainerPublished(graph, r)\r
+                ;\r
+    }\r
+\r
 }\r