KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.resources.IMarker;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.jface.viewers.StructuredSelection;
17 import org.eclipse.jface.window.Window;
18 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.ui.internal.views.tasklist.TaskListMessages;
20
21 /**
22  * This action creates a new task. If a resource is currently
23  * present at the tasklist's input, this task will be
24  * associated with it. If the tasklist is currently
25  * observing all the markers in the workbench, the task
26  * will not be associated with any resource.
27  * <p>The newly created task will have low priority,
28  * fixed description text and will not be subject to
29  * sorting or filtering until its desciprion is being
30  * changed for the first time. For this reason, new
31  * tasks remain at the top of the task list
32  * until modified. It is possible that the newly
33  * created task dissapears after that if its
34  * type or some other property causes it to
35  * be filtered out.
36  */

37 class NewTaskAction extends TaskAction {
38
39     /**
40      * Creates the action.
41      *
42      * @param tasklist the task list
43      * @param id the id
44      */

45     public NewTaskAction(TaskList tasklist, String JavaDoc id) {
46         super(tasklist, id);
47         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
48                 ITaskListHelpContextIds.NEW_TASK_ACTION);
49     }
50
51     /**
52      * Opens the new task dialog and shows the newly created task when done.
53      * The new task is created on the currently selected resource.
54      */

55     public void run() {
56         TaskPropertiesDialog dialog = new TaskPropertiesDialog(getShell());
57         dialog.setResource(getTaskList().getResource());
58         int result = dialog.open();
59         if (result == Window.OK) {
60             showMarker(dialog.getMarker());
61         }
62     }
63
64     /**
65      * Show the newly created marker.
66      */

67     private void showMarker(final IMarker marker) {
68         if (marker == null) {
69             return;
70         }
71         if (getTaskList().shouldShow(marker)) {
72             // Need to do this in an asyncExec, even though we're in the UI thread here,
73
// since the task list updates itself with the addition in an asyncExec,
74
// which hasn't been processed yet.
75
getShell().getDisplay().asyncExec(new Runnable JavaDoc() {
76                 public void run() {
77                     getTaskList().setSelection(new StructuredSelection(marker),
78                             true);
79                 }
80             });
81         } else {
82             MessageDialog.openInformation(getShell(), TaskListMessages.NewTask_notShownTitle,
83                     TaskListMessages.NewTask_notShownMsg);
84         }
85     }
86 }
87
Popular Tags