KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > actions > WorkspaceModifyDelegatingOperation


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.ui.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.jobs.ISchedulingRule;
18 import org.eclipse.jface.operation.IRunnableWithProgress;
19
20 /**
21  * An operation which delegates its work to a runnable that modifies the
22  * workspace.
23  * <p>
24  * This class may be instantiated; it is not intended to be subclassed.
25  * </p>
26  */

27 public class WorkspaceModifyDelegatingOperation extends
28         WorkspaceModifyOperation {
29
30     /**
31      * The runnable to delegate work to at execution time.
32      */

33     private IRunnableWithProgress content;
34
35     /**
36      * Creates a new operation which will delegate its work to the given
37      * runnable using the provided scheduling rule.
38      *
39      * @param content
40      * the runnable to delegate to when this operation is executed
41      * @param rule
42      * The ISchedulingRule to use or <code>null</code>.
43      */

44     public WorkspaceModifyDelegatingOperation(IRunnableWithProgress content,
45             ISchedulingRule rule) {
46         super(rule);
47         this.content = content;
48     }
49
50     /**
51      * Creates a new operation which will delegate its work to the given
52      * runnable. Schedule using the supplied s
53      *
54      * @param content
55      * the runnable to delegate to when this operation is executed
56      */

57     public WorkspaceModifyDelegatingOperation(IRunnableWithProgress content) {
58         super();
59         this.content = content;
60     }
61
62     /*
63      * (non-Javadoc) Method declared on WorkbenchModifyOperation.
64      */

65     protected void execute(IProgressMonitor monitor) throws CoreException,
66             InterruptedException JavaDoc {
67         try {
68             content.run(monitor);
69         } catch (InvocationTargetException JavaDoc e) {
70             if (e.getTargetException() instanceof CoreException) {
71                 throw (CoreException) e.getTargetException();
72             }
73             if (e.getTargetException() instanceof RuntimeException JavaDoc) {
74                 throw (RuntimeException JavaDoc) e.getTargetException();
75             }
76             if (e.getTargetException() instanceof Error JavaDoc) {
77                 throw (Error JavaDoc) e.getTargetException();
78             }
79             e.getTargetException().printStackTrace();
80         }
81     }
82 }
83
Popular Tags