]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.team.ui/src/org/simantics/team/ui/handlers/CommitAllHandler.java
e047a3e565101de68797d9a3135459ac5d042bd9
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / handlers / CommitAllHandler.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.simantics.db.Session;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.service.TeamSupport;
21 import org.simantics.team.Activator;
22 import org.simantics.team.Utils;
23 import org.simantics.team.ui.CommentDialog;
24 import org.simantics.ui.SimanticsUI;
25 import org.simantics.ui.workbench.handler.AbstractPreferenceHandler;
26
27 public class CommitAllHandler extends AbstractPreferenceHandler {
28
29     public CommitAllHandler() {
30         super(Activator.getDefault());
31     }
32     @Override
33     public Object execute(ExecutionEvent event) throws ExecutionException {
34         System.out.println("CommitAllHandler");
35 //        ISelection sel = HandlerUtil.getCurrentSelection(event);
36 //        IStructuredSelection ss = StructuredSelection.EMPTY;
37 //        if (sel instanceof IStructuredSelection)
38 //            ss = (IStructuredSelection) sel;
39         try {
40             File teamFolder = Utils.getTeamFolder();
41             commitAll(teamFolder, false); // Don't initialize.
42         } catch (DatabaseException e) {
43             throw new ExecutionException("Failed to commit.", e);
44         }
45         return null;
46     }
47     static CommentDialog.Data commitAll(File teamFolder, boolean init) 
48     throws DatabaseException {
49         Session session = SimanticsUI.getSession();
50         TeamSupport ts = session.getService(TeamSupport.class);
51         final CommentDialog.Data data = new CommentDialog.Data("Commit Comment");
52         if (CommentDialog.openCommentDialog(data))
53             ts.commit(data.comment, teamFolder, init);
54         return data;
55     }
56 }