01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.actions;
11:
12: import java.lang.reflect.InvocationTargetException;
13:
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.core.runtime.IProgressMonitor;
16: import org.eclipse.core.runtime.jobs.ISchedulingRule;
17: import org.eclipse.jface.operation.IRunnableWithProgress;
18:
19: /**
20: * An operation which delegates its work to a runnable that modifies the
21: * workspace.
22: * <p>
23: * This class may be instantiated; it is not intended to be subclassed.
24: * </p>
25: */
26: public class WorkspaceModifyDelegatingOperation extends
27: WorkspaceModifyOperation {
28:
29: /**
30: * The runnable to delegate work to at execution time.
31: */
32: private IRunnableWithProgress content;
33:
34: /**
35: * Creates a new operation which will delegate its work to the given
36: * runnable using the provided scheduling rule.
37: *
38: * @param content
39: * the runnable to delegate to when this operation is executed
40: * @param rule
41: * The ISchedulingRule to use or <code>null</code>.
42: */
43: public WorkspaceModifyDelegatingOperation(
44: IRunnableWithProgress content, ISchedulingRule rule) {
45: super (rule);
46: this .content = content;
47: }
48:
49: /**
50: * Creates a new operation which will delegate its work to the given
51: * runnable. Schedule using the supplied s
52: *
53: * @param content
54: * the runnable to delegate to when this operation is executed
55: */
56: public WorkspaceModifyDelegatingOperation(
57: 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)
66: throws CoreException, InterruptedException {
67: try {
68: content.run(monitor);
69: } catch (InvocationTargetException e) {
70: if (e.getTargetException() instanceof CoreException) {
71: throw (CoreException) e.getTargetException();
72: }
73: if (e.getTargetException() instanceof RuntimeException) {
74: throw (RuntimeException) e.getTargetException();
75: }
76: if (e.getTargetException() instanceof Error) {
77: throw (Error) e.getTargetException();
78: }
79: e.getTargetException().printStackTrace();
80: }
81: }
82: }
|