]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
cc3283efacf4911f5de5ffd2f38ff00a7d0f4162
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.browser.nodes;\r
2 \r
3 import org.simantics.browsing.ui.common.node.DeleteException;\r
4 import org.simantics.browsing.ui.common.node.IDeletableNode;\r
5 import org.simantics.db.Resource;\r
6 import org.simantics.db.WriteGraph;\r
7 import org.simantics.db.common.request.ObjectsWithType;\r
8 import org.simantics.db.common.request.WriteRequest;\r
9 import org.simantics.db.common.utils.ListUtils;\r
10 import org.simantics.db.exception.CancelTransactionException;\r
11 import org.simantics.db.exception.DatabaseException;\r
12 import org.simantics.db.layer0.util.RemoverUtil;\r
13 import org.simantics.db.layer0.variable.Variable;\r
14 import org.simantics.layer0.Layer0;\r
15 import org.simantics.sysdyn.SysdynResource;\r
16 import org.simantics.ui.SimanticsUI;\r
17 import org.simantics.utils.ui.ExceptionUtils;\r
18 \r
19 public class EnumerationNode extends VariableNode<Resource> implements /*IModifiableNode,*/ IDeletableNode {\r
20 \r
21         public EnumerationNode(Resource resource) {\r
22                 super(resource);\r
23         }\r
24         \r
25         public EnumerationNode(Variable variable, Resource represents) {\r
26         super(variable, represents);\r
27         }\r
28     /*\r
29     @Override\r
30     public Modifier getModifier(String columnId) {\r
31         \r
32         Session session = SimanticsUI.getSession();\r
33         LabelModifier modifier = new LabelModifier(session, data, session.getService(Layer0.class).HasName) {\r
34             @Override\r
35             public String isValid(String label) {\r
36                 if (!new VariableNameValidator().isValid(data, label))\r
37                     return "Not valid";\r
38                 else\r
39                     return null;\r
40             }\r
41         };\r
42         return modifier;\r
43     }*/\r
44 \r
45         @Override\r
46         public void delete() throws DeleteException {\r
47         try {\r
48             SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
49                 @Override\r
50                 public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
51                     SysdynResource sr = SysdynResource.getInstance(graph);\r
52                     for(Resource redeclaration : graph.getObjects(data, sr.Redeclaration_replacedEnumeration_Inverse)) {\r
53                         graph.deny(redeclaration, sr.Module_redeclaration_Inverse);\r
54                     }\r
55                     \r
56                     for(Resource redeclaration : graph.getObjects(data, sr.Redeclaration_replacingEnumeration_Inverse)) {\r
57                         graph.deny(redeclaration, sr.Module_redeclaration_Inverse);\r
58                     }\r
59                     \r
60                     Layer0 L0 = Layer0.getInstance(graph);\r
61                     Resource conf = graph.getPossibleObject(data, L0.PartOf);\r
62                     for(Resource var : graph.syncRequest(new ObjectsWithType(conf, L0.ConsistsOf, sr.Variable))) {\r
63                         Resource arrayIndexes = graph.getPossibleObject(var, sr.Variable_arrayIndexesList);\r
64                         if(arrayIndexes != null) {\r
65                             if(ListUtils.getNode(graph, arrayIndexes, data) != null) {\r
66                                 ListUtils.removeElement(graph, arrayIndexes, data);\r
67                             }\r
68                         }\r
69                     }\r
70                     \r
71                     RemoverUtil.remove(graph, data);\r
72                     \r
73                 }\r
74             });\r
75         } catch (DatabaseException e) {\r
76             ExceptionUtils.logAndShowError(e);\r
77         }        \r
78     }\r
79 \r
80 }\r