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