]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.team.ui/src/org/simantics/team/ui/handlers/StageInitHandler.java
09e8d6d2ddba473cf4b2a4ccd71b63628055e2f8
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / handlers / StageInitHandler.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.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.Platform;
19 import org.simantics.db.Session;
20 import org.simantics.team.Activator;
21 import org.simantics.team.ui.CommentDialog;
22 import org.simantics.team.ui.StageInitWizard;
23 import org.simantics.ui.SimanticsUI;
24 import org.simantics.ui.workbench.handler.AbstractPreferenceHandler;
25 import org.simantics.utils.ui.dialogs.ShowError;
26
27 public class StageInitHandler extends AbstractPreferenceHandler {
28
29     public StageInitHandler() {
30         super(Activator.getDefault());
31     }
32     private void showError(String msg, Throwable t) {
33         String title = "Staging Initialization";
34         ShowError.showError(title, msg, t);
35     }
36     @Override
37     public Object execute(ExecutionEvent event) throws ExecutionException {
38         System.out.println("DEBUG: " + this.getClass().getName());
39         try {
40             Session session = SimanticsUI.getSession();
41             File wsFolder = new File(Platform.getInstanceLocation().getURL().getFile());
42             File stFolder = new File(wsFolder, "staging");
43             final StageInitWizard.Data data = new StageInitWizard.Data(stFolder, null);
44             if (!StageInitWizard.openInitWizard(data))
45                 return null; // User cancelled the operation.
46             File tf = data.teamFolder;
47             assert(null != tf && tf.isDirectory() && tf.list().length == 0);
48             CommentDialog.Data  commentData = CommitAllHandler.commitAll(data.teamFolder, true); // init
49             if (!commentData.ok)
50                 return null; // User cancelled the operation.
51             //Utils.setTeamFolder(tf);
52             SynchroniseAllHandler.pullAll(session, tf, stFolder);
53             SynchroniseAllHandler.show(session, tf, stFolder);
54         } catch (Throwable t) {
55             showError("Failed!", t);
56         }
57         return null;
58     }
59 }