]> gerrit.simantics Code Review - simantics/platform.git/blob
6405079c44d5288897c3681e628ddaf4b43c12a7
[simantics/platform.git] /
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.team.ui.handlers;
13
14 import java.io.File;
15
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;
29
30 public class RevertToSelectedRevisionHandlerStopOnError extends AbstractHandler {
31     public RevertToSelectedRevisionHandlerStopOnError() {
32     }
33     @Override
34     public Object execute(ExecutionEvent event) throws ExecutionException {
35         ISelection sel = HandlerUtil.getCurrentSelection(event);
36         if (sel instanceof IStructuredSelection) {
37             IStructuredSelection ss = (IStructuredSelection)sel;
38             try {
39                 Object o = ss.getFirstElement();
40                 if (null == o || !(o instanceof Command))
41                     return null;
42                 Command command = (Command)o;
43                 ChangeSetIdentifier csi = command.getChangeSetIdentifier();
44                 if (null == csi)
45                     return null;
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);
56           }
57             
58         }
59         return null;
60     }
61 }