1 package org.simantics.sysdyn.ui.browser.actions;
\r
3 import org.simantics.db.Resource;
\r
4 import org.simantics.db.WriteGraph;
\r
5 import org.simantics.db.common.request.WriteRequest;
\r
6 import org.simantics.db.common.utils.NameUtils;
\r
7 import org.simantics.db.common.utils.OrderedSetUtils;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.db.layer0.adapter.ActionFactory;
\r
10 import org.simantics.layer0.Layer0;
\r
11 import org.simantics.layer0.utils.direct.GraphUtils;
\r
12 import org.simantics.modeling.ModelingResources;
\r
13 import org.simantics.structural.stubs.StructuralResource2;
\r
14 import org.simantics.sysdyn.SysdynResource;
\r
15 import org.simantics.ui.SimanticsUI;
\r
17 public class NewEnumerationAction implements ActionFactory{
\r
20 public Runnable create(Object target) {
\r
21 if(!(target instanceof Resource))
\r
23 final Resource resource = (Resource)target;
\r
25 return new Runnable() {
\r
30 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
33 public void perform(WriteGraph g) throws DatabaseException {
\r
34 SysdynResource sr = SysdynResource.getInstance(g);
\r
35 Layer0 l0 = Layer0.getInstance(g);
\r
37 Resource configuration = null;
\r
38 if(g.isInstanceOf(resource, sr.Configuration)) {
\r
39 configuration = resource;
\r
40 } else if(g.isInheritedFrom(resource, sr.ModuleSymbol)) {
\r
41 Resource module = g.getPossibleObject(resource,ModelingResources.getInstance(g).SymbolToComponentType);
\r
42 configuration = g.getPossibleObject(module, StructuralResource2.getInstance(g).IsDefinedBy);
\r
44 Resource instanceOf = g.getSingleObject(resource, l0.InstanceOf);
\r
45 if(g.isInheritedFrom(instanceOf, sr.Module)) {
\r
46 configuration = g.getPossibleObject(instanceOf, StructuralResource2.getInstance(g).IsDefinedBy);
\r
52 Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes);
\r
54 String name = NameUtils.findFreshName(g, "Enum", configuration, l0.ConsistsOf, "%s%d");
\r
56 GraphUtils.create2(g,
\r
59 sr.HasEnumerationIndexes, enumerationIndexes,
\r
60 l0.PartOf, configuration);
\r