]> gerrit.simantics Code Review - simantics/platform.git/blob
656159abf3cc948e36ba8f326b9268cd6f9045a6
[simantics/platform.git] /
1 package org.simantics.diagram.profile.view;
2
3 import org.simantics.Simantics;
4 import org.simantics.browsing.ui.swt.ModelledActionImpl;
5 import org.simantics.db.Resource;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.common.request.WriteRequest;
8 import org.simantics.db.common.utils.NameUtils;
9 import org.simantics.db.common.utils.OrderedSetUtils;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.diagram.Logger;
12 import org.simantics.diagram.stubs.DiagramResource;
13 import org.simantics.layer0.Layer0;
14
15 public class CreateProfileAction extends ModelledActionImpl<Resource> {
16
17         public CreateProfileAction(Resource configuration) {
18                 super(configuration);
19         }
20         
21         public void run(final Resource runtimeDiagram) {
22
23                 try {
24                 
25                         Simantics.getSession().syncRequest(new WriteRequest() {
26         
27                                 @Override
28                                 public void perform(WriteGraph graph) throws DatabaseException {
29         
30                                         Layer0 L0 = Layer0.getInstance(graph);
31                                         DiagramResource DIA = DiagramResource.getInstance(graph);
32                                 String modelURI = graph.getPossibleRelatedValue((Resource)runtimeDiagram, DIA.RuntimeDiagram_HasModelURI);
33                                 if (modelURI == null) return;
34                                 
35                                 Resource model = graph.getPossibleResource(modelURI);
36                                 if(model == null) return;
37                                 
38                                 String name = NameUtils.findFreshName(graph, "Profile", model, L0.ConsistsOf);
39
40                                 Resource list = OrderedSetUtils.create(graph, DIA.Profile);
41
42                                 Resource profile = graph.newResource();
43                                 graph.claim(profile, L0.InstanceOf, null, DIA.Profile);
44                                 graph.claimLiteral(profile, L0.HasName, name);
45                                 graph.claim(profile, DIA.HasEntries, null, list);
46                                 graph.claim(model, L0.ConsistsOf, profile);
47                                 //graph.claim(model, DIA.HasProfile, profile);
48         
49                                 }
50         
51                         });
52                 
53                 } catch (DatabaseException e) {
54
55                         Logger.defaultLogError(e);
56                         
57                 }
58
59         }
60
61 }