]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.team.ui/src/org/simantics/team/ui/handlers/DumpToSelectedRevisionHandler.java
6fd74c773b2fabbe301bc2624af9c118b7fce172
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / handlers / DumpToSelectedRevisionHandler.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.ManagementSupport;\r
27 import org.simantics.db.service.TeamSupport;\r
28 import org.simantics.team.ui.Command;\r
29 import org.simantics.ui.SimanticsUI;\r
30 \r
31 public class DumpToSelectedRevisionHandler extends AbstractHandler {\r
32     public DumpToSelectedRevisionHandler() {\r
33     }\r
34     @Override\r
35     public Object execute(ExecutionEvent event) throws ExecutionException {\r
36         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
37         if (sel instanceof IStructuredSelection) {\r
38             IStructuredSelection ss = (IStructuredSelection)sel;\r
39             try {\r
40                 Object o = ss.getFirstElement();\r
41                 if (null == o || !(o instanceof Command))\r
42                     return null;\r
43                 Command command = (Command)o;\r
44                 ChangeSetIdentifier csi = command.getChangeSetIdentifier();\r
45                 if (null == csi)\r
46                     return null;\r
47                 long csid = csi.getId();\r
48                 Session session = SimanticsUI.getSession();\r
49                 ManagementSupport ms = session.getService(ManagementSupport.class);\r
50                 ms.dumpRevision(csid);\r
51                 File wsFolder = new File(Platform.getInstanceLocation().getURL().getFile());\r
52                 File frFolder = new File(wsFolder, "db");\r
53                 File toFolder = new File(wsFolder, "Dump-ws");\r
54                 TeamSupport ts = session.getService(TeamSupport.class);\r
55                 ts.dump(frFolder, toFolder, csid);\r
56                 SynchroniseAllHandler.show(session, null, toFolder);\r
57           } catch (Exception e) {\r
58               Logger.defaultLogError(e);\r
59           }\r
60             \r
61         }\r
62         return null;\r
63     }\r
64 }\r