KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > BatchOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import org.eclipse.core.resources.IResourceStatus;
14 import org.eclipse.core.resources.IWorkspaceRunnable;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jdt.core.IJavaModelStatus;
17 import org.eclipse.jdt.core.JavaModelException;
18
19 /**
20  * An operation created as a result of a call to JavaCore.run(IWorkspaceRunnable, IProgressMonitor)
21  * that encapsulates a user defined IWorkspaceRunnable.
22  */

23 public class BatchOperation extends JavaModelOperation {
24     protected IWorkspaceRunnable runnable;
25     public BatchOperation(IWorkspaceRunnable runnable) {
26         this.runnable = runnable;
27     }
28
29     protected boolean canModifyRoots() {
30         // anything in the workspace runnable can modify the roots
31
return true;
32     }
33     
34     /* (non-Javadoc)
35      * @see org.eclipse.jdt.internal.core.JavaModelOperation#executeOperation()
36      */

37     protected void executeOperation() throws JavaModelException {
38         try {
39             this.runnable.run(this.progressMonitor);
40         } catch (CoreException ce) {
41             if (ce instanceof JavaModelException) {
42                 throw (JavaModelException)ce;
43             } else {
44                 if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
45                     Throwable JavaDoc e= ce.getStatus().getException();
46                     if (e instanceof JavaModelException) {
47                         throw (JavaModelException) e;
48                     }
49                 }
50                 throw new JavaModelException(ce);
51             }
52         }
53     }
54     
55     /* (non-Javadoc)
56      * @see org.eclipse.jdt.internal.core.JavaModelOperation#verify()
57      */

58     protected IJavaModelStatus verify() {
59         // cannot verify user defined operation
60
return JavaModelStatus.VERIFIED_OK;
61     }
62
63     
64 }
65
Popular Tags