Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 145884 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+105 lines)
Lines 419-425 Link Here
419
             id="org.eclipse.mylar.tasklist.hyperlinkLister.task"
419
             id="org.eclipse.mylar.tasklist.hyperlinkLister.task"
420
             type="task"/>
420
             type="task"/>
421
    </extension>-->
421
    </extension>-->
422
  
423
  	<extension point="org.eclipse.ui.handlers">
424
		<handler
425
			commandId="org.eclipse.mylar.tasklist.commands.addNewLocalTask"
426
			class="org.eclipse.mylar.internal.tasklist.ui.commands.NewLocalTaskHandler">
427
		</handler>		
428
		
429
		<handler
430
			commandId="org.eclipse.mylar.tasklist.commands.addNewLocalSubTask"
431
			class="org.eclipse.mylar.internal.tasklist.ui.commands.NewLocalSubTaskHandler">
432
		</handler>		
433
434
		<handler
435
			commandId="org.eclipse.mylar.tasklist.commands.activateTask"
436
			class="org.eclipse.mylar.internal.tasklist.ui.commands.TaskActivateHandler">
437
		</handler>		
438
439
		<handler
440
			commandId="org.eclipse.mylar.tasklist.commands.completeTask"
441
			class="org.eclipse.mylar.internal.tasklist.ui.commands.MarkTaskCompleteHandler">
442
		</handler>		
443
444
    </extension>
445
  
446
  	<extension point="org.eclipse.ui.commands">
447
		<command 
448
			description="Add new Mylar Task"
449
			id="org.eclipse.mylar.tasklist.commands.addNewLocalTask"
450
			name="Add new Mylar Task">
451
			<commandParameter 
452
				id="taskName" 
453
				name="Task Name"
454
				optional="false"/>
455
			<commandParameter 
456
				id="taskHandle" 
457
				name="Unique Task Handle"
458
				optional="true"/>
459
			<commandParameter 
460
				id="categoryName" 
461
				name="Category Name"
462
				optional="true"/>
463
			<commandParameter 
464
				id="activateTask" 
465
				name="Boolean parameter to activate the task"
466
				optional="true"/>
467
			<commandParameter 
468
				id="resetContext" 
469
				name="Boolean parameter to delete the context of the existing task"
470
				optional="true"/>
471
		</command>
472
	
473
		<command 
474
			description="Add new Mylar Subtask"
475
			id="org.eclipse.mylar.tasklist.commands.addNewLocalSubTask"
476
			name="Add new Mylar Subtask">
477
			<commandParameter 
478
				id="taskName" 
479
				name="Subtask Name"
480
				optional="false"/>
481
			<commandParameter 
482
				id="taskHandle" 
483
				name="Unique Task Handle"
484
				optional="true"/>
485
			<commandParameter 
486
				id="parentHandle" 
487
				name="Handle to parent task"
488
				optional="false"/>
489
			<commandParameter 
490
				id="activateTask" 
491
				name="Boolean parameter to activate the subtask"
492
				optional="true"/>
493
			<commandParameter 
494
				id="resetContext" 
495
				name="Boolean parameter to delete the context of the existing subtask"
496
				optional="true"/>
497
		</command>
498
499
		<command 
500
			description="Activate/Deactivate a Mylar task"
501
			id="org.eclipse.mylar.tasklist.commands.activateTask"
502
			name="Activate a Mylar task">			
503
			<commandParameter 
504
				id="taskHandle" 
505
				name="Unique Task Handle"
506
				optional="false"/>
507
			<commandParameter 
508
				id="activateTask" 
509
				name="Boolean parameter to Activate/Deactivate"
510
				optional="true"/>
511
		</command>
512
513
		<command 
514
			description="Mark Complete/Incomplete a Mylar task"
515
			id="org.eclipse.mylar.tasklist.commands.completeTask"
516
			name="Complete a Mylar task">			
517
			<commandParameter 
518
				id="taskHandle" 
519
				name="Unique Task Handle"
520
				optional="false"/>
521
			<commandParameter 
522
				id="completeTask" 
523
				name="Boolean parameter to set Complete/Incomplete"
524
				optional="true"/>
525
		</command>
422
526
527
    </extension>  
423
  
528
  
424
</plugin>
529
</plugin>
425
530
Lines 433-436 Link Here
433
	  		class="org.eclipse.mylar.tasklist.ui.actions.GoIntoAction"
538
	  		class="org.eclipse.mylar.tasklist.ui.actions.GoIntoAction"
434
	  		icon="icons/etool16/go-into.gif"
539
	  		icon="icons/etool16/go-into.gif"
435
	  		enablesFor="1"/>
540
	  		enablesFor="1"/>
(-)src/org/eclipse/mylar/internal/tasklist/ui/actions/MarkTaskIncompleteAction.java (-2 / +14 lines)
Lines 19-25 Link Here
19
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
19
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
20
20
21
/**
21
/**
22
 * @author Mik Kersten and Ken Sueda
22
 * @author Mik Kersten, Ken Sueda and Izzet Safer
23
 */
23
 */
24
public class MarkTaskIncompleteAction extends Action {
24
public class MarkTaskIncompleteAction extends Action {
25
25
Lines 27-32 Link Here
27
27
28
	private final TaskListView view;
28
	private final TaskListView view;
29
29
30
	public MarkTaskIncompleteAction() {
31
		this(TaskListView.getFromActivePerspective());
32
	}
33
	
30
	public MarkTaskIncompleteAction(TaskListView view) {
34
	public MarkTaskIncompleteAction(TaskListView view) {
31
		this.view = view;
35
		this.view = view;
32
		setText("Mark Incomplete");
36
		setText("Mark Incomplete");
Lines 39-46 Link Here
39
	public void run() {
43
	public void run() {
40
		for (Object selectedObject : ((IStructuredSelection) this.view.getViewer().getSelection()).toList()) {
44
		for (Object selectedObject : ((IStructuredSelection) this.view.getViewer().getSelection()).toList()) {
41
			if (selectedObject instanceof ITask) {
45
			if (selectedObject instanceof ITask) {
42
				MylarTaskListPlugin.getTaskListManager().getTaskList().markComplete(((ITask) selectedObject), false);
46
				markIncomplete((ITask)selectedObject);
43
			}
47
			}
44
		}
48
		}
45
	}
49
	}
50
	
51
	public void run(ITask task) {
52
		markIncomplete(task);
53
	}
54
	
55
	private void markIncomplete(ITask task) {
56
		MylarTaskListPlugin.getTaskListManager().getTaskList().markComplete(task, false);
57
	}
46
}
58
}
(-)src/org/eclipse/mylar/internal/tasklist/ui/actions/NewCategoryAction.java (-4 / +12 lines)
Lines 21-27 Link Here
21
import org.eclipse.ui.PlatformUI;
21
import org.eclipse.ui.PlatformUI;
22
22
23
/**
23
/**
24
 * @author Mik Kersten and Ken Sueda
24
 * @author Mik Kersten, Ken Sueda and Izzet Safer
25
 */
25
 */
26
public class NewCategoryAction extends Action {
26
public class NewCategoryAction extends Action {
27
27
Lines 43-51 Link Here
43
				"Enter name", "Enter a name for the Category: ", "", null);
43
				"Enter name", "Enter a name for the Category: ", "", null);
44
		int dialogResult = dialog.open();
44
		int dialogResult = dialog.open();
45
		if (dialogResult == Window.OK) {
45
		if (dialogResult == Window.OK) {
46
			TaskCategory cat = new TaskCategory(dialog.getValue(), MylarTaskListPlugin.getTaskListManager().getTaskList());
46
			addCategory(dialog.getValue());
47
			MylarTaskListPlugin.getTaskListManager().getTaskList().addCategory(cat);
48
			this.view.getViewer().refresh();
49
		}
47
		}
50
	}
48
	}
49
	
50
	public void run(String categoryName) {
51
		addCategory(categoryName);
52
	}
53
	
54
	private void addCategory(String categoryName) {
55
		TaskCategory cat = new TaskCategory(categoryName, MylarTaskListPlugin.getTaskListManager().getTaskList());
56
		MylarTaskListPlugin.getTaskListManager().getTaskList().addCategory(cat);
57
		this.view.getViewer().refresh();
58
	}
51
}
59
}
(-)src/org/eclipse/mylar/internal/tasklist/ui/actions/MarkTaskCompleteAction.java (-2 / +14 lines)
Lines 19-25 Link Here
19
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
19
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
20
20
21
/**
21
/**
22
 * @author Mik Kersten
22
 * @author Mik Kersten and Izzet Safer
23
 */
23
 */
24
public class MarkTaskCompleteAction extends Action {
24
public class MarkTaskCompleteAction extends Action {
25
25
Lines 27-32 Link Here
27
27
28
	private final TaskListView view;
28
	private final TaskListView view;
29
29
30
	public MarkTaskCompleteAction() {
31
		this(TaskListView.getFromActivePerspective());
32
	}
33
30
	public MarkTaskCompleteAction(TaskListView view) {
34
	public MarkTaskCompleteAction(TaskListView view) {
31
		this.view = view;
35
		this.view = view;
32
		setText("Mark Complete");
36
		setText("Mark Complete");
Lines 39-46 Link Here
39
	public void run() {
43
	public void run() {
40
		for (Object selectedObject : ((IStructuredSelection) this.view.getViewer().getSelection()).toList()) {
44
		for (Object selectedObject : ((IStructuredSelection) this.view.getViewer().getSelection()).toList()) {
41
			if (selectedObject instanceof ITask) {
45
			if (selectedObject instanceof ITask) {
42
				MylarTaskListPlugin.getTaskListManager().getTaskList().markComplete(((ITask) selectedObject), true);
46
				markComplete((ITask)selectedObject);
43
			}
47
			}
44
		}
48
		}
45
	}
49
	}
50
	
51
	public void run(ITask task) {
52
		markComplete(task);
53
	}
54
	
55
	private void markComplete(ITask task) {
56
		MylarTaskListPlugin.getTaskListManager().getTaskList().markComplete(task, true);
57
	}
46
}
58
}
(-)src/org/eclipse/mylar/internal/tasklist/ui/actions/NewLocalTaskAction.java (-31 / +70 lines)
Lines 21-26 Link Here
21
import org.eclipse.mylar.internal.tasklist.ui.TaskUiUtil;
21
import org.eclipse.mylar.internal.tasklist.ui.TaskUiUtil;
22
import org.eclipse.mylar.internal.tasklist.ui.views.TaskInputDialog;
22
import org.eclipse.mylar.internal.tasklist.ui.views.TaskInputDialog;
23
import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView;
23
import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView;
24
import org.eclipse.mylar.provisional.tasklist.AbstractTaskContainer;
24
import org.eclipse.mylar.provisional.tasklist.ITask;
25
import org.eclipse.mylar.provisional.tasklist.ITask;
25
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
26
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
26
import org.eclipse.mylar.provisional.tasklist.Task;
27
import org.eclipse.mylar.provisional.tasklist.Task;
Lines 28-34 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
Lines 38-43 Link Here
38
39
39
	private final TaskListView view;
40
	private final TaskListView view;
40
41
42
	private Task newTask;
43
	
44
	public NewLocalTaskAction() {
45
		this(TaskListView.getFromActivePerspective());
46
	}
47
41
	public NewLocalTaskAction(TaskListView view) {
48
	public NewLocalTaskAction(TaskListView view) {
42
		this.view = view;
49
		this.view = view;
43
		setText(TaskInputDialog.LABEL_SHELL);
50
		setText(TaskInputDialog.LABEL_SHELL);
Lines 47-97 Link Here
47
	}
54
	}
48
55
49
	@Override
56
	@Override
50
	public void run() {
57
	public void run() {	
51
		Task newTask = new Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(), DESCRIPTION_DEFAULT, true);
58
		String taskHandle = MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle();
52
//		newTask.setUrl(getDefaultIssueURL());
59
		AbstractTaskContainer category = null;		
53
		
60
		
54
		Calendar reminderCalendar = GregorianCalendar.getInstance();
61
		boolean showWarning = false;
55
		MylarTaskListPlugin.getTaskListManager().setScheduledToday(reminderCalendar);
56
		MylarTaskListPlugin.getTaskListManager().setReminder(newTask, reminderCalendar.getTime());
57
58
		Object selectedObject = ((IStructuredSelection) view.getViewer().getSelection()).getFirstElement();
62
		Object selectedObject = ((IStructuredSelection) view.getViewer().getSelection()).getFirstElement();
59
63
		
60
		if (selectedObject instanceof TaskCategory) {
64
		if (selectedObject instanceof TaskCategory) {
61
			MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask, (TaskCategory) selectedObject);
65
			category = (TaskCategory) selectedObject;
62
		} else if (selectedObject instanceof ITask) {
66
		} else if (selectedObject instanceof ITask) {
63
			ITask task = (ITask) selectedObject;
67
			ITask task = (ITask) selectedObject;
64
			if (task.getContainer() instanceof TaskCategory) {
68
			if (task.getContainer() instanceof TaskCategory) {
65
				MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask,
69
				category = (TaskCategory) task.getContainer();
66
						(TaskCategory) task.getContainer());
67
			} else if (view.getDrilledIntoCategory() instanceof TaskCategory) {
70
			} else if (view.getDrilledIntoCategory() instanceof TaskCategory) {
68
				MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask,
71
				category = (TaskCategory) view.getDrilledIntoCategory();
69
						(TaskCategory) view.getDrilledIntoCategory());
70
			} else {
72
			} else {
71
				MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask,
73
				category = MylarTaskListPlugin.getTaskListManager().getTaskList().getRootCategory();
72
						MylarTaskListPlugin.getTaskListManager().getTaskList().getRootCategory());
73
				// MylarTaskListPlugin.getTaskListManager().getTaskList().moveToRoot(newTask);
74
			}
74
			}
75
		} else if (view.getDrilledIntoCategory() instanceof TaskCategory) {
75
		} else if (view.getDrilledIntoCategory() instanceof TaskCategory) {
76
			MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask,
76
			category = (TaskCategory) view.getDrilledIntoCategory();
77
					(TaskCategory) view.getDrilledIntoCategory());
78
		} else {
77
		} else {
79
			if (view.getDrilledIntoCategory() != null) {
78
			showWarning = true;
80
				MessageDialog.openInformation(Display.getCurrent().getActiveShell(), MylarTaskListPlugin.TITLE_DIALOG, 
79
			category = MylarTaskListPlugin.getTaskListManager().getTaskList().getRootCategory();
81
						"The new task has been added to the root of the list, since tasks can not be added to a query.");
82
			}
83
			MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask,
84
					MylarTaskListPlugin.getTaskListManager().getTaskList().getRootCategory());
85
		}
80
		}
86
		TaskUiUtil.openEditor(newTask, true);
81
				
87
		// newTask.openTaskInEditor(false);
82
		addNewLocalTask(taskHandle, DESCRIPTION_DEFAULT, category, true, showWarning);
88
		view.getViewer().refresh();
83
	}
84
	
85
	public void run(String taskHandle, String taskName, String categoryName) {		
86
		if (taskHandle == null || taskHandle.equals("")) 
87
			taskHandle = MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle();
88
		
89
		AbstractTaskContainer category = null; 
90
		if (categoryName == null || categoryName.equals("")) {
91
			category = MylarTaskListPlugin.getTaskListManager().getTaskList().getRootCategory();
92
		}
93
		else {
94
			category = MylarTaskListPlugin.getTaskListManager().getTaskList().getContainerForHandle(categoryName.toString());	
95
			if (category == null) {
96
				// the category is not found, create it by calling NewCategoryAction
97
				NewCategoryAction action = new NewCategoryAction(this.view);
98
				action.run(categoryName.toString());
99
				category = MylarTaskListPlugin.getTaskListManager().getTaskList().getContainerForHandle(categoryName.toString());
100
			}			
101
		}
102
		
103
		addNewLocalTask(taskHandle, taskName, category, false, false);
104
	}
105
106
	private void addNewLocalTask(String taskHandle, String taskName, AbstractTaskContainer category, boolean edit, boolean showMessage) {
107
		newTask = new Task(taskHandle, taskName, true);
108
//		newTask.setUrl(getDefaultIssueURL());
109
		
110
		Calendar reminderCalendar = GregorianCalendar.getInstance();
111
		MylarTaskListPlugin.getTaskListManager().setScheduledToday(reminderCalendar);
112
		MylarTaskListPlugin.getTaskListManager().setReminder(newTask, reminderCalendar.getTime());
89
113
114
		if (showMessage) {
115
			MessageDialog.openInformation(Display.getCurrent().getActiveShell(), MylarTaskListPlugin.TITLE_DIALOG, 
116
					"The new task has been added to the root of the list, since tasks can not be added to a query.");
117
		}
118
		MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask, category);
90
		
119
		
91
		view.setInRenameAction(true);
120
		view.getViewer().refresh();
92
		view.getViewer().editElement(newTask, 4);
121
93
		view.setInRenameAction(false);
122
		if (edit) {
123
			TaskUiUtil.openEditor(newTask, true);
124
			// newTask.openTaskInEditor(false);
125
			view.setInRenameAction(true);
126
			view.getViewer().editElement(newTask, 4);
127
			view.setInRenameAction(false);
128
		}
94
//		view.getViewer().setSelection(new StructuredSelection(newTask));
129
//		view.getViewer().setSelection(new StructuredSelection(newTask));
95
		// }
130
		// }
96
	}
131
	}
132
	
133
	public ITask getNewTask() {
134
		return newTask;
135
	}
97
}
136
}
(-)src/org/eclipse/mylar/internal/tasklist/ui/commands/NewLocalSubTaskHandler.java (+100 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasklist.ui.commands;
2
3
import java.util.Collection;
4
import java.util.Map;
5
6
import org.eclipse.core.commands.AbstractHandler;
7
import org.eclipse.core.commands.ExecutionEvent;
8
import org.eclipse.core.commands.ExecutionException;
9
import org.eclipse.mylar.internal.tasklist.ui.actions.MarkTaskIncompleteAction;
10
import org.eclipse.mylar.internal.tasklist.ui.actions.NewLocalSubTaskAction;
11
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskActivateAction;
12
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskDeactivateAction;
13
import org.eclipse.mylar.provisional.core.MylarPlugin;
14
import org.eclipse.mylar.provisional.tasklist.ITask;
15
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
16
17
/**
18
 * @author Izzet Safer
19
 */
20
public class NewLocalSubTaskHandler extends AbstractHandler {
21
22
	private static final String PARAMETER_TASK_NAME_ID = "taskName"; //$NON-NLS-1$
23
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
24
	private static final String PARAMETER_PARENT_HANDLE_ID = "parentHandle"; //$NON-NLS-1$
25
	private static final String PARAMETER_ACTIVATE_TASK_ID = "activateTask"; //$NON-NLS-1$
26
	private static final String PARAMETER_RESET_CONTEXT_ID = "resetContext"; //$NON-NLS-1$
27
		
28
	private NewLocalSubTaskAction newAction = null; 
29
	private TaskActivateAction activateAction = null;
30
	private TaskDeactivateAction deactivateAction = null;
31
	private MarkTaskIncompleteAction incompleteAction = null;
32
	
33
	public NewLocalSubTaskHandler () {
34
		newAction = new NewLocalSubTaskAction();
35
		activateAction = new TaskActivateAction();
36
		deactivateAction = new TaskDeactivateAction();
37
		incompleteAction = new MarkTaskIncompleteAction();
38
	}
39
	
40
	@Override
41
	public Object execute(ExecutionEvent event) throws ExecutionException {
42
		Object returnValue = null;
43
		final Map parameters = event.getParameters();
44
45
		final Object taskName = parameters.get(PARAMETER_TASK_NAME_ID);
46
		// if task handle is not null and a task with that handle already exists, 
47
		// that task will be used and no new task will be created
48
		final Object taskHandle = parameters.get(PARAMETER_TASK_HANDLE_ID);
49
50
		final Object parentHandle = parameters.get(PARAMETER_PARENT_HANDLE_ID);
51
		
52
		final boolean activateTask = parameters.get(PARAMETER_ACTIVATE_TASK_ID) == null ? true 
53
				: Boolean.parseBoolean((String)parameters.get(PARAMETER_ACTIVATE_TASK_ID));
54
55
		// delete the context associated with the task if an existing task is used
56
		final boolean resetContext = parameters.get(PARAMETER_RESET_CONTEXT_ID) == null ? true 
57
				: Boolean.parseBoolean((String)parameters.get(PARAMETER_RESET_CONTEXT_ID));
58
59
		if (taskName == null || parentHandle == null) {
60
			return returnValue;
61
		} else {
62
			ITask newSubTask = null;
63
			if (taskHandle != null) {
64
				Collection<ITask> allTasks = MylarTaskListPlugin.getTaskListManager().getTaskList().getAllTasks();
65
				newSubTask = findSubtaskWithHandle(allTasks, (String)taskHandle);
66
				if (newSubTask != null && resetContext) {
67
					//TODO: do this using ContextClearAction
68
					MylarPlugin.getContextManager().deleteContext(newSubTask.getHandleIdentifier());
69
					//TODO: call DeleteAction to delete the subtasks of this task, or just
70
					//delete subtasks' context
71
					//newTask.getChildren().clear();
72
					incompleteAction.run(newSubTask);
73
				}
74
			}
75
			
76
			if (newSubTask == null) {			
77
				newAction.run(taskHandle == null ? "" : (String)taskHandle, 
78
						(String)taskName, (String)parentHandle);			
79
				newSubTask = newAction.getNewSubTask();
80
			}
81
			
82
			// fail.. no new sub task created
83
			if (newSubTask == null) return returnValue;
84
			
85
			if (activateTask) activateAction.run(newSubTask);
86
			else deactivateAction.run(newSubTask);
87
			
88
		}
89
		
90
		return returnValue;
91
	}
92
	
93
	private ITask findSubtaskWithHandle(Collection<ITask> tasks, String taskHandle) {
94
		for (ITask t : tasks) {
95
			if (t.getHandleIdentifier().equals(taskHandle)) return t;
96
			findSubtaskWithHandle(t.getChildren(), taskHandle);
97
		}
98
		return null;
99
	}
100
}
(-)src/org/eclipse/mylar/internal/tasklist/ui/commands/NewLocalTaskHandler.java (+92 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasklist.ui.commands;
2
3
import java.util.Map;
4
5
import org.eclipse.core.commands.AbstractHandler;
6
import org.eclipse.core.commands.ExecutionEvent;
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.mylar.internal.tasklist.ui.actions.MarkTaskIncompleteAction;
9
import org.eclipse.mylar.internal.tasklist.ui.actions.NewLocalTaskAction;
10
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskActivateAction;
11
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskDeactivateAction;
12
import org.eclipse.mylar.provisional.core.MylarPlugin;
13
import org.eclipse.mylar.provisional.tasklist.ITask;
14
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
15
16
/**
17
 * @author Izzet Safer
18
 */
19
public class NewLocalTaskHandler extends AbstractHandler {
20
21
	private static final String PARAMETER_TASK_NAME_ID = "taskName"; //$NON-NLS-1$
22
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
23
	private static final String PARAMETER_CATEGORY_NAME_ID = "categoryName"; //$NON-NLS-1$
24
	private static final String PARAMETER_ACTIVATE_TASK_ID = "activateTask"; //$NON-NLS-1$
25
	private static final String PARAMETER_RESET_CONTEXT_ID = "resetContext"; //$NON-NLS-1$
26
		
27
	private NewLocalTaskAction newAction = null; 
28
	private TaskActivateAction activateAction = null;
29
	private TaskDeactivateAction deactivateAction = null;
30
	private MarkTaskIncompleteAction incompleteAction = null;
31
	
32
	public NewLocalTaskHandler () {
33
		newAction = new NewLocalTaskAction();
34
		activateAction = new TaskActivateAction();
35
		deactivateAction = new TaskDeactivateAction();
36
		incompleteAction = new MarkTaskIncompleteAction();
37
	}
38
	
39
	@Override
40
	public Object execute(ExecutionEvent event) throws ExecutionException {
41
		Object returnValue = null;
42
		final Map parameters = event.getParameters();
43
44
		final Object taskName = parameters.get(PARAMETER_TASK_NAME_ID);
45
		// if task handle is not null and a task with that handle already exists, 
46
		// that task will be used and no new task will be created
47
		final Object taskHandle = parameters.get(PARAMETER_TASK_HANDLE_ID);
48
49
		// use root when null
50
		final Object categoryName = parameters.get(PARAMETER_CATEGORY_NAME_ID);
51
		
52
		final boolean activateTask = parameters.get(PARAMETER_ACTIVATE_TASK_ID) == null ? true 
53
				: Boolean.parseBoolean((String)parameters.get(PARAMETER_ACTIVATE_TASK_ID));
54
55
		// delete the context associated with the task if an existing task is used
56
		final boolean resetContext = parameters.get(PARAMETER_RESET_CONTEXT_ID) == null ? true 
57
				: Boolean.parseBoolean((String)parameters.get(PARAMETER_RESET_CONTEXT_ID));
58
	
59
		if (taskName == null) {
60
			return returnValue;
61
		} else {
62
			ITask newTask = null;
63
			if (taskHandle != null) {
64
				newTask = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask((String)taskHandle);
65
				if (newTask != null && resetContext) {
66
					//TODO: do this using ContextClearAction
67
					MylarPlugin.getContextManager().deleteContext(newTask.getHandleIdentifier());
68
					//TODO: call DeleteAction to delete the subtasks of this task, or just
69
					//delete subtasks' context
70
					//newTask.getChildren().clear();
71
					incompleteAction.run(newTask);
72
				}
73
			}
74
			
75
			if (newTask == null) {			
76
				newAction.run(taskHandle == null ? "" : (String)taskHandle, 
77
						(String)taskName, 
78
						categoryName == null ? "" : (String)categoryName);			
79
				newTask = newAction.getNewTask();
80
			}
81
			
82
			// fail.. no new task created
83
			if (newTask == null) return returnValue;
84
			
85
			if (activateTask) activateAction.run(newTask);
86
			else deactivateAction.run(newTask);
87
			
88
		}
89
		
90
		return returnValue;
91
	}
92
}
(-)src/org/eclipse/mylar/internal/tasklist/ui/commands/MarkTaskCompleteHandler.java (+55 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasklist.ui.commands;
2
3
4
5
import java.util.Map;
6
7
import org.eclipse.core.commands.AbstractHandler;
8
import org.eclipse.core.commands.ExecutionEvent;
9
import org.eclipse.core.commands.ExecutionException;
10
import org.eclipse.mylar.internal.tasklist.ui.actions.MarkTaskCompleteAction;
11
import org.eclipse.mylar.internal.tasklist.ui.actions.MarkTaskIncompleteAction;
12
import org.eclipse.mylar.provisional.tasklist.ITask;
13
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
14
15
/**
16
 * @author Izzet Safer
17
 */
18
public class MarkTaskCompleteHandler extends AbstractHandler {
19
20
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
21
	private static final String PARAMETER_COMPLETE_TASK_ID = "completeTask"; //$NON-NLS-1$
22
23
	private MarkTaskCompleteAction completeAction = null;
24
	private MarkTaskIncompleteAction incompleteAction = null;
25
	
26
	public MarkTaskCompleteHandler() {
27
		completeAction = new MarkTaskCompleteAction();
28
		incompleteAction = new MarkTaskIncompleteAction();		
29
	}
30
	
31
	@Override
32
	public Object execute(ExecutionEvent event) throws ExecutionException {
33
		final Map parameters = event.getParameters();
34
		final Object taskHandle = parameters.get(PARAMETER_TASK_HANDLE_ID);
35
		
36
		final boolean completeTask = parameters.get(PARAMETER_COMPLETE_TASK_ID) == null ? true 
37
				: Boolean.parseBoolean((String)parameters.get(PARAMETER_COMPLETE_TASK_ID));
38
	
39
		if (taskHandle == null) {
40
			return null;
41
		} else {			
42
			ITask task = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(taskHandle.toString());
43
			if (task != null) {
44
				if (completeTask) {
45
					completeAction.run(task);
46
				}
47
				else {
48
					incompleteAction.run(task);
49
				}
50
			}
51
			
52
			return Boolean.valueOf(completeTask).toString();
53
		}
54
	}
55
}
(-)src/org/eclipse/mylar/internal/tasklist/ui/actions/NewLocalSubTaskAction.java (+115 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia 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
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.tasklist.ui.actions;
13
14
import java.util.Calendar;
15
import java.util.GregorianCalendar;
16
17
import org.eclipse.jface.action.Action;
18
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.mylar.internal.tasklist.ui.TaskListImages;
21
import org.eclipse.mylar.internal.tasklist.ui.TaskUiUtil;
22
import org.eclipse.mylar.internal.tasklist.ui.views.TaskInputDialog;
23
import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView;
24
import org.eclipse.mylar.provisional.tasklist.ITask;
25
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
26
import org.eclipse.mylar.provisional.tasklist.Task;
27
import org.eclipse.swt.widgets.Display;
28
29
/**
30
 * @author Izzet Safer
31
 */
32
public class NewLocalSubTaskAction extends Action {
33
34
	public static final String DESCRIPTION_DEFAULT = "new subtask";
35
36
	public static final String ID = "org.eclipse.mylar.tasklist.actions.create.subtask";
37
38
	private final TaskListView view;
39
40
	private Task newSubTask;
41
	
42
	public NewLocalSubTaskAction() {
43
		this(TaskListView.getFromActivePerspective());
44
	}
45
46
	public NewLocalSubTaskAction(TaskListView view) {
47
		this.view = view;
48
		setText(TaskInputDialog.LABEL_SHELL);			//TODO change
49
		setToolTipText(TaskInputDialog.LABEL_SHELL); 	//TODO change
50
		setId(ID);
51
		setImageDescriptor(TaskListImages.TASK_NEW);
52
	}
53
54
	@Override
55
	public void run() {	
56
		String taskHandle = MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle();
57
		ITask parentTask = null; 
58
				
59
		//! allows infinite level of nesting, adding a subtask to another subtask is ok
60
		Object selectedObject = ((IStructuredSelection) view.getViewer().getSelection()).getFirstElement();
61
		
62
		if (selectedObject instanceof ITask) {
63
			parentTask = (ITask) selectedObject;		
64
		} else {
65
			MessageDialog.openInformation(Display.getCurrent().getActiveShell(), MylarTaskListPlugin.TITLE_DIALOG, 
66
					"The new subtask cannot be added to a category, please choose a task.");
67
			newSubTask = null;
68
			return;
69
		}
70
71
		addNewLocalSubTask(taskHandle, DESCRIPTION_DEFAULT, parentTask, true);
72
	}
73
	
74
	public void run(String taskHandle, String taskName, String parentHandle) {		
75
		if (taskHandle == null || taskHandle.equals("")) 
76
			taskHandle = MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle();
77
	 		
78
		if (parentHandle == null || parentHandle.equals("")) {
79
			newSubTask = null;
80
			return;
81
		}
82
83
		ITask parentTask = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(parentHandle);
84
		if (parentTask == null) return;	
85
		
86
		addNewLocalSubTask(taskHandle, taskName, parentTask, false);
87
	}
88
89
	private void addNewLocalSubTask(String taskHandle, String taskName, ITask parentTask, boolean edit) {
90
		newSubTask = new Task(taskHandle, taskName, true);
91
//		newTask.setUrl(getDefaultIssueURL());
92
		
93
		Calendar reminderCalendar = GregorianCalendar.getInstance();
94
		MylarTaskListPlugin.getTaskListManager().setScheduledToday(reminderCalendar);
95
		MylarTaskListPlugin.getTaskListManager().setReminder(newSubTask, reminderCalendar.getTime());
96
97
		parentTask.addSubTask(newSubTask);
98
		
99
		view.getViewer().refresh();
100
101
		if (edit) {
102
			TaskUiUtil.openEditor(newSubTask, true);
103
			// newTask.openTaskInEditor(false);
104
			view.setInRenameAction(true);
105
			view.getViewer().editElement(newSubTask, 4);
106
			view.setInRenameAction(false);
107
		}
108
//		view.getViewer().setSelection(new StructuredSelection(newTask));
109
		// }	
110
	}
111
	
112
	public ITask getNewSubTask() {
113
		return newSubTask;
114
	}
115
}
(-)src/org/eclipse/mylar/internal/tasklist/ui/commands/TaskActivateHandler.java (+55 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasklist.ui.commands;
2
3
4
5
import java.util.Map;
6
7
import org.eclipse.core.commands.AbstractHandler;
8
import org.eclipse.core.commands.ExecutionEvent;
9
import org.eclipse.core.commands.ExecutionException;
10
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskActivateAction;
11
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskDeactivateAction;
12
import org.eclipse.mylar.provisional.tasklist.ITask;
13
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
14
15
/**
16
 * @author Izzet Safer
17
 */
18
public class TaskActivateHandler extends AbstractHandler {
19
20
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
21
	private static final String PARAMETER_ACTIVATE_TASK_ID = "activateTask"; //$NON-NLS-1$
22
23
	private TaskActivateAction activateAction = null;
24
	private TaskDeactivateAction deactivateAction = null;
25
	
26
	public TaskActivateHandler() {
27
		activateAction = new TaskActivateAction();
28
		deactivateAction = new TaskDeactivateAction();		
29
	}
30
	
31
	@Override
32
	public Object execute(ExecutionEvent event) throws ExecutionException {
33
		final Map parameters = event.getParameters();
34
		final Object taskHandle = parameters.get(PARAMETER_TASK_HANDLE_ID);
35
36
		final boolean activateTask = parameters.get(PARAMETER_ACTIVATE_TASK_ID) == null ? true 
37
				: Boolean.parseBoolean((String)parameters.get(PARAMETER_ACTIVATE_TASK_ID));
38
	
39
		if (taskHandle == null) {
40
			return null;
41
		} else {			
42
			ITask task = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(taskHandle.toString());
43
			if (task != null) {
44
				if (activateTask) {
45
					activateAction.run(task);
46
				}
47
				else {
48
					deactivateAction.run(task);
49
				}
50
			}		
51
			
52
			return Boolean.valueOf(activateTask).toString();
53
		}
54
	}
55
}

Return to bug 145884