Refactory
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / actions / WorkbenchRunnableAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
12
13 import java.lang.reflect.InvocationTargetException;
14
15 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
16
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18
19 import org.eclipse.core.resources.IWorkspaceRunnable;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.OperationCanceledException;
23 import org.eclipse.jface.operation.IRunnableWithProgress;
24
25 /**
26  * An <code>IRunnableWithProgress</code> that adapts and
27  * <code>IWorkspaceRunnable</code> so that is can be executed inside
28  * <code>IRunnableContext</code>. <code>OperationCanceledException</code>
29  * thrown by the apapted runnabled are cought and rethrown as a
30  * <code>InterruptedException</code>.
31  */
32 public class WorkbenchRunnableAdapter implements IRunnableWithProgress {
33
34         private IWorkspaceRunnable fWorkspaceRunnable;
35
36         public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable) {
37                 fWorkspaceRunnable = runnable;
38         }
39
40         /*
41          * @see IRunnableWithProgress#run(IProgressMonitor)
42          */
43         public void run(IProgressMonitor monitor) throws InvocationTargetException,
44                         InterruptedException {
45                 try {
46                         PHPeclipsePlugin.run(fWorkspaceRunnable, monitor);
47                 } catch (OperationCanceledException e) {
48                         throw new InterruptedException(e.getMessage());
49                 } catch (CoreException e) {
50                         throw new InvocationTargetException(e);
51                 }
52         }
53
54 }