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