1 package net.sourceforge.phpdt.externaltools.internal.program.launchConfigurations;
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
10 **********************************************************************/
12 import java.lang.reflect.InvocationTargetException;
14 import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
15 import net.sourceforge.phpdt.externaltools.variable.ExpandVariableContext;
16 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.debug.core.DebugEvent;
21 import org.eclipse.debug.core.DebugPlugin;
22 import org.eclipse.debug.core.IDebugEventSetListener;
23 import org.eclipse.debug.core.ILaunchConfiguration;
24 import org.eclipse.debug.core.model.IProcess;
25 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
26 import org.eclipse.jface.operation.IRunnableWithProgress;
29 * Refreshes resources as specified by a lanunch configuration, when
30 * an associated process terminates.
32 public class BackgroundResourceRefresher implements IDebugEventSetListener, Runnable, IRunnableWithProgress {
34 private ExpandVariableContext fContext;
35 private ILaunchConfiguration fConfiguration;
36 private IProcess fProcess;
38 public BackgroundResourceRefresher(ILaunchConfiguration configuration, IProcess process, ExpandVariableContext context) {
39 fConfiguration = configuration;
45 * If the process has already terminated, resource refreshing is done
46 * immediately in the current thread. Otherwise, refreshing is done when the
49 public void startBackgroundRefresh() {
50 synchronized (fProcess) {
51 if (fProcess.isTerminated()) {
54 DebugPlugin.getDefault().addDebugEventListener(this);
60 * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent)
62 public void handleDebugEvents(DebugEvent[] events) {
63 for (int i = 0; i < events.length; i++) {
64 DebugEvent event = events[i];
65 if (event.getSource() == fProcess && event.getKind() == DebugEvent.TERMINATE) {
66 DebugPlugin.getDefault().removeDebugEventListener(this);
74 * Submits a runnable to do the refresh
76 protected void refresh() {
77 PHPeclipsePlugin.getStandardDisplay().asyncExec(this);
81 * Creates a dialog to run the refresh
83 * @see java.lang.Runnable#run()
86 ProgressMonitorDialog dialog = new ProgressMonitorDialog(PHPeclipsePlugin.getStandardDisplay().getActiveShell());
88 dialog.run(true, true, this);
89 } catch (InvocationTargetException e) {
90 // report the exception
91 } catch (InterruptedException e) {
97 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
99 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
101 ExternalToolsUtil.refreshResources(fConfiguration, fContext, monitor);
102 } catch (CoreException e) {
103 throw new InvocationTargetException(e);