|
Lines 21-26
Link Here
|
| 21 |
import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil; |
21 |
import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil; |
| 22 |
import org.eclipse.mylar.internal.tasks.ui.views.TaskInputDialog; |
22 |
import org.eclipse.mylar.internal.tasks.ui.views.TaskInputDialog; |
| 23 |
import org.eclipse.mylar.internal.tasks.ui.views.TaskListView; |
23 |
import org.eclipse.mylar.internal.tasks.ui.views.TaskListView; |
|
|
24 |
import org.eclipse.mylar.tasks.core.AbstractTaskContainer; |
| 24 |
import org.eclipse.mylar.tasks.core.ITask; |
25 |
import org.eclipse.mylar.tasks.core.ITask; |
| 25 |
import org.eclipse.mylar.tasks.core.Task; |
26 |
import org.eclipse.mylar.tasks.core.Task; |
| 26 |
import org.eclipse.mylar.tasks.core.TaskCategory; |
27 |
import org.eclipse.mylar.tasks.core.TaskCategory; |
|
Lines 28-43
Link Here
|
| 28 |
import org.eclipse.swt.widgets.Display; |
29 |
import org.eclipse.swt.widgets.Display; |
| 29 |
|
30 |
|
| 30 |
/** |
31 |
/** |
| 31 |
* @author Mik Kersten |
32 |
* @author Mik Kersten and Izzet Safer |
| 32 |
*/ |
33 |
*/ |
| 33 |
public class NewLocalTaskAction extends Action { |
34 |
public class NewLocalTaskAction extends Action { |
| 34 |
|
35 |
|
| 35 |
public static final String DESCRIPTION_DEFAULT = "new task"; |
36 |
public static final String DESCRIPTION_DEFAULT = "New Task"; |
| 36 |
|
37 |
|
| 37 |
public static final String ID = "org.eclipse.mylar.tasklist.actions.create.task"; |
38 |
public static final String ID = "org.eclipse.mylar.tasklist.actions.create.task"; |
| 38 |
|
39 |
|
| 39 |
private final TaskListView view; |
40 |
private final TaskListView view; |
| 40 |
|
41 |
|
| 41 |
public NewLocalTaskAction() { |
42 |
public NewLocalTaskAction() { |
| 42 |
this(null); |
43 |
this(null); |
| 43 |
} |
44 |
} |
|
Lines 52-99
Link Here
|
| 52 |
|
53 |
|
| 53 |
@Override |
54 |
@Override |
| 54 |
public void run() { |
55 |
public void run() { |
| 55 |
Task newTask = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(), DESCRIPTION_DEFAULT, true); |
56 |
String taskHandle = TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(); |
| 56 |
|
57 |
AbstractTaskContainer category = null; |
| 57 |
Calendar reminderCalendar = GregorianCalendar.getInstance(); |
58 |
boolean showWarning = false; |
| 58 |
TasksUiPlugin.getTaskListManager().setScheduledToday(reminderCalendar); |
59 |
|
| 59 |
TasksUiPlugin.getTaskListManager().setReminder(newTask, reminderCalendar.getTime()); |
|
|
| 60 |
|
| 61 |
Object selectedObject = null; |
60 |
Object selectedObject = null; |
| 62 |
if (view != null) { |
61 |
if (view != null) { |
| 63 |
selectedObject = ((IStructuredSelection) view.getViewer().getSelection()).getFirstElement(); |
62 |
selectedObject = ((IStructuredSelection) view.getViewer().getSelection()).getFirstElement(); |
| 64 |
} |
63 |
} |
|
|
64 |
|
| 65 |
if (selectedObject instanceof TaskCategory) { |
65 |
if (selectedObject instanceof TaskCategory) { |
| 66 |
TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask, (TaskCategory) selectedObject); |
66 |
category = (TaskCategory) selectedObject; |
| 67 |
} else if (selectedObject instanceof ITask) { |
67 |
} else if (selectedObject instanceof ITask) { |
| 68 |
ITask task = (ITask) selectedObject; |
68 |
ITask task = (ITask) selectedObject; |
| 69 |
if (task.getContainer() instanceof TaskCategory) { |
69 |
if (task.getContainer() instanceof TaskCategory) { |
| 70 |
TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask, |
70 |
category = (TaskCategory) task.getContainer(); |
| 71 |
(TaskCategory) task.getContainer()); |
|
|
| 72 |
} else if (view.getDrilledIntoCategory() instanceof TaskCategory) { |
71 |
} else if (view.getDrilledIntoCategory() instanceof TaskCategory) { |
| 73 |
TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask, |
72 |
category = (TaskCategory) view.getDrilledIntoCategory(); |
| 74 |
(TaskCategory) view.getDrilledIntoCategory()); |
|
|
| 75 |
} else { |
73 |
} else { |
| 76 |
TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask, |
74 |
category = TasksUiPlugin.getTaskListManager().getTaskList().getRootCategory(); |
| 77 |
TasksUiPlugin.getTaskListManager().getTaskList().getRootCategory()); |
|
|
| 78 |
} |
75 |
} |
| 79 |
} else if (view != null && view.getDrilledIntoCategory() instanceof TaskCategory) { |
76 |
} else if (view != null && view.getDrilledIntoCategory() instanceof TaskCategory) { |
| 80 |
TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask, |
77 |
category = (TaskCategory) view.getDrilledIntoCategory(); |
| 81 |
(TaskCategory) view.getDrilledIntoCategory()); |
|
|
| 82 |
} else { |
78 |
} else { |
| 83 |
if (view != null && view.getDrilledIntoCategory() != null) { |
79 |
if (view != null && view.getDrilledIntoCategory() != null) { |
| 84 |
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), TasksUiPlugin.TITLE_DIALOG, |
80 |
showWarning = true; |
| 85 |
"The new task has been added to the root of the list, since tasks can not be added to a query."); |
|
|
| 86 |
} |
81 |
} |
| 87 |
TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask, |
82 |
category = TasksUiPlugin.getTaskListManager().getTaskList().getRootCategory(); |
| 88 |
TasksUiPlugin.getTaskListManager().getTaskList().getRootCategory()); |
|
|
| 89 |
} |
83 |
} |
| 90 |
TaskUiUtil.openEditor(newTask, true); |
84 |
|
|
|
85 |
addNewLocalTask(taskHandle, DESCRIPTION_DEFAULT, category, true, showWarning); |
| 86 |
} |
| 87 |
|
| 88 |
public ITask run(String taskHandle, String taskName, String categoryName) { |
| 89 |
if (taskHandle == null || taskHandle.equals("")) |
| 90 |
taskHandle = TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(); |
| 91 |
|
91 |
|
| 92 |
if (view != null) { |
92 |
AbstractTaskContainer category = null; |
| 93 |
view.getViewer().refresh(); |
93 |
if (categoryName == null || categoryName.equals("")) { |
| 94 |
view.setInRenameAction(true); |
94 |
category = TasksUiPlugin.getTaskListManager().getTaskList().getRootCategory(); |
| 95 |
view.getViewer().editElement(newTask, 4); |
95 |
} |
| 96 |
view.setInRenameAction(false); |
96 |
else { |
|
|
97 |
category = TasksUiPlugin.getTaskListManager().getTaskList().getContainerForHandle(categoryName); |
| 98 |
if (category == null) { |
| 99 |
// the category is not found, create it by calling NewCategoryAction |
| 100 |
NewCategoryAction action = new NewCategoryAction(TaskListView.getFromActivePerspective()); |
| 101 |
action.run(categoryName); |
| 102 |
category = TasksUiPlugin.getTaskListManager().getTaskList().getContainerForHandle(categoryName); |
| 103 |
if (category == null) category = TasksUiPlugin.getTaskListManager().getTaskList().getRootCategory(); |
| 104 |
} |
| 97 |
} |
105 |
} |
|
|
106 |
|
| 107 |
return addNewLocalTask(taskHandle, taskName, category, false, false); |
| 98 |
} |
108 |
} |
|
|
109 |
|
| 110 |
private ITask addNewLocalTask(String taskHandle, String taskName, AbstractTaskContainer category, boolean edit, boolean showWarning) { |
| 111 |
ITask newTask = new Task(taskHandle, taskName, true); |
| 112 |
// newTask.setUrl(getDefaultIssueURL()); |
| 113 |
|
| 114 |
Calendar reminderCalendar = GregorianCalendar.getInstance(); |
| 115 |
TasksUiPlugin.getTaskListManager().setScheduledToday(reminderCalendar); |
| 116 |
TasksUiPlugin.getTaskListManager().setReminder(newTask, reminderCalendar.getTime()); |
| 117 |
|
| 118 |
if (showWarning) { |
| 119 |
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), TasksUiPlugin.TITLE_DIALOG, |
| 120 |
"The new task has been added to the root of the list, since tasks can not be added to a query."); |
| 121 |
} |
| 122 |
TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask, category); |
| 123 |
|
| 124 |
if (edit) TaskUiUtil.openEditor(newTask, true); |
| 125 |
|
| 126 |
if (view != null) { |
| 127 |
view.getViewer().refresh(); |
| 128 |
|
| 129 |
if (edit) { |
| 130 |
view.setInRenameAction(true); |
| 131 |
view.getViewer().editElement(newTask, 4); |
| 132 |
view.setInRenameAction(false); |
| 133 |
} |
| 134 |
} |
| 135 |
return newTask; |
| 136 |
} |
| 99 |
} |
137 |
} |