KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > console > WorkspaceOperationRunner


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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
12 package org.eclipse.debug.internal.ui.views.console;
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15
16 import org.eclipse.core.resources.ResourcesPlugin;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.NullProgressMonitor;
19 import org.eclipse.core.runtime.jobs.ISchedulingRule;
20
21 import org.eclipse.jface.operation.IRunnableContext;
22 import org.eclipse.jface.operation.IRunnableWithProgress;
23
24 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
25 import org.eclipse.ui.texteditor.ISchedulingRuleProvider;
26
27 /**
28  * @since 3.0
29  */

30 class WorkspaceOperationRunner implements IRunnableContext {
31     
32     private IProgressMonitor fProgressMonitor;
33     
34     public WorkspaceOperationRunner() {
35     }
36     
37     /**
38      * Sets the progress monitor.
39      *
40      * @param progressMonitor the progress monitor to set
41      */

42     public void setProgressMonitor(IProgressMonitor progressMonitor) {
43         fProgressMonitor= progressMonitor;
44     }
45
46     /**
47      * Returns the progress monitor. It there is no progress monitor the monitor\
48      * is set to the <code>NullProgressMonitor</code>.
49      *
50      * @return the progress monitor
51      */

52     public IProgressMonitor getProgressMonitor() {
53         if (fProgressMonitor == null)
54             fProgressMonitor= new NullProgressMonitor();
55         return fProgressMonitor;
56     }
57
58     /*
59      * @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
60      */

61     public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
62         if (runnable instanceof ISchedulingRuleProvider)
63             run(fork, cancelable, runnable, ((ISchedulingRuleProvider)runnable).getSchedulingRule());
64         else
65             run(fork, cancelable, runnable, ResourcesPlugin.getWorkspace().getRoot());
66     }
67     
68     /*
69      * @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
70      */

71     public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable, ISchedulingRule schedulingRule) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
72         WorkspaceModifyDelegatingOperation operation= new WorkspaceModifyDelegatingOperation(runnable, schedulingRule);
73         operation.run(getProgressMonitor());
74     }
75 }
76
Popular Tags