Skip to main content
summaryrefslogtreecommitdiffstats
blob: a6c0c2799ef94c2a63985acf28f518138bd63c2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.internal.tasklist.ui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.mylar.internal.tasklist.Task;
import org.eclipse.mylar.internal.tasklist.TaskCategory;
import org.eclipse.mylar.internal.tasklist.ui.TaskListImages;
import org.eclipse.mylar.internal.tasklist.ui.TaskListUiUtil;
import org.eclipse.mylar.internal.tasklist.ui.views.TaskInputDialog;
import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.MylarTaskListPlugin;
import org.eclipse.ui.internal.Workbench;

/**
 * @author Mik Kersten
 */
public class NewLocalTaskAction extends Action {

	public static final String ID = "org.eclipse.mylar.tasklist.actions.create.task";

	private final TaskListView view;

	public NewLocalTaskAction(TaskListView view) {
		this.view = view;
		setText("Add Task");
		setToolTipText("Add Task");
		setId(ID);
		setImageDescriptor(TaskListImages.TASK_NEW);
	}

	@Override
	public void run() {
		TaskInputDialog dialog = new TaskInputDialog(Workbench.getInstance().getActiveWorkbenchWindow().getShell());
		int dialogResult = dialog.open();
		if (dialogResult == Window.OK) {
			Task newTask = new Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(), dialog
					.getTaskname(), true);
			newTask.setPriority(dialog.getSelectedPriority());
			newTask.setReminderDate(dialog.getReminderDate());
			newTask.setUrl(dialog.getIssueURL());

			Object selectedObject = ((IStructuredSelection) view.getViewer().getSelection()).getFirstElement();

			if (selectedObject instanceof TaskCategory) {
				MylarTaskListPlugin.getTaskListManager().moveToCategory((TaskCategory) selectedObject, newTask);
			} else if (selectedObject instanceof ITask) {
				ITask task = (ITask) selectedObject;
				if (task.getCategory() != null) {
					MylarTaskListPlugin.getTaskListManager().moveToCategory((TaskCategory) task.getCategory(), newTask);
				} else if (view.getDrilledIntoCategory() != null) {
					MylarTaskListPlugin.getTaskListManager().moveToCategory(
							(TaskCategory) view.getDrilledIntoCategory(), newTask);
				} else {
					MylarTaskListPlugin.getTaskListManager().moveToRoot(newTask);
				}
			} else if (view.getDrilledIntoCategory() != null) {
				MylarTaskListPlugin.getTaskListManager().moveToCategory((TaskCategory) view.getDrilledIntoCategory(),
						newTask);
			} else {
				MylarTaskListPlugin.getTaskListManager().moveToRoot(newTask);
			}
			TaskListUiUtil.openEditor(newTask);
//			newTask.openTaskInEditor(false);
			view.getViewer().setSelection(new StructuredSelection(newTask));
			view.getViewer().refresh();
		}
	}
}

Back to the top