]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/NewSubscription.java
(refs #7561) Allow extra parameters to the application of type alias
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / NewSubscription.java
1 package org.simantics.modeling.ui.actions;
2
3 import java.util.UUID;
4
5 import org.simantics.db.Resource;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.common.CommentMetadata;
8 import org.simantics.db.common.request.WriteRequest;
9 import org.simantics.db.common.utils.NameUtils;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.adapter.ActionFactory;
12 import org.simantics.layer0.Layer0;
13 import org.simantics.layer0.utils.direct.GraphUtils;
14 import org.simantics.modeling.ModelingResources;
15 import org.simantics.ui.SimanticsUI;
16
17 /**
18  * @author Tuukka Lehtonen
19  */
20 public class NewSubscription implements ActionFactory {
21
22     @Override
23     public Runnable create(Object target) {
24         if (!(target instanceof Resource))
25             return null;
26         final Resource model = (Resource)target;
27
28         return new Runnable() {
29             @Override
30             public void run() {
31                 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
32                     @Override
33                     public void perform(WriteGraph g) throws DatabaseException {
34                         g.markUndoPoint();
35                         
36                         Layer0 l0 = Layer0.getInstance(g);
37                         ModelingResources wr = ModelingResources.getInstance(g);
38                         String freshLabel = NameUtils.findFreshLabel(g, "Subscription", model);
39                         @SuppressWarnings("unused")
40                         Resource subscription = GraphUtils.create2(g, wr.Subscription,
41                                 l0.HasName, UUID.randomUUID().toString(),
42                                 l0.HasLabel, freshLabel,
43                                 l0.PartOf, model);
44                         
45                         CommentMetadata cm = g.getMetadata(CommentMetadata.class);
46                         g.addMetadata(cm.add("Created subscription folder " + freshLabel));
47                     }
48                 });
49             }
50         };
51     }
52
53 }