]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntrySelectionListener.java
Better support for ontological profiles
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / ProfileEntrySelectionListener.java
index c67558b2733323f25053b134778e8bef974f65e6..f87a8286bb43fa8c06e8006c4d416847003b9b13 100644 (file)
@@ -20,52 +20,41 @@ import org.simantics.simulation.ontology.SimulationResource;
 
 public class ProfileEntrySelectionListener implements Listener {
 
-       public void processRecursively(WriteGraph graph, Resource runtimeProfile, Resource entry, boolean checked) throws DatabaseException {
+    public void processRecursively(WriteGraph graph, Resource runtimeProfile, Resource entry, boolean checked) throws DatabaseException {
+        DiagramResource DIA = DiagramResource.getInstance(graph);
 
-       DiagramResource DIA = DiagramResource.getInstance(graph);
-               
-       if(graph.isInstanceOf(entry, DIA.Profile)) {
-               
-               for(Resource child : ProfileUtils.getProfileChildren(graph, entry)) {
-                       processRecursively(graph, runtimeProfile, child, checked);
-               }
-               
-       } else if(graph.isInstanceOf(entry, DIA.ProfileEntry)) {
-
-            if(checked) {
+        if (graph.isInstanceOf(entry, DIA.Profile)) {
+            for (Resource child : ProfileUtils.getProfileChildren(graph, entry)) {
+                processRecursively(graph, runtimeProfile, child, checked);
+            }
+        } else if (graph.isInstanceOf(entry, DIA.ProfileEntry)) {
+            if (checked) {
                 graph.claim(runtimeProfile, SimulationResource.getInstance(graph).IsActive, null, entry);
             } else {
                 graph.denyStatement(runtimeProfile, SimulationResource.getInstance(graph).IsActive, entry);
             }
+        }
+    }
 
-               }
-               
-       }
-       
     @Override
     public void handleEvent (Event event) {
-       
         if(event.detail == SWT.CHECK) {
-               
             final TreeItem item = (TreeItem)event.item;
             Tree tree = item.getParent();
             GraphExplorer explorer = (GraphExplorer)tree.getData(GraphExplorer.KEY_GRAPH_EXPLORER);
             final Resource runtimeDiagram = (Resource)explorer.getRoot().getConstant(BuiltinKeys.INPUT);
             final boolean checked = item.getChecked();
             NodeContext context = (NodeContext)item.getData();
-            final ResourcePair entry = (ResourcePair)context.getConstant(BuiltinKeys.INPUT);
+            final ProfileTuple entry = (ProfileTuple)context.getConstant(BuiltinKeys.INPUT);
             try {
-               
                 VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class);
                 Simantics.getSession().syncRequest(new WriteRequest(support.getWorkspacePersistent("profiles")) {
 
                     @Override
                     public void perform(WriteGraph graph) throws DatabaseException {
-                       
-                       DiagramResource DIA = DiagramResource.getInstance(graph);
-                       Resource runtimeProfile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
-                       processRecursively(graph, runtimeProfile, entry.getSecond(), checked);
-                        
+                        DiagramResource DIA = DiagramResource.getInstance(graph);
+                        Resource runtimeProfile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
+                        processRecursively(graph, runtimeProfile, entry.getEntry(), checked);
                     }
 
                 });