1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.event.view.handler;
\r
14 import java.util.Collection;
\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
25 * This action fixes all MilestoneLabels of an EventLog.
\r
27 * The label is derieved from the order number of an event.
\r
29 * @author toni.kalajainen
\r
31 public class CorrectMilestoneLabelsAction extends WriteRequest {
\r
35 public CorrectMilestoneLabelsAction(Resource eventlog, VirtualGraph vg) {
\r
37 this.eventlog = eventlog;
\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
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