1 package org.simantics.diagram.profile.view;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.widgets.Event;
5 import org.eclipse.swt.widgets.Listener;
6 import org.eclipse.swt.widgets.Tree;
7 import org.eclipse.swt.widgets.TreeItem;
8 import org.simantics.Simantics;
9 import org.simantics.browsing.ui.BuiltinKeys;
10 import org.simantics.browsing.ui.GraphExplorer;
11 import org.simantics.browsing.ui.NodeContext;
12 import org.simantics.db.Resource;
13 import org.simantics.db.WriteGraph;
14 import org.simantics.db.common.request.WriteRequest;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.service.VirtualGraphSupport;
17 import org.simantics.diagram.stubs.DiagramResource;
18 import org.simantics.scenegraph.profile.ProfileUtils;
19 import org.simantics.simulation.ontology.SimulationResource;
21 public class ProfileEntrySelectionListener implements Listener {
23 public void processRecursively(WriteGraph graph, Resource runtimeProfile, Resource entry, boolean checked) throws DatabaseException {
25 DiagramResource DIA = DiagramResource.getInstance(graph);
27 if(graph.isInstanceOf(entry, DIA.Profile)) {
29 for(Resource child : ProfileUtils.getProfileChildren(graph, entry)) {
30 processRecursively(graph, runtimeProfile, child, checked);
33 } else if(graph.isInstanceOf(entry, DIA.ProfileEntry)) {
36 graph.claim(runtimeProfile, SimulationResource.getInstance(graph).IsActive, null, entry);
38 graph.denyStatement(runtimeProfile, SimulationResource.getInstance(graph).IsActive, entry);
46 public void handleEvent (Event event) {
48 if(event.detail == SWT.CHECK) {
50 final TreeItem item = (TreeItem)event.item;
51 Tree tree = item.getParent();
52 GraphExplorer explorer = (GraphExplorer)tree.getData(GraphExplorer.KEY_GRAPH_EXPLORER);
53 final Resource runtimeDiagram = (Resource)explorer.getRoot().getConstant(BuiltinKeys.INPUT);
54 final boolean checked = item.getChecked();
55 NodeContext context = (NodeContext)item.getData();
56 final ResourcePair entry = (ResourcePair)context.getConstant(BuiltinKeys.INPUT);
59 VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class);
60 Simantics.getSession().syncRequest(new WriteRequest(support.getWorkspacePersistent("profiles")) {
63 public void perform(WriteGraph graph) throws DatabaseException {
65 DiagramResource DIA = DiagramResource.getInstance(graph);
66 Resource runtimeProfile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
67 processRecursively(graph, runtimeProfile, entry.getSecond(), checked);
72 } catch (DatabaseException e) {