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