1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*******************************************************************************
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.egit.ui.internal.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.core.op.TrackOperation;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
/**
* An action to add resources to the Git repository.
*
* @see TrackOperation
*/
public class Track extends RepositoryAction {
@Override
public void run(IAction action) {
try {
final TrackOperation op = new TrackOperation(Arrays
.asList(getSelectedResources()));
getTargetPart().getSite().getWorkbenchWindow().run(true, false,
new IRunnableWithProgress() {
public void run(IProgressMonitor arg0)
throws InvocationTargetException,
InterruptedException {
try {
op.run(arg0);
} catch (CoreException e) {
MessageDialog.openError(getShell(),
"Track failed", e.getMessage());
}
}
});
} catch (InvocationTargetException e) {
MessageDialog.openError(getShell(), "Track failed", e.getMessage());
} catch (InterruptedException e) {
MessageDialog.openError(getShell(), "Track failed", e.getMessage());
}
}
@Override
public boolean isEnabled() {
return getSelectedAdaptables(getSelection(), IResource.class).length > 0;
}
}
|