1 11 package org.eclipse.core.internal.resources; 12 13 import org.eclipse.core.internal.utils.Policy; 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.core.runtime.jobs.Job; 17 18 22 public abstract class InternalWorkspaceJob extends Job { 23 private Workspace workspace; 24 25 public InternalWorkspaceJob(String name) { 26 super(name); 27 this.workspace = (Workspace) ResourcesPlugin.getWorkspace(); 28 } 29 30 public final IStatus run(IProgressMonitor monitor) { 31 monitor = Policy.monitorFor(monitor); 32 try { 33 int depth = -1; 34 try { 35 workspace.prepareOperation(null, monitor); 36 workspace.beginOperation(true); 37 depth = workspace.getWorkManager().beginUnprotected(); 38 return runInWorkspace(monitor); 39 } catch (OperationCanceledException e) { 40 workspace.getWorkManager().operationCanceled(); 41 return Status.CANCEL_STATUS; 42 } finally { 43 if (depth >= 0) 44 workspace.getWorkManager().endUnprotected(depth); 45 workspace.endOperation(null, false, monitor); 46 } 47 } catch (CoreException e) { 48 return e.getStatus(); 49 } 50 } 51 52 protected abstract IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException; 53 } 54 | Popular Tags |