]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/TypicalMasterRemover.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / TypicalMasterRemover.java
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/TypicalMasterRemover.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/TypicalMasterRemover.java
new file mode 100644 (file)
index 0000000..7d1f0e2
--- /dev/null
@@ -0,0 +1,33 @@
+package org.simantics.modeling.adapters;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.IsParent;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class TypicalMasterRemover extends ExistingInstancesRemover {\r
+\r
+       public TypicalMasterRemover(Resource resource, String typeDescription) {\r
+               super(resource, typeDescription);\r
+       }\r
+\r
+       @Override\r
+       public void remove(WriteGraph graph) throws DatabaseException {\r
+               // In typical masters the actual typical type is defined as a part of\r
+               // the master instance itself. Therefore we need to customize this code\r
+               // to look for the correct type.\r
+               for (Resource type : graph.getPrincipalTypes(resource)) {\r
+                       if (graph.syncRequest(new IsParent(resource, type))) {\r
+                               remove(graph, resource, type, resource);\r
+                               return;\r
+                       }\r
+               }\r
+\r
+               // Typical type not found. Just remove, no questions asked.\r
+               justRemove(graph);\r
+       }\r
+\r
+}
\ No newline at end of file