1 package org.simantics.diagram.profile.view;
\r
3 import org.simantics.Simantics;
\r
4 import org.simantics.browsing.ui.swt.widgets.impl.ModifyComboListenerImpl;
\r
5 import org.simantics.db.Resource;
\r
6 import org.simantics.db.WriteGraph;
\r
7 import org.simantics.db.common.request.WriteRequest;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.db.service.VirtualGraphSupport;
\r
10 import org.simantics.diagram.stubs.DiagramResource;
\r
12 public class ActiveProfileModifier extends ModifyComboListenerImpl<Resource, Resource> {
\r
15 public void applySelection(WriteGraph graph, final Resource runtimeDiagram, final Resource profile) throws DatabaseException {
\r
17 VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class);
\r
18 Simantics.getSession().asyncRequest(new WriteRequest(support.getWorkspacePersistent("profiles")) {
\r
21 public void perform(WriteGraph graph) throws DatabaseException {
\r
23 DiagramResource DIA = DiagramResource.getInstance(graph);
\r
24 Resource current = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
\r
25 if(profile.equals(current)) return;
\r
27 graph.deny(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile, null, current);
\r
28 graph.claim(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile, null, profile);
\r
30 // Set this profile as the default profile for this model
\r
31 String modelURI = graph.getRelatedValue(runtimeDiagram, DIA.RuntimeDiagram_HasModelURI);
\r
32 Resource model = graph.getResource(modelURI);
\r
33 graph.deny(model, DIA.HasActiveProfile);
\r
34 graph.claim(model, DIA.HasActiveProfile, profile);
\r
36 // Set this profile as the default profile for this diagram
\r
37 Resource configuration = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasConfiguration);
\r
38 graph.deny(configuration, DIA.HasActiveProfile);
\r
39 graph.claim(configuration, DIA.HasActiveProfile, profile);
\r