1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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.team.ui.handlers;
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.ui.handlers.HandlerUtil;
23 import org.simantics.db.ChangeSetIdentifier;
24 import org.simantics.db.Session;
25 import org.simantics.db.common.utils.Logger;
26 import org.simantics.db.service.TeamSupport;
27 import org.simantics.team.ui.Command;
28 import org.simantics.ui.SimanticsUI;
30 public class RevertToSelectedRevisionHandlerStopOnError extends AbstractHandler {
31 public RevertToSelectedRevisionHandlerStopOnError() {
34 public Object execute(ExecutionEvent event) throws ExecutionException {
35 ISelection sel = HandlerUtil.getCurrentSelection(event);
36 if (sel instanceof IStructuredSelection) {
37 IStructuredSelection ss = (IStructuredSelection)sel;
39 Object o = ss.getFirstElement();
40 if (null == o || !(o instanceof Command))
42 Command command = (Command)o;
43 ChangeSetIdentifier csi = command.getChangeSetIdentifier();
46 long csid = csi.getId();
47 Session session = SimanticsUI.getSession();
48 File wsFolder = new File(Platform.getInstanceLocation().getURL().getFile());
49 File frFolder = new File(wsFolder, "db");
50 File toFolder = new File(wsFolder, "Revert-ws");
51 TeamSupport ts = session.getService(TeamSupport.class);
52 ts.revert(frFolder, toFolder, csid, true); // Stop on error.
53 SynchroniseAllHandler.show(session, null, toFolder);
54 } catch (Exception e) {
55 Logger.defaultLogError(e);