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