]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
d55a10f36cd213946a2304975d4a0a800b21fc3f
[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 \r
15 public class EnumerationLabeler extends ColumnLabelerContributorImpl<EnumerationNode>{\r
16 \r
17         @Override\r
18         public Map<String, String> getLabel(ReadGraph graph, EnumerationNode input)\r
19                         throws DatabaseException {\r
20                 \r
21                 String name =  NameUtils.getSafeName(graph, input.data);\r
22                 HashMap<String, String> map = new HashMap<String, String>();\r
23                 map.put(Keys.ENUMERATION, name);\r
24                 \r
25                 SysdynResource sr = SysdynResource.getInstance(graph);\r
26                 Resource enumerationIndexes = graph.getPossibleObject(input.data, sr.HasEnumerationIndexes);\r
27                 ListIterator<Resource> indexes = OrderedSetUtils.iterator(graph, enumerationIndexes);\r
28                 StringBuilder sb = new StringBuilder();\r
29                 sb.append("[");\r
30                 while(indexes.hasNext()) {\r
31                         Resource i = indexes.next();\r
32                         sb.append(NameUtils.getSafeName(graph, i));\r
33                         if(indexes.hasNext())\r
34                                 sb.append(", ");\r
35                 }\r
36                 sb.append("]");\r
37                 map.put(Keys.INDEXES, sb.toString());\r
38                 return map;\r
39         }\r
40 \r
41 \r
42 \r
43 }\r