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