From ec8730ff1167c5a607274e51f9b7b41a87dc2a4b Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 29 Apr 2009 20:05:28 +0000 Subject: [PATCH] [274414] Use a Job to prevent locking the UI --- .../gdb/launching/FinalLaunchSequence.java | 126 +++++++++++------- 1 file changed, 77 insertions(+), 49 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java index 8f4a451cd7f..e02e42f89e0 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java @@ -49,6 +49,7 @@ import org.eclipse.core.runtime.IPath; 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.debug.core.DebugPlugin; import org.eclipse.debug.core.IStatusHandler; @@ -306,57 +307,84 @@ public class FinalLaunchSequence extends Sequence { * Specify the core file to be debugged if we are launching such a debug session. */ new Step() { - private String promptForCoreFilePath() throws CoreException { - IStatus promptStatus = new Status(IStatus.INFO, "org.eclipse.debug.ui", 200/*STATUS_HANDLER_PROMPT*/, "", null); //$NON-NLS-1$//$NON-NLS-2$ - IStatus filePrompt = new Status(IStatus.INFO, "org.eclipse.cdt.dsf.gdb.ui", 1001, "", null); //$NON-NLS-1$//$NON-NLS-2$ - // consult a status handler - IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(promptStatus); - if (prompter != null) { - Object result = prompter.handleStatus(filePrompt, null); - if (result instanceof String) { - return (String)result; - } - } - return null; - } - @Override - public void execute(final RequestMonitor requestMonitor) { - if (fSessionType == SessionType.CORE) { - Exception exception = null; - String coreFile; - try { - coreFile = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, ""); //$NON-NLS-1$ + // Need a job because prompter.handleStatus will block + class PromptForCoreJob extends Job { + DataRequestMonitor fRequestMonitor; - if (coreFile != null) { - if (coreFile.length() == 0) { - coreFile = promptForCoreFilePath(); - if (coreFile == null || coreFile.length()== 0) { - requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get core file path", exception)); //$NON-NLS-1$ - requestMonitor.done(); - return; - } - } - - fCommandControl.queueCommand( - new MITargetSelectCore(fCommandControl.getContext(), coreFile), - new DataRequestMonitor(getExecutor(), requestMonitor) { - @Override - protected void handleSuccess() { - requestMonitor.done(); - } - }); - return; - } - } catch (CoreException e) { - exception = e; - } + public PromptForCoreJob(String name, DataRequestMonitor rm) { + super(name); + fRequestMonitor = rm; + } - requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get core file path", exception)); //$NON-NLS-1$ - requestMonitor.done(); - } else { - requestMonitor.done(); - } - }}, + @Override + protected IStatus run(IProgressMonitor monitor) { + final IStatus promptStatus = new Status(IStatus.INFO, "org.eclipse.debug.ui", 200/*STATUS_HANDLER_PROMPT*/, "", null); //$NON-NLS-1$//$NON-NLS-2$ + final IStatus filePrompt = new Status(IStatus.INFO, "org.eclipse.cdt.dsf.gdb.ui", 1001, "", null); //$NON-NLS-1$//$NON-NLS-2$ + // consult a status handler + final IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(promptStatus); + + final Status NO_CORE_STATUS = new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, + LaunchMessages.getString("LocalCDILaunchDelegate.6"), //$NON-NLS-1$ + null); + + if (prompter == null) { + fRequestMonitor.setStatus(NO_CORE_STATUS); + fRequestMonitor.done(); + return Status.OK_STATUS; + } + + try { + Object result = prompter.handleStatus(filePrompt, null); + if (result instanceof String) { + fRequestMonitor.setData((String)result); + } else { + fRequestMonitor.setStatus(NO_CORE_STATUS); + } + } catch (CoreException e) { + fRequestMonitor.setStatus(NO_CORE_STATUS); + } + fRequestMonitor.done(); + + return Status.OK_STATUS; + } + }; + @Override + public void execute(final RequestMonitor requestMonitor) { + if (fSessionType == SessionType.CORE) { + try { + String coreFile = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, ""); //$NON-NLS-1$ + + if (coreFile.length() == 0) { + new PromptForCoreJob( + "Prompt for core file", //$NON-NLS-1$ + new DataRequestMonitor(getExecutor(), requestMonitor) { + @Override + protected void handleSuccess() { + String newCoreFile = getData(); + if (newCoreFile == null || newCoreFile.length()== 0) { + requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get core file path", null)); //$NON-NLS-1$ + requestMonitor.done(); + } else { + fCommandControl.queueCommand( + new MITargetSelectCore(fCommandControl.getContext(), newCoreFile), + new DataRequestMonitor(getExecutor(), requestMonitor)); + } + } + }).schedule(); + } else { + fCommandControl.queueCommand( + new MITargetSelectCore(fCommandControl.getContext(), coreFile), + new DataRequestMonitor(getExecutor(), requestMonitor)); + } + } catch (CoreException e) { + requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get core file path", e)); //$NON-NLS-1$ + requestMonitor.done(); + } + } else { + requestMonitor.done(); + } + } + }, /* * If remote debugging, connect to target. */