Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / BatchOperation.java
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BatchOperation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BatchOperation.java
new file mode 100644 (file)
index 0000000..5f3e020
--- /dev/null
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are 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:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package net.sourceforge.phpdt.internal.core;
+
+import net.sourceforge.phpdt.core.IJavaModelStatus;
+import net.sourceforge.phpdt.core.JavaModelException;
+
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.runtime.CoreException;
+
+
+/**
+ * An operation created as a result of a call to JavaCore.run(IWorkspaceRunnable, IProgressMonitor)
+ * that encapsulates a user defined IWorkspaceRunnable.
+ */
+public class BatchOperation extends JavaModelOperation {
+       protected IWorkspaceRunnable runnable;
+       public BatchOperation(IWorkspaceRunnable runnable) {
+               this.runnable = runnable;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jdt.internal.core.JavaModelOperation#executeOperation()
+        */
+       protected void executeOperation() throws JavaModelException {
+               try {
+                       this.runnable.run(fMonitor);
+               } catch (CoreException ce) {
+                       if (ce instanceof JavaModelException) {
+                               throw (JavaModelException)ce;
+                       } else {
+                               if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
+                                       Throwable e= ce.getStatus().getException();
+                                       if (e instanceof JavaModelException) {
+                                               throw (JavaModelException) e;
+                                       }
+                               }
+                               throw new JavaModelException(ce);
+                       }
+               }
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jdt.internal.core.JavaModelOperation#verify()
+        */
+       protected IJavaModelStatus verify() {
+               // cannot verify user defined operation
+               return JavaModelStatus.VERIFIED_OK;
+       }
+
+       
+}