KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > tasklist > TaskAction


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
12 package org.eclipse.ui.views.tasklist;
13
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.operations.IUndoableOperation;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.action.Action;
20 import org.eclipse.jface.dialogs.ErrorDialog;
21 import org.eclipse.jface.dialogs.IDialogSettings;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
25 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
26
27 /**
28  * This is the base class of all the local actions used in the task list view.
29  */

30 abstract class TaskAction extends Action {
31
32     private TaskList taskList;
33
34     /**
35      * TaskAction constructor.
36      */

37     protected TaskAction(TaskList tasklist, String JavaDoc id) {
38         super();
39         this.taskList = tasklist;
40         setId(id);
41     }
42
43     /**
44      * Returns the shell to use within actions.
45      */

46     protected Shell getShell() {
47         return taskList.getSite().getShell();
48     }
49
50     /**
51      * Returns the task list viewer.
52      */

53     protected TaskList getTaskList() {
54         return taskList;
55     }
56
57     /**
58      * Stores the current state value of this toggle action into the dialog
59      * store using action ID as a key.
60      */

61     protected void storeValue() {
62         IDialogSettings workbenchSettings = TaskList.getPlugin()
63                 .getDialogSettings();
64         IDialogSettings settings = workbenchSettings.getSection("TaskAction");//$NON-NLS-1$
65
if (settings == null) {
66             settings = workbenchSettings.addNewSection("TaskAction");//$NON-NLS-1$
67
}
68         settings.put(getId(), isChecked());
69     }
70
71     /**
72      * Execute the specified undoable operation
73      */

74     void execute(IUndoableOperation operation, String JavaDoc title,
75             IProgressMonitor monitor, IAdaptable uiInfo) {
76         try {
77             PlatformUI.getWorkbench().getOperationSupport()
78                     .getOperationHistory().execute(operation, monitor, uiInfo);
79         } catch (ExecutionException e) {
80             if (e.getCause() instanceof CoreException) {
81                 ErrorDialog
82                         .openError(WorkspaceUndoUtil.getShell(uiInfo), title,
83                                 null, ((CoreException) e.getCause())
84                                         .getStatus());
85             } else {
86                 IDEWorkbenchPlugin.log(title, e);
87             }
88         }
89     }
90
91 }
92
Popular Tags