diff options
author | Darin Wright | 2002-11-06 03:57:57 +0000 |
---|---|---|
committer | Darin Wright | 2002-11-06 03:57:57 +0000 |
commit | 1b850bbd976895fa1741552ceb7fccfa75198504 (patch) | |
tree | 31bfa4c898bdd518dab47135322d912e62075990 /org.eclipse.ui.externaltools | |
parent | 37d874f62c8124cb200d386e251f361e65b9967c (diff) | |
download | eclipse.platform.debug-1b850bbd976895fa1741552ceb7fccfa75198504.tar.gz eclipse.platform.debug-1b850bbd976895fa1741552ceb7fccfa75198504.tar.xz eclipse.platform.debug-1b850bbd976895fa1741552ceb7fccfa75198504.zip |
resource refresh
Diffstat (limited to 'org.eclipse.ui.externaltools')
2 files changed, 128 insertions, 1 deletions
diff --git a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/BackgroundResourceRefresher.java b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/BackgroundResourceRefresher.java new file mode 100644 index 000000000..a6612f017 --- /dev/null +++ b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/BackgroundResourceRefresher.java @@ -0,0 +1,105 @@ +package org.eclipse.ui.externaltools.internal.program.launchConfigurations; + +/********************************************************************** +Copyright (c) 2002 IBM Corp. and others. All rights reserved. +This file is made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: +**********************************************************************/ + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin; +import org.eclipse.ui.externaltools.launchConfigurations.ExternalToolsUtil; +import org.eclipse.ui.externaltools.variable.ExpandVariableContext; + +/** + * Refreshes resources as specified by a lanunch configuration, when + * an associated process terminates. + */ +public class BackgroundResourceRefresher implements IDebugEventSetListener, Runnable, IRunnableWithProgress { + + private ExpandVariableContext fContext; + private ILaunchConfiguration fConfiguration; + private IProcess fProcess; + + public BackgroundResourceRefresher(ILaunchConfiguration configuration, IProcess process, ExpandVariableContext context) { + fConfiguration = configuration; + fProcess = process; + fContext = context; + } + + /** + * If the process has already terminated, resource refreshing is done + * immediately in the current thread. Otherwise, refreshing is done when the + * process terminates. + */ + public void startBackgroundRefresh() { + synchronized (fProcess) { + if (fProcess.isTerminated()) { + refresh(); + } else { + DebugPlugin.getDefault().addDebugEventListener(this); + } + } + } + + /** + * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent) + */ + public void handleDebugEvents(DebugEvent[] events) { + for (int i = 0; i < events.length; i++) { + DebugEvent event = events[i]; + if (event.getSource() == fProcess && event.getKind() == DebugEvent.TERMINATE) { + DebugPlugin.getDefault().removeDebugEventListener(this); + refresh(); + break; + } + } + } + + /** + * Submits a runnable to do the refresh + */ + protected void refresh() { + ExternalToolsPlugin.getStandardDisplay().asyncExec(this); + } + + /** + * Creates a dialog to run the refresh + * + * @see java.lang.Runnable#run()
*/ + public void run() { + ProgressMonitorDialog dialog = new ProgressMonitorDialog(ExternalToolsPlugin.getStandardDisplay().getActiveShell()); + try { + dialog.run(true, true, this); + } catch (InvocationTargetException e) { + // report the exception + } catch (InterruptedException e) { + } + } + /** + * Peforms the refresh + * + * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) + */ + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + ExternalToolsUtil.refreshResources(fConfiguration, fContext, monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + +} diff --git a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java index e92f8bec2..d57d5646d 100644 --- a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java +++ b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java @@ -19,6 +19,7 @@ import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; +import org.eclipse.debug.core.model.IProcess; import org.eclipse.ui.externaltools.launchConfigurations.ExternalToolsUtil; import org.eclipse.ui.externaltools.variable.ExpandVariableContext; @@ -99,10 +100,31 @@ public class ProgramLaunchDelegate implements ILaunchConfigurationDelegate { } Process p = DebugPlugin.exec(cmdLine, workingDir); + IProcess process = null; if (p != null) { - DebugPlugin.newProcess(launch, p, location.toOSString()); + process = DebugPlugin.newProcess(launch, p, location.toOSString()); } + if (!ExternalToolsUtil.isBackground(configuration)) { + // wait for process to exit + while (!process.isTerminated()) { + try { + if (monitor.isCanceled()) { + process.terminate(); + break; + } + Thread.sleep(50); + } catch (InterruptedException e) { + } + } + + } + + // refresh resources + if (ExternalToolsUtil.getRefreshScope(configuration) != null) { + BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(configuration, process, resourceContext); + refresher.startBackgroundRefresh(); + } } } |