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
;
34 public class ResetAction
extends RepositoryAction
{
36 public void execute(IAction action
) {
41 public void run(IAction action
) {
42 final Repository repository
= getRepository();
43 if (repository
== null)
46 BranchSelectionDialog branchSelectionDialog
= new BranchSelectionDialog(getShell(), repository
);
47 if (branchSelectionDialog
.open() == IDialogConstants
.OK_ID
) {
48 final String refName
= branchSelectionDialog
.getRefName();
49 final ResetType type
= branchSelectionDialog
.getResetType();
52 getTargetPart().getSite().getWorkbenchWindow().run(true, false,
53 new IRunnableWithProgress() {
54 public void run(final IProgressMonitor monitor
)
55 throws InvocationTargetException
{
57 new ResetOperation(repository
, refName
, type
).run(monitor
);
58 GitResourceDecorator
.refresh();
59 } catch (CoreException ce
) {
61 throw new InvocationTargetException(ce
);
65 } catch (InvocationTargetException e
) {
66 MessageDialog
.openError(getShell(),"Reset failed", e
.getMessage());
67 } catch (InterruptedException e
) {
68 MessageDialog
.openError(getShell(),"Reset failed", e
.getMessage());
75 public boolean isEnabled() {
76 return !getSelection().isEmpty();