]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ActiveProfileModifier.java
Better support for ontological profiles
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / ActiveProfileModifier.java
1 package org.simantics.diagram.profile.view;
2
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;
11
12 public class ActiveProfileModifier extends ModifyComboListenerImpl<Resource, Resource> {
13
14         @Override
15         public void applySelection(WriteGraph graph, final Resource runtimeDiagram, final Resource profile) throws DatabaseException {
16                 
17         VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class);
18         Simantics.getSession().asyncRequest(new WriteRequest(support.getWorkspacePersistent("profiles")) {
19
20             @Override
21             public void perform(WriteGraph graph) throws DatabaseException {
22
23                         DiagramResource DIA = DiagramResource.getInstance(graph);
24                         Resource current = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
25                         if(profile.equals(current)) return;
26                 
27                                 graph.deny(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile, null, current);
28                                 graph.claim(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile, null, profile);
29
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);
35                                 
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);
40                                 
41             }
42             
43         });
44                 
45         }
46
47 }