1 package org.simantics.diagram.profile.view;
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;
15 public class CreateProfileAction extends ModelledActionImpl<Resource> {
17 public CreateProfileAction(Resource configuration) {
21 public void run(final Resource runtimeDiagram) {
25 Simantics.getSession().syncRequest(new WriteRequest() {
28 public void perform(WriteGraph graph) throws DatabaseException {
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;
35 Resource model = graph.getPossibleResource(modelURI);
36 if(model == null) return;
38 String name = NameUtils.findFreshName(graph, "Profile", model, L0.ConsistsOf);
40 Resource list = OrderedSetUtils.create(graph, DIA.Profile);
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);
53 } catch (DatabaseException e) {
55 Logger.defaultLogError(e);