2 * Copyright (C) 2007 Dave Watson <dwatson@mimvista.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 package org
.spearce
.egit
.ui
.internal
.actions
;
20 import java
.lang
.reflect
.InvocationTargetException
;
22 import org
.eclipse
.core
.runtime
.CoreException
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.jface
.action
.IAction
;
25 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
26 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
27 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
28 import org
.spearce
.egit
.core
.op
.ResetOperation
;
29 import org
.spearce
.egit
.core
.op
.ResetOperation
.ResetType
;
30 import org
.spearce
.egit
.ui
.internal
.decorators
.GitResourceDecorator
;
31 import org
.spearce
.egit
.ui
.internal
.dialogs
.BranchSelectionDialog
;
32 import org
.spearce
.jgit
.lib
.Repository
;
35 * An acton to reset the current branch to a specific revision.
39 public class ResetAction
extends RepositoryAction
{
42 public void run(IAction action
) {
43 final Repository repository
= getRepository();
44 if (repository
== null)
47 if (!repository
.getRepositoryState().canResetHead()) {
48 MessageDialog
.openError(getShell(), "Cannot reset HEAD now",
50 + repository
.getRepositoryState().getDescription());
54 BranchSelectionDialog branchSelectionDialog
= new BranchSelectionDialog(getShell(), repository
);
55 if (branchSelectionDialog
.open() == IDialogConstants
.OK_ID
) {
56 final String refName
= branchSelectionDialog
.getRefName();
57 final ResetType type
= branchSelectionDialog
.getResetType();
60 getTargetPart().getSite().getWorkbenchWindow().run(true, false,
61 new IRunnableWithProgress() {
62 public void run(final IProgressMonitor monitor
)
63 throws InvocationTargetException
{
65 new ResetOperation(repository
, refName
, type
).run(monitor
);
66 GitResourceDecorator
.refresh();
67 } catch (CoreException ce
) {
69 throw new InvocationTargetException(ce
);
73 } catch (InvocationTargetException e
) {
74 MessageDialog
.openError(getShell(),"Reset failed", e
.getMessage());
75 } catch (InterruptedException e
) {
76 MessageDialog
.openError(getShell(),"Reset failed", e
.getMessage());
83 public boolean isEnabled() {
84 return !getSelection().isEmpty();