1 package org.simantics.event.view.handler;
\r
3 import java.util.List;
\r
5 import org.eclipse.jface.action.Action;
\r
6 import org.eclipse.jface.resource.ImageDescriptor;
\r
7 import org.simantics.Simantics;
\r
8 import org.simantics.db.Resource;
\r
9 import org.simantics.db.Session;
\r
10 import org.simantics.db.VirtualGraph;
\r
11 import org.simantics.db.WriteGraph;
\r
12 import org.simantics.db.common.request.WriteRequest;
\r
13 import org.simantics.db.exception.DatabaseException;
\r
14 import org.simantics.db.service.VirtualGraphSupport;
\r
15 import org.simantics.event.ontology.EventResource;
\r
18 * @author Tuukka Lehtonen
\r
20 public class TagAction extends Action {
\r
22 private final String virtualGraphId;
\r
23 private final String tagURI;
\r
24 private final boolean tag;
\r
25 private final List<Resource> resources;
\r
30 * @param virtualGraphId
\r
32 * @param tag <code>true</code> to add tag, <code>false</code> to remove tag
\r
35 public TagAction(String label, ImageDescriptor image, String virtualGraphId, String tagURI, boolean tag, List<Resource> input) {
\r
36 super(label, image);
\r
38 this.virtualGraphId = virtualGraphId;
\r
39 this.tagURI = tagURI;
\r
41 this.resources = input;
\r
46 Session session = Simantics.peekSession();
\r
47 if (session == null) return;
\r
49 final VirtualGraph vg = virtualGraphId == null ? null :
\r
50 session.getService(VirtualGraphSupport.class).getWorkspacePersistent(virtualGraphId);
\r
51 session.asyncRequest(new WriteRequest(vg) {
\r
53 public void perform(WriteGraph graph) throws DatabaseException {
\r
55 Resource tr = graph.getResource(tagURI);
\r
56 for (Resource r : resources) {
\r
58 graph.claim(r, tr, tr, r);
\r
60 graph.deny(r, tr, r);
\r
63 // Set milestone labels for all events of the event log
\r
64 if (tagURI.equals(EventResource.URIs.Milestone)) {
\r
65 CorrectMilestoneLabelsAction.correctMilestoneLabels(graph, vg, resources);
\r
68 // Perform any extra writes desired
\r
69 postTagWrite(graph);
\r
75 public void postTagWrite(WriteGraph graph) throws DatabaseException {
\r