Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / 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.PHPCore;
16
17 import org.eclipse.core.resources.IWorkspaceRunnable;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.OperationCanceledException;
21 import org.eclipse.jface.operation.IRunnableWithProgress;
22
23
24 /**
25  * An <code>IRunnableWithProgress</code> that adapts and  <code>IWorkspaceRunnable</code>
26  * so that is can be executed inside <code>IRunnableContext</code>. <code>OperationCanceledException</code> 
27  * thrown by the apapted runnabled are cought and rethrown as a <code>InterruptedException</code>.
28  */
29 public class WorkbenchRunnableAdapter implements IRunnableWithProgress {
30         
31         private IWorkspaceRunnable fWorkspaceRunnable;
32         
33         public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable) {
34                 fWorkspaceRunnable= runnable;
35         }
36
37         /*
38          * @see IRunnableWithProgress#run(IProgressMonitor)
39          */
40         public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
41                 try {
42                         PHPCore.run(fWorkspaceRunnable, monitor);
43                 } catch (OperationCanceledException e) {
44                         throw new InterruptedException(e.getMessage());
45                 } catch (CoreException e) {
46                         throw new InvocationTargetException(e);
47                 }
48         }
49
50 }
51