1 /*******************************************************************************
2 * Copyright (C) 2010, Roland Grunberg <rgrunber@redhat.com>
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 package org
.eclipse
.egit
.ui
.internal
.actions
;
11 import org
.eclipse
.core
.resources
.IProject
;
12 import org
.eclipse
.core
.resources
.IResource
;
13 import org
.eclipse
.core
.runtime
.CoreException
;
14 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
17 import org
.eclipse
.core
.runtime
.jobs
.Job
;
18 import org
.eclipse
.egit
.core
.op
.DiscardChangesOperation
;
19 import org
.eclipse
.egit
.ui
.Activator
;
20 import org
.eclipse
.egit
.ui
.UIText
;
21 import org
.eclipse
.jface
.action
.IAction
;
22 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
23 import org
.eclipse
.jgit
.lib
.Repository
;
24 import org
.eclipse
.jgit
.lib
.RepositoryState
;
27 * Checkout all selected dirty files.
29 public class DiscardChangesAction
extends RepositoryAction
{
32 public void execute(IAction action
) {
34 boolean performAction
= MessageDialog
.openConfirm(getShell(),
35 UIText
.DiscardChangesAction_confirmActionTitle
,
36 UIText
.DiscardChangesAction_confirmActionMessage
);
39 final DiscardChangesOperation operation
= new DiscardChangesOperation(
40 getSelectedResources());
41 String jobname
= UIText
.DiscardChangesAction_discardChanges
;
42 Job job
= new Job(jobname
) {
44 protected IStatus
run(IProgressMonitor monitor
) {
46 operation
.execute(monitor
);
47 } catch (CoreException e
) {
48 return Activator
.createErrorStatus(e
.getStatus()
51 return Status
.OK_STATUS
;
55 job
.setRule(operation
.getSchedulingRule());
60 public boolean isEnabled() {
61 for (IResource res
: getSelectedResources()) {
62 IProject
[] proj
= new IProject
[] { res
.getProject() };
63 Repository repository
= getRepositoriesFor(proj
)[0];
64 if (!repository
.getRepositoryState().equals(RepositoryState
.SAFE
)) {