]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.team.ui/src/org/simantics/team/ui/handlers/RevertToSelectedRevisionHandlerStopOnError.java
0a5690c4560ed2662c607f39696713e0f652b68b
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / handlers / RevertToSelectedRevisionHandlerStopOnError.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.team.ui.handlers;\r
13 \r
14 import java.io.File;\r
15 \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
29 \r
30 public class RevertToSelectedRevisionHandlerStopOnError extends AbstractHandler {\r
31     public RevertToSelectedRevisionHandlerStopOnError() {\r
32     }\r
33     @Override\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
38             try {\r
39                 Object o = ss.getFirstElement();\r
40                 if (null == o || !(o instanceof Command))\r
41                     return null;\r
42                 Command command = (Command)o;\r
43                 ChangeSetIdentifier csi = command.getChangeSetIdentifier();\r
44                 if (null == csi)\r
45                     return null;\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
56           }\r
57             \r
58         }\r
59         return null;\r
60     }\r
61 }\r