Remove trailing whitespace across EGit
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / actions / ResetAction.java
blob1245b140a1716e6f9f2f44c80502aa44a09b8775
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 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *******************************************************************************/
11 package org.eclipse.egit.ui.internal.actions;
13 import java.lang.reflect.InvocationTargetException;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.egit.core.op.ResetOperation;
18 import org.eclipse.egit.core.op.ResetOperation.ResetType;
19 import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator;
20 import org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.dialogs.IDialogConstants;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.jface.operation.IRunnableWithProgress;
25 import org.eclipse.jgit.lib.Repository;
27 /**
28 * An action to reset the current branch to a specific revision.
30 * @see ResetOperation
32 public class ResetAction extends RepositoryAction {
34 @Override
35 public void run(IAction action) {
36 final Repository repository = getRepository(true);
37 if (repository == null)
38 return;
40 if (!repository.getRepositoryState().canResetHead()) {
41 MessageDialog.openError(getShell(), "Cannot reset HEAD now",
42 "Repository state:"
43 + repository.getRepositoryState().getDescription());
44 return;
47 BranchSelectionDialog branchSelectionDialog = new BranchSelectionDialog(getShell(), repository);
48 if (branchSelectionDialog.open() == IDialogConstants.OK_ID) {
49 final String refName = branchSelectionDialog.getRefName();
50 final ResetType type = branchSelectionDialog.getResetType();
52 try {
53 getTargetPart().getSite().getWorkbenchWindow().run(true, false,
54 new IRunnableWithProgress() {
55 public void run(final IProgressMonitor monitor)
56 throws InvocationTargetException {
57 try {
58 new ResetOperation(repository, refName, type).run(monitor);
59 GitLightweightDecorator.refresh();
60 } catch (CoreException ce) {
61 ce.printStackTrace();
62 throw new InvocationTargetException(ce);
65 });
66 } catch (InvocationTargetException e) {
67 MessageDialog.openError(getShell(),"Reset failed", e.getMessage());
68 } catch (InterruptedException e) {
69 MessageDialog.openError(getShell(),"Reset failed", e.getMessage());
75 @Override
76 public boolean isEnabled() {
77 return getRepository(false) != null;