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