1 package org.simantics.sysdyn.modelImport.model.support;
\r
3 import java.util.HashSet;
\r
4 import java.util.Set;
\r
6 import org.simantics.db.Resource;
\r
7 import org.simantics.db.WriteGraph;
\r
8 import org.simantics.db.common.utils.ListUtils;
\r
9 import org.simantics.db.exception.DatabaseException;
\r
10 import org.simantics.layer0.Layer0;
\r
11 import org.simantics.layer0.utils.direct.GraphUtils;
\r
12 import org.simantics.sysdyn.SysdynResource;
\r
13 import org.simantics.sysdyn.modelImport.model.IWriteableObject;
\r
14 import org.simantics.sysdyn.modelImport.model.WriteContext;
\r
16 public class Enumeration implements IWriteableObject {
\r
18 private String name;
\r
19 private Set<String> values;
\r
21 private Resource enumeration;
\r
23 public Enumeration(String name, Set<String> values) {
\r
25 this.values = values;
\r
28 public String getName() {
\r
32 public Set<String> getValues() {
\r
37 public Resource write(WriteGraph graph, Resource parent, WriteContext context)
\r
38 throws DatabaseException {
\r
39 Layer0 l0 = Layer0.getInstance(graph);
\r
40 SysdynResource sr = SysdynResource.getInstance(graph);
\r
42 enumeration = GraphUtils.create2(graph, sr.Enumeration,
\r
46 Set<Resource> indices = new HashSet<Resource>();
\r
47 for (String index : values) {
\r
48 indices.add(GraphUtils.create2(graph, sr.EnumerationIndex,
\r
49 l0.HasName, index));
\r
52 graph.claim(enumeration, sr.Enumeration_enumerationIndexList, ListUtils.create(graph, indices));
\r
58 public Resource getResource() {
\r