Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-03-13 23:03:22 +0000
committerMatthias Sohn2013-03-24 00:35:52 +0000
commit7b9d64e73729490c37057fb1697c00cc71d09786 (patch)
tree3363651b0757a956a8723e8d55d696b69b1e161b /org.eclipse.egit.ui
parentd5d2e285998c16a97aff971761f663126b785828 (diff)
downloadegit-7b9d64e73729490c37057fb1697c00cc71d09786.tar.gz
egit-7b9d64e73729490c37057fb1697c00cc71d09786.tar.xz
egit-7b9d64e73729490c37057fb1697c00cc71d09786.zip
Fetch from Gerrit should allow to be run in background
Bug: 402633 Change-Id: Ic01a8ccb7569ae1d5f473eeb3034ce46e060c536 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java154
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties5
3 files changed, 116 insertions, 46 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index fd0a0ad83d..89e01a4d10 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -2559,6 +2559,9 @@ public class UIText extends NLS {
public static String FetchGerritChangePage_ProvideRefNameMessage;
/** */
+ public static String FetchGerritChangePage_RunInBackground;
+
+ /** */
public static String FetchGerritChangePage_SuggestedRefNamePattern;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
index 4daa917eda..0ccf76a29e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
@@ -25,10 +25,13 @@ import java.util.regex.PatternSyntaxException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.CreateLocalBranchOperation;
import org.eclipse.egit.core.op.ListRemoteOperation;
import org.eclipse.egit.core.op.TagOperation;
import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.UIUtils;
import org.eclipse.egit.ui.internal.UIText;
@@ -79,6 +82,7 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
/**
* Fetch a change from Gerrit
@@ -88,6 +92,8 @@ public class FetchGerritChangePage extends WizardPage {
private static final String LAST_URI_POSTFIX = ".lastUri"; //$NON-NLS-1$
+ private static final String RUN_IN_BACKGROUND = "runInBackground"; //$NON-NLS-1$
+
private final Repository repository;
private final IDialogSettings settings;
@@ -122,6 +128,8 @@ public class FetchGerritChangePage extends WizardPage {
private Button activateAdditionalRefs;
+ private Button runInBackgroud;
+
/**
* @param repository
* @param refName initial value for the ref field
@@ -187,7 +195,7 @@ public class FetchGerritChangePage extends WizardPage {
Group checkoutGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
checkoutGroup.setLayout(new GridLayout(2, false));
- GridDataFactory.fillDefaults().span(2, 1).grab(true, true)
+ GridDataFactory.fillDefaults().span(2, 1).grab(true, false)
.applyTo(checkoutGroup);
checkoutGroup.setText(UIText.FetchGerritChangePage_AfterFetchGroup);
@@ -295,6 +303,12 @@ public class FetchGerritChangePage extends WizardPage {
}
});
+ runInBackgroud = new Button(main, SWT.CHECK);
+ GridDataFactory.fillDefaults().span(2, 1).align(SWT.BEGINNING, SWT.END)
+ .grab(true, true)
+ .applyTo(runInBackgroud);
+ runInBackgroud.setText(UIText.FetchGerritChangePage_RunInBackground);
+
// get all available URIs from the repository
SortedSet<String> uris = new TreeSet<String>();
try {
@@ -316,13 +330,13 @@ public class FetchGerritChangePage extends WizardPage {
uriCombo.setText(defaultUri);
else
selectLastUsedUri();
+ restoreRunInBackgroundSelection();
refText.setFocus();
Dialog.applyDialogFont(main);
setControl(main);
checkPage();
}
-
private void storeLastUsedUri(String uri) {
settings.put(lastUriKey, uri.trim());
}
@@ -339,6 +353,14 @@ public class FetchGerritChangePage extends WizardPage {
uriCombo.select(0);
}
+ private void storeRunInBackgroundSelection() {
+ settings.put(RUN_IN_BACKGROUND, runInBackgroud.getSelection());
+ }
+
+ private void restoreRunInBackgroundSelection() {
+ runInBackgroud.setSelection(settings.getBoolean(RUN_IN_BACKGROUND));
+ }
+
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
@@ -469,49 +491,52 @@ public class FetchGerritChangePage extends WizardPage {
}
boolean doFetch() {
- try {
- final RefSpec spec = new RefSpec().setSource(refText.getText())
- .setDestination(Constants.FETCH_HEAD);
- final String uri = uriCombo.getText();
- final boolean doCheckout = checkout.getSelection();
- final boolean doCreateTag = createTag.getSelection();
- final boolean doCreateBranch = createBranch.getSelection();
- final boolean doActivateAdditionalRefs = (checkout.getSelection() || dontCheckout
- .getSelection()) && activateAdditionalRefs.getSelection();
- final String textForTag = tagText.getText();
- final String textForBranch = branchText.getText();
+ final RefSpec spec = new RefSpec().setSource(refText.getText())
+ .setDestination(Constants.FETCH_HEAD);
+ final String uri = uriCombo.getText();
+ final boolean doCheckout = checkout.getSelection();
+ final boolean doCreateTag = createTag.getSelection();
+ final boolean doCreateBranch = createBranch.getSelection();
+ final boolean doActivateAdditionalRefs = (checkout.getSelection() || dontCheckout
+ .getSelection()) && activateAdditionalRefs.getSelection();
+ final String textForTag = tagText.getText();
+ final String textForBranch = branchText.getText();
+
+ storeRunInBackgroundSelection();
+
+ if (runInBackgroud.getSelection()) {
+ Job job = new Job(UIText.FetchGerritChangePage_GetChangeTaskName) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ internalDoFetch(spec, uri, doCheckout, doCreateTag,
+ doCreateBranch, doActivateAdditionalRefs,
+ textForTag, textForBranch, monitor);
+ return org.eclipse.core.runtime.Status.OK_STATUS;
+ }
+
+ @Override
+ public boolean belongsTo(Object family) {
+ if (JobFamilies.FETCH.equals(family))
+ return true;
+ return super.belongsTo(family);
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+ return true;
+ } else {
+ try {
getWizard().getContainer().run(true, true,
new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException,
InterruptedException {
- int totalWork = 1;
- if (doCheckout)
- totalWork++;
- if (doCreateTag || doCreateBranch)
- totalWork++;
- monitor.beginTask(
- UIText.FetchGerritChangePage_GetChangeTaskName,
- totalWork);
-
try {
- RevCommit commit = fetchChange(uri, spec,
- monitor);
-
- if (doCreateTag) {
- createTag(spec, textForTag, commit, monitor);
- }
- if (doCreateBranch) {
- createBranch(textForBranch, commit, monitor);
- }
- if (doCheckout || doCreateTag) {
- checkout(commit, monitor);
- }
- if (doActivateAdditionalRefs) {
- activateAdditionalRefs();
- }
- storeLastUsedUri(uri);
+ internalDoFetch(spec, uri, doCheckout,
+ doCreateTag, doCreateBranch,
+ doActivateAdditionalRefs, textForTag,
+ textForBranch, monitor);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
@@ -521,14 +546,55 @@ public class FetchGerritChangePage extends WizardPage {
}
}
});
- } catch (InvocationTargetException e) {
+ } catch (InvocationTargetException e) {
+ Activator.handleError(e.getCause().getMessage(), e.getCause(),
+ true);
+ return false;
+ } catch (InterruptedException e) {
+ // just return
+ }
+ return true;
+ }
+ }
+
+ private void internalDoFetch(RefSpec spec, String uri, boolean doCheckout,
+ boolean doCreateTag, boolean doCreateBranch,
+ boolean doActivateAdditionalRefs, String textForTag,
+ String textForBranch, IProgressMonitor monitor) {
+
+ int totalWork = 1;
+ if (doCheckout)
+ totalWork++;
+ if (doCreateTag || doCreateBranch)
+ totalWork++;
+ monitor.beginTask(
+ UIText.FetchGerritChangePage_GetChangeTaskName,
+ totalWork);
+
+ try {
+ RevCommit commit = fetchChange(uri, spec,
+ monitor);
+
+ if (doCreateTag)
+ createTag(spec, textForTag, commit, monitor);
+
+ if (doCreateBranch)
+ createBranch(textForBranch, commit, monitor);
+
+ if (doCheckout || doCreateTag)
+ checkout(commit, monitor);
+
+ if (doActivateAdditionalRefs)
+ activateAdditionalRefs();
+
+ storeLastUsedUri(uri);
+
+ } catch (Exception e) {
Activator
.handleError(e.getCause().getMessage(), e.getCause(), true);
- return false;
- } catch (InterruptedException e) {
- // just return
+ } finally {
+ monitor.done();
}
- return true;
}
private RevCommit fetchChange(String uri, RefSpec spec,
@@ -605,7 +671,7 @@ public class FetchGerritChangePage extends WizardPage {
private void activateAdditionalRefs() {
// do this in the UI thread as it results in a
// refresh() on the history page
- getContainer().getShell().getDisplay().asyncExec(new Runnable() {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
Activator
.getDefault()
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 8d24014ebe..54271d6488 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
@@ -833,7 +833,7 @@ FetchDestinationPage_TrackingBranchNotFoundMessage=Remote tracking branch ''{0}'
FetchGerritChangePage_ActivateAdditionalRefsButton=Make FETCH_HEAD visible in &History View
FetchGerritChangePage_ActivateAdditionalRefsTooltip=The History View is currently configured not to show FETCH_HEAD; if you check this, the History View settings will be changed so that FETCH_HEAD becomes visible
FetchGerritChangePage_AfterFetchGroup=Action to perform after fetch
-FetchGerritChangePage_BranchNameText=Branch &name
+FetchGerritChangePage_BranchNameText=Branch &name:
FetchGerritChangePage_ChangeLabel=&Change:
FetchGerritChangePage_CheckingOutTaskName=Checking out change
FetchGerritChangePage_CheckoutRadio=Check&out FETCH_HEAD
@@ -850,8 +850,9 @@ FetchGerritChangePage_MissingChangeMessage=Please provide a change
FetchGerritChangePage_PageMessage=Please select a Gerrit URI and change to fetch
FetchGerritChangePage_PageTitle=Fetch a change from Gerrit into repository {0}
FetchGerritChangePage_ProvideRefNameMessage=Please provide a name for the new branch or tag
+FetchGerritChangePage_RunInBackground=&Run in background
FetchGerritChangePage_SuggestedRefNamePattern=change/{0}/{1}
-FetchGerritChangePage_TagNameText=Tag &name
+FetchGerritChangePage_TagNameText=Tag &name:
FetchGerritChangePage_TagRadio=Create and checkout a &tag
FetchGerritChangePage_UpdateRadio=U&pdate FETCH_HEAD only
FetchGerritChangePage_UriLabel=&URI:

Back to the top