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.views.tasklist;
11:
12: import org.eclipse.core.commands.ExecutionException;
13: import org.eclipse.core.commands.operations.IUndoableOperation;
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.core.runtime.IAdaptable;
16: import org.eclipse.core.runtime.IProgressMonitor;
17: import org.eclipse.jface.action.Action;
18: import org.eclipse.jface.dialogs.ErrorDialog;
19: import org.eclipse.jface.dialogs.IDialogSettings;
20: import org.eclipse.swt.widgets.Shell;
21: import org.eclipse.ui.PlatformUI;
22: import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
23: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
24:
25: /**
26: * This is the base class of all the local actions used in the task list view.
27: */
28: abstract class TaskAction extends Action {
29:
30: private TaskList taskList;
31:
32: /**
33: * TaskAction constructor.
34: */
35: protected TaskAction(TaskList tasklist, String id) {
36: super ();
37: this .taskList = tasklist;
38: setId(id);
39: }
40:
41: /**
42: * Returns the shell to use within actions.
43: */
44: protected Shell getShell() {
45: return taskList.getSite().getShell();
46: }
47:
48: /**
49: * Returns the task list viewer.
50: */
51: protected TaskList getTaskList() {
52: return taskList;
53: }
54:
55: /**
56: * Stores the current state value of this toggle action into the dialog
57: * store using action ID as a key.
58: */
59: protected void storeValue() {
60: IDialogSettings workbenchSettings = TaskList.getPlugin()
61: .getDialogSettings();
62: IDialogSettings settings = workbenchSettings
63: .getSection("TaskAction");//$NON-NLS-1$
64: if (settings == null) {
65: settings = workbenchSettings.addNewSection("TaskAction");//$NON-NLS-1$
66: }
67: settings.put(getId(), isChecked());
68: }
69:
70: /**
71: * Execute the specified undoable operation
72: */
73: void execute(IUndoableOperation operation, String title,
74: IProgressMonitor monitor, IAdaptable uiInfo) {
75: try {
76: PlatformUI.getWorkbench().getOperationSupport()
77: .getOperationHistory().execute(operation, monitor,
78: uiInfo);
79: } catch (ExecutionException e) {
80: if (e.getCause() instanceof CoreException) {
81: ErrorDialog.openError(WorkspaceUndoUtil
82: .getShell(uiInfo), title, null,
83: ((CoreException) e.getCause()).getStatus());
84: } else {
85: IDEWorkbenchPlugin.log(title, e);
86: }
87: }
88: }
89:
90: }
|