]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.event.view.handler;\r
13 \r
14 import java.util.Collection;\r
15 \r
16 import org.simantics.databoard.Bindings;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.db.VirtualGraph;\r
19 import org.simantics.db.WriteGraph;\r
20 import org.simantics.db.common.request.WriteRequest;\r
21 import org.simantics.db.exception.DatabaseException;\r
22 import org.simantics.event.ontology.EventResource;\r
23 \r
24 /**\r
25  * This action fixes all MilestoneLabels of an EventLog.\r
26  * \r
27  * The label is derieved from the order number of an event. \r
28  * \r
29  * @author toni.kalajainen\r
30  */\r
31 public class CorrectMilestoneLabelsAction extends WriteRequest {\r
32 \r
33         Resource eventlog;\r
34 \r
35         public CorrectMilestoneLabelsAction(Resource eventlog, VirtualGraph vg) {\r
36                 super(vg);\r
37                 this.eventlog = eventlog;\r
38         }\r
39 \r
40         @Override\r
41         public void perform(WriteGraph graph) throws DatabaseException {\r
42                 EventResource EVENT = EventResource.getInstance(graph);\r
43                 MilestoneList ml = graph.sync( new MilestoneListQuery( eventlog ) );\r
44                 //System.out.println("Setting labels");\r
45                 if ( !ml.milestones.isEmpty() ) {\r
46                         for (int i=0; i<ml.milestones.size(); i++) {\r
47                                 String lbl = Integer.toString( i+1 );\r
48                                 Resource milestone = ml.milestones.get(i);\r
49                                 graph.claimLiteral(milestone, EVENT.Event_milestoneLabel, lbl, Bindings.STRING);\r
50                                 //System.out.println("Setting "+milestone+" to "+lbl);\r
51                         }\r
52                 }\r
53 \r
54         }\r
55 \r
56         public static void correctMilestoneLabels(WriteGraph graph, VirtualGraph vg, Collection<Resource> events) throws DatabaseException {\r
57                 Collection<Resource> eventlogs = graph.sync( new GetEventLogsQuery( events ) );\r
58                 for (Resource eventlog : eventlogs) {\r
59                         graph.syncRequest( new CorrectMilestoneLabelsAction(eventlog, vg) );\r
60                 }\r
61         }\r
62 \r
63 }\r