01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 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.resources.IMarker;
13: import org.eclipse.jface.dialogs.MessageDialog;
14: import org.eclipse.jface.viewers.StructuredSelection;
15: import org.eclipse.jface.window.Window;
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.internal.views.tasklist.TaskListMessages;
18:
19: /**
20: * This action creates a new task. If a resource is currently
21: * present at the tasklist's input, this task will be
22: * associated with it. If the tasklist is currently
23: * observing all the markers in the workbench, the task
24: * will not be associated with any resource.
25: * <p>The newly created task will have low priority,
26: * fixed description text and will not be subject to
27: * sorting or filtering until its desciprion is being
28: * changed for the first time. For this reason, new
29: * tasks remain at the top of the task list
30: * until modified. It is possible that the newly
31: * created task dissapears after that if its
32: * type or some other property causes it to
33: * be filtered out.
34: */
35: class NewTaskAction extends TaskAction {
36:
37: /**
38: * Creates the action.
39: *
40: * @param tasklist the task list
41: * @param id the id
42: */
43: public NewTaskAction(TaskList tasklist, String id) {
44: super (tasklist, id);
45: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
46: ITaskListHelpContextIds.NEW_TASK_ACTION);
47: }
48:
49: /**
50: * Opens the new task dialog and shows the newly created task when done.
51: * The new task is created on the currently selected resource.
52: */
53: public void run() {
54: TaskPropertiesDialog dialog = new TaskPropertiesDialog(
55: getShell());
56: dialog.setResource(getTaskList().getResource());
57: int result = dialog.open();
58: if (result == Window.OK) {
59: showMarker(dialog.getMarker());
60: }
61: }
62:
63: /**
64: * Show the newly created marker.
65: */
66: private void showMarker(final IMarker marker) {
67: if (marker == null) {
68: return;
69: }
70: if (getTaskList().shouldShow(marker)) {
71: // Need to do this in an asyncExec, even though we're in the UI thread here,
72: // since the task list updates itself with the addition in an asyncExec,
73: // which hasn't been processed yet.
74: getShell().getDisplay().asyncExec(new Runnable() {
75: public void run() {
76: getTaskList().setSelection(
77: new StructuredSelection(marker), true);
78: }
79: });
80: } else {
81: MessageDialog.openInformation(getShell(),
82: TaskListMessages.NewTask_notShownTitle,
83: TaskListMessages.NewTask_notShownMsg);
84: }
85: }
86: }
|