Add a Track toolbar icon for adding resources
[egit/zawir.git] / org.spearce.egit.ui / src / org / spearce / egit / ui / internal / actions / Track.java
blobe4de70c1438a7bc30c7b0a9a2d3b46d31f2d535b
1 /*******************************************************************************
2 * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * See LICENSE for the full license text, also available.
8 *******************************************************************************/
9 package org.spearce.egit.ui.internal.actions;
11 import java.lang.reflect.InvocationTargetException;
12 import java.util.Arrays;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.dialogs.MessageDialog;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.spearce.egit.core.op.TrackOperation;
22 /**
23 * An action to add resources to the Git repository.
25 * @see TrackOperation
27 public class Track extends RepositoryAction {
29 @Override
30 public void run(IAction action) {
31 try {
32 final TrackOperation op = new TrackOperation(Arrays
33 .asList(getSelectedResources()));
34 getTargetPart().getSite().getWorkbenchWindow().run(true, false,
35 new IRunnableWithProgress() {
36 public void run(IProgressMonitor arg0)
37 throws InvocationTargetException,
38 InterruptedException {
39 try {
40 op.run(arg0);
41 } catch (CoreException e) {
42 MessageDialog.openError(getShell(),
43 "Track failed", e.getMessage());
46 });
47 } catch (InvocationTargetException e) {
48 MessageDialog.openError(getShell(), "Track failed", e.getMessage());
49 } catch (InterruptedException e) {
50 MessageDialog.openError(getShell(), "Track failed", e.getMessage());
54 @Override
55 public boolean isEnabled() {
56 return getSelectedAdaptables(getSelection(), IResource.class).length > 0;