1 package org.simantics.modeling.ui.actions;
\r
3 import java.util.UUID;
\r
5 import org.simantics.db.Resource;
\r
6 import org.simantics.db.WriteGraph;
\r
7 import org.simantics.db.common.CommentMetadata;
\r
8 import org.simantics.db.common.request.WriteRequest;
\r
9 import org.simantics.db.common.utils.NameUtils;
\r
10 import org.simantics.db.exception.DatabaseException;
\r
11 import org.simantics.db.layer0.adapter.ActionFactory;
\r
12 import org.simantics.layer0.Layer0;
\r
13 import org.simantics.layer0.utils.direct.GraphUtils;
\r
14 import org.simantics.modeling.ModelingResources;
\r
15 import org.simantics.ui.SimanticsUI;
\r
18 * @author Tuukka Lehtonen
\r
20 public class NewSubscription implements ActionFactory {
\r
23 public Runnable create(Object target) {
\r
24 if (!(target instanceof Resource))
\r
26 final Resource model = (Resource)target;
\r
28 return new Runnable() {
\r
31 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
33 public void perform(WriteGraph g) throws DatabaseException {
\r
36 Layer0 l0 = Layer0.getInstance(g);
\r
37 ModelingResources wr = ModelingResources.getInstance(g);
\r
38 String freshLabel = NameUtils.findFreshLabel(g, "Subscription", model);
\r
39 @SuppressWarnings("unused")
\r
40 Resource subscription = GraphUtils.create2(g, wr.Subscription,
\r
41 l0.HasName, UUID.randomUUID().toString(),
\r
42 l0.HasLabel, freshLabel,
\r
45 CommentMetadata cm = g.getMetadata(CommentMetadata.class);
\r
46 g.addMetadata(cm.add("Created subscription folder " + freshLabel));
\r