]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
bbaaa54a72995ec173564f3eabdc062eecafdf76
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
2 \r
3 import java.util.HashMap;\r
4 import java.util.ListIterator;\r
5 import java.util.Map;\r
6 \r
7 import org.simantics.browsing.ui.graph.impl.contributor.labeler.ColumnLabelerContributorImpl;\r
8 import org.simantics.db.ReadGraph;\r
9 import org.simantics.db.Resource;\r
10 import org.simantics.db.common.utils.NameUtils;\r
11 import org.simantics.db.common.utils.OrderedSetUtils;\r
12 import org.simantics.db.exception.DatabaseException;\r
13 import org.simantics.sysdyn.SysdynResource;\r
14 import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
15 \r
16 public class EnumerationLabeler extends ColumnLabelerContributorImpl<EnumerationNode>{\r
17 \r
18         @Override\r
19         public Map<String, String> getLabel(ReadGraph graph, EnumerationNode input)\r
20                         throws DatabaseException {\r
21                 \r
22                 String name =  NameUtils.getSafeName(graph, input.data);\r
23                 HashMap<String, String> map = new HashMap<String, String>();\r
24                 map.put(ColumnKeys.ENUMERATION, name);\r
25                 \r
26                 SysdynResource sr = SysdynResource.getInstance(graph);\r
27                 \r
28                 Resource enumerationIndexes = graph.getPossibleObject(input.data, sr.HasEnumerationIndexes);\r
29                 ListIterator<Resource> indexes = OrderedSetUtils.iterator(graph, enumerationIndexes);\r
30                 StringBuilder sb = new StringBuilder();\r
31                 sb.append("[");\r
32                 while(indexes.hasNext()) {\r
33                         Resource i = indexes.next();\r
34                         sb.append(NameUtils.getSafeName(graph, i));\r
35                         if(indexes.hasNext())\r
36                                 sb.append(", ");\r
37                 }\r
38                 sb.append("]");\r
39                 \r
40                 Boolean relaceable = graph.getPossibleRelatedValue(input.data, sr.IsReplaceable);\r
41                 if(Boolean.TRUE.equals(relaceable)) {\r
42                         sb.append(" Replaceable");\r
43                 }\r
44                 \r
45                 map.put(ColumnKeys.INDEXES, sb.toString());\r
46                 \r
47                 return map;\r
48         }\r
49 \r
50 \r
51 \r
52 }\r