Fix a typo.
[egit/zawir.git] / org.spearce.egit.ui / src / org / spearce / egit / ui / internal / actions / ResetAction.java
blob7ca48af91cf1cc90b704ca53e0912b049dd3703e
1 /*******************************************************************************
2 * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
3 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
4 * Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org>
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * See LICENSE for the full license text, also available.
9 *******************************************************************************/
10 package org.spearce.egit.ui.internal.actions;
12 import java.lang.reflect.InvocationTargetException;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.jface.dialogs.MessageDialog;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.spearce.egit.core.op.ResetOperation;
21 import org.spearce.egit.core.op.ResetOperation.ResetType;
22 import org.spearce.egit.ui.internal.decorators.GitResourceDecorator;
23 import org.spearce.egit.ui.internal.dialogs.BranchSelectionDialog;
24 import org.spearce.jgit.lib.Repository;
26 /**
27 * An action to reset the current branch to a specific revision.
29 * @see ResetOperation
31 public class ResetAction extends RepositoryAction {
33 @Override
34 public void run(IAction action) {
35 final Repository repository = getRepository(true);
36 if (repository == null)
37 return;
39 if (!repository.getRepositoryState().canResetHead()) {
40 MessageDialog.openError(getShell(), "Cannot reset HEAD now",
41 "Respository state:"
42 + repository.getRepositoryState().getDescription());
43 return;
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();
51 try {
52 getTargetPart().getSite().getWorkbenchWindow().run(true, false,
53 new IRunnableWithProgress() {
54 public void run(final IProgressMonitor monitor)
55 throws InvocationTargetException {
56 try {
57 new ResetOperation(repository, refName, type).run(monitor);
58 GitResourceDecorator.refresh();
59 } catch (CoreException ce) {
60 ce.printStackTrace();
61 throw new InvocationTargetException(ce);
64 });
65 } catch (InvocationTargetException e) {
66 MessageDialog.openError(getShell(),"Reset failed", e.getMessage());
67 } catch (InterruptedException e) {
68 MessageDialog.openError(getShell(),"Reset failed", e.getMessage());
74 @Override
75 public boolean isEnabled() {
76 return getRepository(false) != null;