5f3e0204d316c0b1ad6f99167f455ba20f1ed5f9
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / BatchOperation.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.core;
12
13 import net.sourceforge.phpdt.core.IJavaModelStatus;
14 import net.sourceforge.phpdt.core.JavaModelException;
15
16 import org.eclipse.core.resources.IResourceStatus;
17 import org.eclipse.core.resources.IWorkspaceRunnable;
18 import org.eclipse.core.runtime.CoreException;
19
20
21 /**
22  * An operation created as a result of a call to JavaCore.run(IWorkspaceRunnable, IProgressMonitor)
23  * that encapsulates a user defined IWorkspaceRunnable.
24  */
25 public class BatchOperation extends JavaModelOperation {
26         protected IWorkspaceRunnable runnable;
27         public BatchOperation(IWorkspaceRunnable runnable) {
28                 this.runnable = runnable;
29         }
30
31         /* (non-Javadoc)
32          * @see org.eclipse.jdt.internal.core.JavaModelOperation#executeOperation()
33          */
34         protected void executeOperation() throws JavaModelException {
35                 try {
36                         this.runnable.run(fMonitor);
37                 } catch (CoreException ce) {
38                         if (ce instanceof JavaModelException) {
39                                 throw (JavaModelException)ce;
40                         } else {
41                                 if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
42                                         Throwable e= ce.getStatus().getException();
43                                         if (e instanceof JavaModelException) {
44                                                 throw (JavaModelException) e;
45                                         }
46                                 }
47                                 throw new JavaModelException(ce);
48                         }
49                 }
50         }
51         
52         /* (non-Javadoc)
53          * @see org.eclipse.jdt.internal.core.JavaModelOperation#verify()
54          */
55         protected IJavaModelStatus verify() {
56                 // cannot verify user defined operation
57                 return JavaModelStatus.VERIFIED_OK;
58         }
59
60         
61 }