diff options
author | Matthias Sohn | 2014-12-10 14:09:30 +0000 |
---|---|---|
committer | Matthias Sohn | 2014-12-22 00:07:55 +0000 |
commit | 66f0b0881138a2f2740eb89c12c6cec26c6b1915 (patch) | |
tree | ec5ae976b372c1f4f42a661664bd4d881006f9ad | |
parent | 41cf113807d67aa2efa4e566699d975ccbfb5776 (diff) | |
download | egit-66f0b0881138a2f2740eb89c12c6cec26c6b1915.tar.gz egit-66f0b0881138a2f2740eb89c12c6cec26c6b1915.tar.xz egit-66f0b0881138a2f2740eb89c12c6cec26c6b1915.zip |
Search running launch configuration in ModalContext
Searching running launch configuration can otherwise freeze the UI
thread.
Bug: 452388
Change-Id: I6edec2ae9d7d3069ee0549e4082fdcf8e1757ace
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
3 files changed, 55 insertions, 22 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 5b991ac005..5696e3d464 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 @@ -3028,6 +3028,9 @@ public class UIText extends NLS { public static String BranchOperationUI_RunningLaunchTitle; /** */ + public static String BranchOperationUI_SearchLaunchConfiguration; + + /** */ public static String BranchRenameDialog_Message; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java index 1f1d030e3a..57338506a6 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java @@ -12,6 +12,7 @@ package org.eclipse.egit.ui.internal.branch; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -24,6 +25,7 @@ import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; @@ -55,6 +57,8 @@ import org.eclipse.egit.ui.internal.repository.CreateBranchWizard; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.operation.ModalContext; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; @@ -64,6 +68,7 @@ import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IMemento; import org.eclipse.ui.PlatformUI; @@ -225,7 +230,7 @@ public class BranchOperationUI { return; } - if (shouldCancelBecauseOfRunningLaunches()) + if (shouldCancelBecauseOfRunningLaunches(new NullProgressMonitor())) return; askForTargetIfNecessary(); @@ -334,7 +339,7 @@ public class BranchOperationUI { return; } - if (shouldCancelBecauseOfRunningLaunches()) + if (shouldCancelBecauseOfRunningLaunches(monitor)) return; askForTargetIfNecessary(); @@ -529,7 +534,8 @@ public class BranchOperationUI { }); } - private boolean shouldCancelBecauseOfRunningLaunches() { + private boolean shouldCancelBecauseOfRunningLaunches( + IProgressMonitor monitor) { if (mode == MODE_CHECKOUT) return false; if (!showQuestionsBeforeCheckout) @@ -539,7 +545,7 @@ public class BranchOperationUI { .getBoolean(UIPreferences.SHOW_RUNNING_LAUNCH_ON_CHECKOUT_WARNING)) return false; - final ILaunchConfiguration launchConfiguration = getRunningLaunchConfiguration(); + final ILaunchConfiguration launchConfiguration = getRunningLaunchConfiguration(monitor); if (launchConfiguration != null) { final boolean[] dialogResult = new boolean[1]; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @@ -576,25 +582,48 @@ public class BranchOperationUI { return false; } - private ILaunchConfiguration getRunningLaunchConfiguration() { - Set<IProject> projects = new HashSet<IProject>( - Arrays.asList(ProjectUtil.getProjects(repository))); - - ILaunchManager launchManager = DebugPlugin.getDefault() - .getLaunchManager(); - ILaunch[] launches = launchManager.getLaunches(); - for (ILaunch launch : launches) { - if (launch.isTerminated()) - continue; - ISourceLocator locator = launch.getSourceLocator(); - if (locator instanceof ISourceLookupDirector) { - ISourceLookupDirector director = (ISourceLookupDirector) locator; - ISourceContainer[] containers = director.getSourceContainers(); - if (isAnyProjectInSourceContainers(containers, projects)) - return launch.getLaunchConfiguration(); - } + private ILaunchConfiguration getRunningLaunchConfiguration( + IProgressMonitor monitor) { + final ILaunchConfiguration[] lc = new ILaunchConfiguration[1]; + try { + ModalContext.run(new IRunnableWithProgress() { + + public void run(IProgressMonitor m) + throws InvocationTargetException, InterruptedException { + + Set<IProject> projects = new HashSet<IProject>(Arrays + .asList(ProjectUtil.getProjects(repository))); + + ILaunchManager launchManager = DebugPlugin.getDefault() + .getLaunchManager(); + ILaunch[] launches = launchManager.getLaunches(); + m.beginTask( + UIText.BranchOperationUI_SearchLaunchConfiguration, + launches.length); + for (ILaunch launch : launches) { + m.worked(1); + if (launch.isTerminated()) + continue; + ISourceLocator locator = launch.getSourceLocator(); + if (locator instanceof ISourceLookupDirector) { + ISourceLookupDirector director = (ISourceLookupDirector) locator; + ISourceContainer[] containers = director + .getSourceContainers(); + if (isAnyProjectInSourceContainers(containers, + projects)) { + lc[0] = launch.getLaunchConfiguration(); + return; + } + } + } + } + }, true, monitor, Display.getDefault()); + } catch (InvocationTargetException e) { + // ignore + } catch (InterruptedException e) { + // ignore } - return null; + return lc[0]; } private boolean isAnyProjectInSourceContainers( diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties index e928f1515e..4a09b2ce47 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties @@ -1036,6 +1036,7 @@ BranchOperationUI_DetachedHeadMessage=You are in the 'detached HEAD' state. This BranchOperationUI_RunningLaunchDontShowAgain=Don't show this warning again BranchOperationUI_RunningLaunchMessage=The launch configuration ''{0}'' is currently running and uses a project of this repository. Continue branch switch? BranchOperationUI_RunningLaunchTitle=Running Launch +BranchOperationUI_SearchLaunchConfiguration=Search running launch configuration BranchRenameDialog_Message=Please enter a new name for branch {0} BranchRenameDialog_NewNameLabel=New Branch &name: BranchRenameDialog_RenameExceptionMessage=Could not rename branch |