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