]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package org.simantics.modeling.adapters;\r
2 \r
3 import org.simantics.db.Resource;\r
4 import org.simantics.db.WriteGraph;\r
5 import org.simantics.db.common.request.IsParent;\r
6 import org.simantics.db.exception.DatabaseException;\r
7 \r
8 /**\r
9  * @author Tuukka Lehtonen\r
10  */\r
11 public class TypicalMasterRemover extends ExistingInstancesRemover {\r
12 \r
13         public TypicalMasterRemover(Resource resource, String typeDescription) {\r
14                 super(resource, typeDescription);\r
15         }\r
16 \r
17         @Override\r
18         public void remove(WriteGraph graph) throws DatabaseException {\r
19                 // In typical masters the actual typical type is defined as a part of\r
20                 // the master instance itself. Therefore we need to customize this code\r
21                 // to look for the correct type.\r
22                 for (Resource type : graph.getPrincipalTypes(resource)) {\r
23                         if (graph.syncRequest(new IsParent(resource, type))) {\r
24                                 remove(graph, resource, type, resource);\r
25                                 return;\r
26                         }\r
27                 }\r
28 \r
29                 // Typical type not found. Just remove, no questions asked.\r
30                 justRemove(graph);\r
31         }\r
32 \r
33 }