]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.event/src/org/simantics/event/view/handler/CorrectMilestoneLabelsAction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / view / handler / CorrectMilestoneLabelsAction.java
diff --git a/bundles/org.simantics.event/src/org/simantics/event/view/handler/CorrectMilestoneLabelsAction.java b/bundles/org.simantics.event/src/org/simantics/event/view/handler/CorrectMilestoneLabelsAction.java
new file mode 100644 (file)
index 0000000..a9783b2
--- /dev/null
@@ -0,0 +1,63 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.event.view.handler;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.event.ontology.EventResource;\r
+\r
+/**\r
+ * This action fixes all MilestoneLabels of an EventLog.\r
+ * \r
+ * The label is derieved from the order number of an event. \r
+ * \r
+ * @author toni.kalajainen\r
+ */\r
+public class CorrectMilestoneLabelsAction extends WriteRequest {\r
+\r
+       Resource eventlog;\r
+\r
+       public CorrectMilestoneLabelsAction(Resource eventlog, VirtualGraph vg) {\r
+               super(vg);\r
+               this.eventlog = eventlog;\r
+       }\r
+\r
+       @Override\r
+       public void perform(WriteGraph graph) throws DatabaseException {\r
+               EventResource EVENT = EventResource.getInstance(graph);\r
+               MilestoneList ml = graph.sync( new MilestoneListQuery( eventlog ) );\r
+               //System.out.println("Setting labels");\r
+               if ( !ml.milestones.isEmpty() ) {\r
+                       for (int i=0; i<ml.milestones.size(); i++) {\r
+                               String lbl = Integer.toString( i+1 );\r
+                               Resource milestone = ml.milestones.get(i);\r
+                               graph.claimLiteral(milestone, EVENT.Event_milestoneLabel, lbl, Bindings.STRING);\r
+                               //System.out.println("Setting "+milestone+" to "+lbl);\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       public static void correctMilestoneLabels(WriteGraph graph, VirtualGraph vg, Collection<Resource> events) throws DatabaseException {\r
+               Collection<Resource> eventlogs = graph.sync( new GetEventLogsQuery( events ) );\r
+               for (Resource eventlog : eventlogs) {\r
+                       graph.syncRequest( new CorrectMilestoneLabelsAction(eventlog, vg) );\r
+               }\r
+       }\r
+\r
+}\r