]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
94909cda42d602a5e8c4ee332659bcb38fe0cc49
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
2 \r
3 import org.simantics.browsing.ui.common.node.AbstractNode;\r
4 import org.simantics.browsing.ui.common.node.IModifiableNode;\r
5 import org.simantics.browsing.ui.content.Labeler.Modifier;\r
6 import org.simantics.db.ReadGraph;\r
7 import org.simantics.db.Resource;\r
8 import org.simantics.db.WriteGraph;\r
9 import org.simantics.db.common.request.WriteRequest;\r
10 import org.simantics.db.exception.DatabaseException;\r
11 import org.simantics.db.request.Read;\r
12 import org.simantics.layer0.Layer0;\r
13 import org.simantics.sysdyn.ui.utils.VariableNameUtils;\r
14 import org.simantics.ui.SimanticsUI;\r
15 \r
16 public class EnumerationIndexNode  extends AbstractNode<Resource> implements IModifiableNode {\r
17 \r
18         public EnumerationIndexNode(Resource resource) {\r
19                 super(resource);\r
20         }\r
21         \r
22         @Override\r
23         public Modifier getModifier(String columnId) {\r
24         Modifier modifier = new Modifier() {\r
25 \r
26             @Override\r
27             public String getValue() {\r
28                 Read<String> request =\r
29                     new Read<String>() {\r
30 \r
31                     @Override\r
32                     public String perform(ReadGraph graph) throws DatabaseException {\r
33                         String name = graph.getPossibleRelatedValue(data, Layer0.getInstance(graph).HasName);\r
34                         return name != null ? name : "";\r
35                     }\r
36 \r
37                 };\r
38                 try {\r
39                     return SimanticsUI.getSession().syncRequest(request);\r
40                 } catch (DatabaseException e) {\r
41                     e.printStackTrace();\r
42                     return "";\r
43                 }\r
44             }\r
45 \r
46             @Override\r
47             public String isValid(String label) {\r
48                 if(!VariableNameUtils.isValid(label))\r
49                         return "Not valid";\r
50                 return null;\r
51             }\r
52 \r
53             @Override\r
54             public void modify(final String label) {\r
55                 SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
56                     @Override\r
57                     public void perform(WriteGraph graph) throws DatabaseException {\r
58                         graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label);\r
59                     }\r
60                 });\r
61             }\r
62 \r
63         };\r
64         \r
65         return modifier;\r
66         \r
67         \r
68         \r
69         \r
70         }\r
71 \r
72 }\r