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 {
24 DiagramResource DIA = DiagramResource.getInstance(graph);
26 if (graph.isInstanceOf(entry, DIA.Profile)) {
27 for (Resource child : ProfileUtils.getProfileChildren(graph, entry)) {
28 processRecursively(graph, runtimeProfile, child, checked);
30 } else if (graph.isInstanceOf(entry, DIA.ProfileEntry)) {
32 graph.claim(runtimeProfile, SimulationResource.getInstance(graph).IsActive, null, entry);
34 graph.denyStatement(runtimeProfile, SimulationResource.getInstance(graph).IsActive, entry);
40 public void handleEvent (Event event) {
41 if(event.detail == SWT.CHECK) {
42 final TreeItem item = (TreeItem)event.item;
43 Tree tree = item.getParent();
44 GraphExplorer explorer = (GraphExplorer)tree.getData(GraphExplorer.KEY_GRAPH_EXPLORER);
45 final Resource runtimeDiagram = (Resource)explorer.getRoot().getConstant(BuiltinKeys.INPUT);
46 final boolean checked = item.getChecked();
47 NodeContext context = (NodeContext)item.getData();
48 final ProfileTuple entry = (ProfileTuple)context.getConstant(BuiltinKeys.INPUT);
50 VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class);
51 Simantics.getSession().syncRequest(new WriteRequest(support.getWorkspacePersistent("profiles")) {
54 public void perform(WriteGraph graph) throws DatabaseException {
55 DiagramResource DIA = DiagramResource.getInstance(graph);
56 Resource runtimeProfile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
57 processRecursively(graph, runtimeProfile, entry.getEntry(), checked);
61 } catch (DatabaseException e) {