aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2010-05-07 10:40:42 (EDT)
committerJens Baumgart2010-05-07 10:40:42 (EDT)
commit98079a73da8134b142f8da8108bcccfb572815e4 (patch)
tree9b2007596c8a284eafaea18e2dc892f85d2384e9
parent3d899a865d64b6323d011e94e15a9d67780e35f9 (diff)
downloadegit-98079a73da8134b142f8da8108bcccfb572815e4.zip
egit-98079a73da8134b142f8da8108bcccfb572815e4.tar.gz
egit-98079a73da8134b142f8da8108bcccfb572815e4.tar.bz2
Replace getWorkbenchWindow().run by using a Jobrefs/changes/64/664/3
ResetAction and Track now use a Job to execute the operation. Change-Id: Ifbad2a09d567a231461b2c33ff03868e1e1c7edc Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java12
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/TrackOperation.java28
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java48
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/Track.java44
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties2
6 files changed, 77 insertions, 63 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java
index b0dbda8..6328050 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java
@@ -18,6 +18,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.egit.core.CoreText;
import org.eclipse.egit.core.internal.util.ProjectUtil;
import org.eclipse.jgit.lib.Commit;
@@ -77,6 +78,17 @@ public class ResetOperation implements IEGitOperation {
this.type = type;
}
+ /**
+ * @return the rule needed to execute this operation
+ */
+ public ISchedulingRule getSchedulingRule() {
+ if (type == ResetType.HARD)
+ return ResourcesPlugin.getWorkspace().getRoot();
+ else
+ return null;
+ }
+
+
/* (non-Javadoc)
* @see org.eclipse.egit.core.op.IEGitOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
*/
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/TrackOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/TrackOperation.java
index 2c36428..5c58944 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/TrackOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/TrackOperation.java
@@ -12,7 +12,6 @@ package org.eclipse.egit.core.op;
import java.io.File;
import java.io.IOException;
-import java.util.Collection;
import java.util.IdentityHashMap;
import java.util.Iterator;
@@ -21,9 +20,10 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.CoreText;
import org.eclipse.egit.core.internal.trace.GitTraceLocation;
@@ -47,7 +47,7 @@ import org.eclipse.team.core.Team;
* </p>
*/
public class TrackOperation implements IEGitOperation {
- private final Collection rsrcList;
+ private final IResource[] rsrcList;
/**
* Create a new operation to track additional files/folders.
@@ -56,10 +56,18 @@ public class TrackOperation implements IEGitOperation {
* collection of {@link IResource}s which should be added to the
* relevant Git repositories.
*/
- public TrackOperation(final Collection rsrcs) {
+ public TrackOperation(IResource[] rsrcs) {
rsrcList = rsrcs;
}
+ /**
+ * @return the rule needed to execute this operation
+ */
+ public ISchedulingRule getSchedulingRule() {
+ return new MultiRule(rsrcList);
+ }
+
+
/* (non-Javadoc)
* @see org.eclipse.egit.core.op.IEGitOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
*/
@@ -69,17 +77,14 @@ public class TrackOperation implements IEGitOperation {
}
final IdentityHashMap<RepositoryMapping, Boolean> tomerge = new IdentityHashMap<RepositoryMapping, Boolean>();
- m.beginTask(CoreText.AddOperation_adding, rsrcList.size() * 200);
+ m.beginTask(CoreText.AddOperation_adding, rsrcList.length * 200);
try {
- for (Object obj : rsrcList) {
- obj = ((IAdaptable)obj).getAdapter(IResource.class);
- if (obj instanceof IResource) {
- final IResource toAdd = (IResource)obj;
+ for (IResource toAdd : rsrcList) {
final RepositoryMapping rm = RepositoryMapping.getMapping(toAdd);
final GitIndex index = rm.getRepository().getIndex();
- if (obj instanceof IFile) {
- String repoPath = rm.getRepoRelativePath((IResource) obj);
+ if (toAdd instanceof IFile) {
+ String repoPath = rm.getRepoRelativePath(toAdd);
Entry entry = index.getEntry(repoPath);
if (entry != null) {
if (!entry.isAssumedValid()) {
@@ -130,7 +135,6 @@ public class TrackOperation implements IEGitOperation {
entry.setAssumeValid(false);
}
- }
m.worked(200);
}
for (RepositoryMapping rm : tomerge.keySet()) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index 1c20907..226d0ce 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -730,6 +730,9 @@ public class UIText extends NLS {
public static String ResetAction_repositoryState;
/** */
+ public static String ResetAction_reset;
+
+ /** */
public static String ResetAction_resetFailed;
/** */
@@ -1540,6 +1543,9 @@ public class UIText extends NLS {
public static String IgnoreAction_error;
/** */
+ public static String Track_addToVersionControl;
+
+ /** */
public static String Track_error;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java
index abcee6d..be5955e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java
@@ -10,21 +10,20 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.actions;
-import java.lang.reflect.InvocationTargetException;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.ResetOperation;
import org.eclipse.egit.core.op.ResetOperation.ResetType;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator;
import org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog;
-import org.eclipse.egit.ui.internal.trace.GitTraceLocation;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.osgi.util.NLS;
@@ -40,40 +39,35 @@ public class ResetAction extends RepositoryAction {
final Repository repository = getRepository(true);
if (repository == null)
return;
-
if (!repository.getRepositoryState().canResetHead()) {
MessageDialog.openError(getShell(), UIText.ResetAction_errorResettingHead,
NLS.bind(UIText.ResetAction_repositoryState, repository.getRepositoryState().getDescription()));
return;
}
-
BranchSelectionDialog branchSelectionDialog = new BranchSelectionDialog(getShell(), repository, true);
if (branchSelectionDialog.open() == IDialogConstants.OK_ID) {
final String refName = branchSelectionDialog.getRefName();
final ResetType type = branchSelectionDialog.getResetType();
-
- try {
- getTargetPart().getSite().getWorkbenchWindow().run(true, false,
- new IRunnableWithProgress() {
- public void run(final IProgressMonitor monitor)
- throws InvocationTargetException {
- try {
- new ResetOperation(repository, refName, type).execute(monitor);
- GitLightweightDecorator.refresh();
- } catch (CoreException e) {
- if (GitTraceLocation.UI.isActive())
- GitTraceLocation.getTrace().trace(GitTraceLocation.UI.getLocation(), e.getMessage(), e);
- throw new InvocationTargetException(e);
- }
+ String jobname = NLS.bind(UIText.ResetAction_reset, refName);
+ final ResetOperation operation = new ResetOperation(repository,
+ refName, type);
+ Job job = new Job(jobname) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ operation.execute(monitor);
+ GitLightweightDecorator.refresh();
+ } catch (CoreException e) {
+ return Activator.createErrorStatus(e.getStatus()
+ .getMessage(), e);
}
- });
- } catch (InvocationTargetException e) {
- Activator.handleError(UIText.ResetAction_resetFailed, e, true);
- } catch (InterruptedException e) {
- Activator.handleError(UIText.ResetAction_resetFailed, e, true);
- }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(operation.getSchedulingRule());
+ job.setUser(true);
+ job.schedule();
}
-
}
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/Track.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/Track.java
index a68e354..0d5eb66 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/Track.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/Track.java
@@ -9,17 +9,16 @@
*******************************************************************************/
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.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.TrackOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.operation.IRunnableWithProgress;
/**
* An action to add resources to the Git repository.
@@ -30,26 +29,23 @@ public class Track extends RepositoryAction {
@Override
public void execute(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.execute(arg0);
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator.handleError(UIText.Track_error, e, true);
- } catch (InterruptedException e) {
- Activator.handleError(UIText.Track_error, e, true);
- }
+ final TrackOperation op = new TrackOperation(getSelectedResources());
+ String jobname = UIText.Track_addToVersionControl;
+ Job job = new Job(jobname) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ op.execute(monitor);
+ } catch (CoreException e) {
+ return Activator.createErrorStatus(e.getStatus()
+ .getMessage(), e);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(op.getSchedulingRule());
+ job.setUser(true);
+ job.schedule();
}
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 2f1cdda..15ade30 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -258,6 +258,7 @@ QuickdiffBaselineOperation_baseline=Cannot set quickdiff baseline
ResetAction_errorResettingHead=Cannot reset HEAD now
ResetAction_repositoryState=Repository state: {0}
+ResetAction_reset=Resetting to {0}
ResetAction_resetFailed=Reset failed
ResourceHistory_toggleCommentWrap=Wrap Comments
ResourceHistory_toggleCommentFill=Fill paragraphs
@@ -552,6 +553,7 @@ Decorator_exceptionMessage=Errors occurred while applying Git decorations to res
IgnoreAction_jobName=Ignore Git resources
IgnoreAction_taskName=Ignoring Git resources
IgnoreAction_error=Unable to ignore resources
+Track_addToVersionControl=Add to Version Control
Track_error=Add to Version Control failed
Track_see_log=See error log for details.