X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Fview%2Fhandler%2FTagAction.java;fp=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Fview%2Fhandler%2FTagAction.java;h=0de441539f55d7a2293eab8ff09b48e13f4902af;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.event/src/org/simantics/event/view/handler/TagAction.java b/bundles/org.simantics.event/src/org/simantics/event/view/handler/TagAction.java new file mode 100644 index 000000000..0de441539 --- /dev/null +++ b/bundles/org.simantics.event/src/org/simantics/event/view/handler/TagAction.java @@ -0,0 +1,78 @@ +package org.simantics.event.view.handler; + +import java.util.List; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.event.ontology.EventResource; + +/** + * @author Tuukka Lehtonen + */ +public class TagAction extends Action { + + private final String virtualGraphId; + private final String tagURI; + private final boolean tag; + private final List resources; + + /** + * @param label + * @param image + * @param virtualGraphId + * @param tagURI + * @param tag true to add tag, false to remove tag + * @param input + */ + public TagAction(String label, ImageDescriptor image, String virtualGraphId, String tagURI, boolean tag, List input) { + super(label, image); + + this.virtualGraphId = virtualGraphId; + this.tagURI = tagURI; + this.tag = tag; + this.resources = input; + } + + @Override + public void run() { + Session session = Simantics.peekSession(); + if (session == null) return; + + final VirtualGraph vg = virtualGraphId == null ? null : + session.getService(VirtualGraphSupport.class).getWorkspacePersistent(virtualGraphId); + session.asyncRequest(new WriteRequest(vg) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Write tags + Resource tr = graph.getResource(tagURI); + for (Resource r : resources) { + if (tag) + graph.claim(r, tr, tr, r); + else + graph.deny(r, tr, r); + } + + // Set milestone labels for all events of the event log + if (tagURI.equals(EventResource.URIs.Milestone)) { + CorrectMilestoneLabelsAction.correctMilestoneLabels(graph, vg, resources); + } + + // Perform any extra writes desired + postTagWrite(graph); + } + }); + + } + + public void postTagWrite(WriteGraph graph) throws DatabaseException { + } + +}