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

(-)src/org/eclipse/mylar/tasks/core/TaskList.java (-2 / +37 lines)
Lines 422-429 Link Here
422
	}
422
	}
423
423
424
	public ITask getTask(String handleIdentifier) {
424
	public ITask getTask(String handleIdentifier) {
425
		return tasks.get(handleIdentifier);
425
		return tasks.get(handleIdentifier);		
426
	}
426
	}
427
428
	//IZZET		
429
	/** Acts as getTask for regular tasks. If the task with 
430
	 * given handle is not found, then look for subTasks
431
	 */
432
	public ITask findTask(String handleIdentifier) {
433
		ITask task = getTask(handleIdentifier);
434
		if (task != null) return task;
435
				
436
		foundTask = null; 
437
		findSubtask(getAllTasks(), handleIdentifier);
438
		return foundTask;
439
	}
440
	
441
	//this shouldn't be used other than findTask and findSubtask
442
	private ITask foundTask = null; 
443
	
444
	/** Temporary solution to find a subtask. Looks for infinite depth. 
445
	 * If the taskHandle matches a task rather than a subTask, 
446
	 * that's a valid match too
447
	 * 
448
	 * @param tasks Collection of tasks to be looked for their children
449
	 * @param taskHandle
450
	 */
451
	private void findSubtask(Collection<ITask> tasks, String taskHandle) {		
452
		for (ITask t : tasks) {
453
			if (foundTask != null) return;
454
			if (t.getHandleIdentifier().equals(taskHandle)) {
455
				foundTask = t;
456
				continue;
457
			}
458
			else findSubtask(t.getChildren(), taskHandle);
459
		}
460
	}
461
	//IZZET	
427
	
462
	
428
	public AbstractTaskContainer getContainerForHandle(String categoryHandle) {
463
	public AbstractTaskContainer getContainerForHandle(String categoryHandle) {
429
		for (AbstractTaskContainer cat : categories) {
464
		for (AbstractTaskContainer cat : categories) {
Lines 547-550 Link Here
547
			}
582
			}
548
		}
583
		}
549
	}
584
	}
550
}
585
}
(-)plugin.xml (+125 lines)
Lines 473-479 Link Here
473
             type="task"/>
473
             type="task"/>
474
    </extension>-->
474
    </extension>-->
475
475
476
  	<extension point="org.eclipse.ui.handlers">
477
		<handler
478
			commandId="org.eclipse.mylar.tasklist.commands.addNewLocalTask"
479
			class="org.eclipse.mylar.internal.tasks.ui.commands.NewLocalTaskHandler">
480
		</handler>		
481
		
482
		<handler
483
			commandId="org.eclipse.mylar.tasklist.commands.addNewLocalSubTask"
484
			class="org.eclipse.mylar.internal.tasks.ui.commands.NewLocalSubTaskHandler">
485
		</handler>		
486
487
		<handler
488
			commandId="org.eclipse.mylar.tasklist.commands.activateTask"
489
			class="org.eclipse.mylar.internal.tasks.ui.commands.TaskActivateHandler">
490
		</handler>		
491
492
		<handler
493
			commandId="org.eclipse.mylar.tasklist.commands.deactivateTask"
494
			class="org.eclipse.mylar.internal.tasks.ui.commands.TaskDeactivateHandler">
495
		</handler>		
496
497
		<handler
498
			commandId="org.eclipse.mylar.tasklist.commands.completeTask"
499
			class="org.eclipse.mylar.internal.tasks.ui.commands.MarkTaskCompleteHandler">
500
		</handler>		
501
502
		<handler
503
			commandId="org.eclipse.mylar.tasklist.commands.incompleteTask"
504
			class="org.eclipse.mylar.internal.tasks.ui.commands.MarkTaskIncompleteHandler">
505
		</handler>		
506
    </extension>
476
  
507
  
508
  	<extension point="org.eclipse.ui.commands">
509
		<command 
510
			description="Add new Mylar Task"
511
			id="org.eclipse.mylar.tasklist.commands.addNewLocalTask"
512
			name="Add new Mylar Task">
513
			<commandParameter 
514
				id="taskName" 
515
				name="Task Name"
516
				optional="false"/>
517
			<commandParameter 
518
				id="taskHandle" 
519
				name="Unique Task Handle"
520
				optional="true"/>
521
			<commandParameter 
522
				id="categoryName" 
523
				name="Category Name"
524
				optional="true"/>
525
			<commandParameter 
526
				id="activateTask" 
527
				name="Boolean parameter to activate the task"
528
				optional="true"/>
529
			<commandParameter 
530
				id="resetContext" 
531
				name="Boolean parameter to delete the context of the existing task"
532
				optional="true"/>
533
		</command>
534
	
535
		<command 
536
			description="Add new Mylar Subtask"
537
			id="org.eclipse.mylar.tasklist.commands.addNewLocalSubTask"
538
			name="Add new Mylar Subtask">
539
			<commandParameter 
540
				id="taskName" 
541
				name="Subtask Name"
542
				optional="false"/>
543
			<commandParameter 
544
				id="taskHandle" 
545
				name="Unique Task Handle"
546
				optional="true"/>
547
			<commandParameter 
548
				id="parentHandle" 
549
				name="Handle to parent task"
550
				optional="false"/>
551
			<commandParameter 
552
				id="activateTask" 
553
				name="Boolean parameter to activate the subtask"
554
				optional="true"/>
555
			<commandParameter 
556
				id="resetContext" 
557
				name="Boolean parameter to delete the context of the existing subtask"
558
				optional="true"/>
559
		</command>
560
561
		<command 
562
			description="Activate a Mylar task"
563
			id="org.eclipse.mylar.tasklist.commands.activateTask"
564
			name="Activate a Mylar task">			
565
			<commandParameter 
566
				id="taskHandle" 
567
				name="Unique Task Handle"
568
				optional="false"/>
569
		</command>
570
571
		<command 
572
			description="Deactivate a Mylar task"
573
			id="org.eclipse.mylar.tasklist.commands.deactivateTask"
574
			name="Deactivate a Mylar task">			
575
			<commandParameter 
576
				id="taskHandle" 
577
				name="Unique Task Handle"
578
				optional="false"/>
579
		</command>
580
581
		<command 
582
			description="Mark Complete a Mylar task"
583
			id="org.eclipse.mylar.tasklist.commands.completeTask"
584
			name="Complete a Mylar task">			
585
			<commandParameter 
586
				id="taskHandle" 
587
				name="Unique Task Handle"
588
				optional="false"/>
589
		</command>
590
591
		<command 
592
			description="Mark Incomplete a Mylar task"
593
			id="org.eclipse.mylar.tasklist.commands.incompleteTask"
594
			name="Incomplete a Mylar task">			
595
			<commandParameter 
596
				id="taskHandle" 
597
				name="Unique Task Handle"
598
				optional="false"/>
599
		</command>
600
    </extension>
601
    		  
477
</plugin>
602
</plugin>
478
603
479
604
Lines 486-489 Link Here
486
	  		class="org.eclipse.mylar.tasklist.ui.actions.GoIntoAction"
611
	  		class="org.eclipse.mylar.tasklist.ui.actions.GoIntoAction"
487
	  		icon="icons/etool16/go-into.gif"
612
	  		icon="icons/etool16/go-into.gif"
488
	  		enablesFor="1"/>
613
	  		enablesFor="1"/>
(-)src/org/eclipse/mylar/internal/tasks/ui/actions/MarkTaskIncompleteAction.java (-2 / +14 lines)
Lines 19-25 Link Here
19
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
19
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
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
				TasksUiPlugin.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
		TasksUiPlugin.getTaskListManager().getTaskList().markComplete(task, false);
57
	}
46
}
58
}
(-)src/org/eclipse/mylar/internal/tasks/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(), TasksUiPlugin.getTaskListManager().getTaskList());
46
			addCategory(dialog.getValue());
47
			TasksUiPlugin.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, TasksUiPlugin.getTaskListManager().getTaskList());
56
		TasksUiPlugin.getTaskListManager().getTaskList().addCategory(cat);
57
		this.view.getViewer().refresh();
58
	}
51
}
59
}
(-)src/org/eclipse/mylar/internal/tasks/ui/actions/NewLocalTaskAction.java (-28 / +66 lines)
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
}
(-)src/org/eclipse/mylar/internal/tasks/ui/actions/MarkTaskCompleteAction.java (-2 / +14 lines)
Lines 19-31 Link Here
19
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
19
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
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
26
	public static final String ID = "org.eclipse.mylar.tasklist.actions.mark.completed";
26
	public static final String ID = "org.eclipse.mylar.tasklist.actions.mark.completed";
27
27
28
	private final TaskListView view;
28
	private final TaskListView view;
29
	
30
	public MarkTaskCompleteAction() {
31
		this(TaskListView.getFromActivePerspective());
32
	}
29
33
30
	public MarkTaskCompleteAction(TaskListView view) {
34
	public MarkTaskCompleteAction(TaskListView view) {
31
		this.view = view;
35
		this.view = view;
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
				TasksUiPlugin.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
		TasksUiPlugin.getTaskListManager().getTaskList().markComplete(task, true);
57
	}
46
}
58
}
(-)src/org/eclipse/mylar/internal/tasks/ui/commands/NewLocalSubTaskHandler.java (+97 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasks.ui.commands;
2
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.mylar.context.core.ContextCorePlugin;
7
import org.eclipse.mylar.internal.tasks.ui.actions.MarkTaskIncompleteAction;
8
import org.eclipse.mylar.internal.tasks.ui.actions.NewLocalSubTaskAction;
9
import org.eclipse.mylar.internal.tasks.ui.actions.TaskActivateAction;
10
import org.eclipse.mylar.internal.tasks.ui.actions.TaskDeactivateAction;
11
import org.eclipse.mylar.internal.tasks.ui.views.TaskListView;
12
import org.eclipse.mylar.tasks.core.ITask;
13
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
14
15
/**
16
 * @author Izzet Safer
17
 */
18
public class NewLocalSubTaskHandler extends AbstractHandler {
19
20
	private static final String PARAMETER_TASK_NAME_ID = "taskName"; //$NON-NLS-1$
21
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
22
	private static final String PARAMETER_PARENT_HANDLE_ID = "parentHandle"; //$NON-NLS-1$
23
	private static final String PARAMETER_ACTIVATE_TASK_ID = "activateTask"; //$NON-NLS-1$
24
	private static final String PARAMETER_RESET_CONTEXT_ID = "resetContext"; //$NON-NLS-1$
25
		
26
	private static final boolean activateTaskDefault = true;
27
	private static final boolean resetContextDefault = true;
28
29
	private NewLocalSubTaskAction newAction = null; 
30
	private TaskActivateAction activateAction = null;
31
	private TaskDeactivateAction deactivateAction = null;
32
	private MarkTaskIncompleteAction incompleteAction = null;
33
	
34
	public NewLocalSubTaskHandler () {
35
		newAction = new NewLocalSubTaskAction();
36
		activateAction = new TaskActivateAction();
37
		deactivateAction = new TaskDeactivateAction();
38
		incompleteAction = new MarkTaskIncompleteAction();
39
	}
40
	
41
	public Object execute(ExecutionEvent event) throws ExecutionException {
42
		Object returnValue = null;
43
44
		final String taskName = event.getParameter(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 String taskHandle = event.getParameter(PARAMETER_TASK_HANDLE_ID);
48
49
		final String parentHandle = event.getParameter(PARAMETER_PARENT_HANDLE_ID);
50
		
51
		final boolean activateTask = event.getParameter(PARAMETER_ACTIVATE_TASK_ID) == null ? activateTaskDefault 
52
				: Boolean.parseBoolean(event.getParameter(PARAMETER_ACTIVATE_TASK_ID));
53
54
		// delete the context associated with the task if an existing task is used
55
		final boolean resetContext = event.getParameter(PARAMETER_RESET_CONTEXT_ID) == null ? resetContextDefault 
56
				: Boolean.parseBoolean(event.getParameter(PARAMETER_RESET_CONTEXT_ID));
57
		
58
		if (taskName == null || parentHandle == null) {
59
			return returnValue;
60
		} else {
61
62
			/*
63
			MessageDialog.openInformation(Display.getCurrent().getActiveShell(), TasksUiPlugin.TITLE_DIALOG, 
64
					"New Subtask with " + taskHandle + ", " + parentHandle);
65
			*/
66
			
67
			ITask newSubTask = null;
68
			if (taskHandle != null) {
69
				newSubTask = TasksUiPlugin.getTaskListManager().getTaskList().findTask((String)taskHandle);				
70
				if (newSubTask != null && resetContext) {
71
					//TODO: do this using ContextClearAction
72
					ContextCorePlugin.getContextManager().deleteContext(newSubTask.getHandleIdentifier());
73
					//TODO: call DeleteAction to delete the subtasks of this task, or just
74
					//delete subtasks' context
75
					newSubTask.getChildren().clear();
76
					incompleteAction.run(newSubTask);				
77
				}				
78
			}
79
			
80
			if (newSubTask == null) {			
81
				newSubTask = newAction.run(taskHandle == null ? "" : taskHandle, 
82
						taskName, parentHandle);	
83
			}
84
			
85
			returnValue = (newSubTask == null) ? null : newSubTask.getHandleIdentifier();
86
			
87
			if (activateTask) activateAction.run(newSubTask);
88
			else deactivateAction.run(newSubTask);		
89
		}
90
		
91
		try {
92
			TaskListView.getFromActivePerspective().getViewer().refresh();
93
		} catch (Exception ex) {}
94
		
95
		return returnValue;
96
	}	
97
}
(-)src/org/eclipse/mylar/internal/tasks/ui/commands/TaskActivateHandler.java (+39 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasks.ui.commands;
2
3
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.tasks.ui.actions.TaskActivateAction;
9
import org.eclipse.mylar.tasks.core.ITask;
10
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
11
12
/**
13
 * @author Izzet Safer
14
 */
15
public class TaskActivateHandler extends AbstractHandler {
16
17
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
18
19
	private TaskActivateAction activateAction = null;
20
	
21
	public TaskActivateHandler() {
22
		activateAction = new TaskActivateAction();
23
	}
24
	
25
	public Object execute(ExecutionEvent event) throws ExecutionException {
26
		String taskHandle = event.getParameter(PARAMETER_TASK_HANDLE_ID);
27
	
28
		if (taskHandle == null) {
29
			return null;
30
		}
31
					
32
		ITask task = TasksUiPlugin.getTaskListManager().getTaskList().findTask((String)taskHandle);
33
		if (task != null) {				
34
			activateAction.run(task);
35
		}
36
		
37
		return Boolean.TRUE;
38
	}
39
}
(-)src/org/eclipse/mylar/internal/tasks/ui/commands/TaskDeactivateHandler.java (+39 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasks.ui.commands;
2
3
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.tasks.ui.actions.TaskDeactivateAction;
9
import org.eclipse.mylar.tasks.core.ITask;
10
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
11
12
/**
13
 * @author Izzet Safer
14
 */
15
public class TaskDeactivateHandler extends AbstractHandler {
16
17
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
18
19
	private TaskDeactivateAction deactivateAction = null;
20
	
21
	public TaskDeactivateHandler() {
22
		deactivateAction = new TaskDeactivateAction();
23
	}
24
	
25
	public Object execute(ExecutionEvent event) throws ExecutionException {
26
		String taskHandle = event.getParameter(PARAMETER_TASK_HANDLE_ID);
27
	
28
		if (taskHandle == null) {
29
			return null;
30
		}
31
					
32
		ITask task = TasksUiPlugin.getTaskListManager().getTaskList().findTask((String)taskHandle);
33
		if (task != null) {				
34
			deactivateAction.run(task);
35
		}
36
		
37
		return Boolean.TRUE;
38
	}
39
}
(-)src/org/eclipse/mylar/internal/tasks/ui/commands/MarkTaskIncompleteHandler.java (+39 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasks.ui.commands;
2
3
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.tasks.ui.actions.MarkTaskIncompleteAction;
9
import org.eclipse.mylar.tasks.core.ITask;
10
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
11
12
/**
13
 * @author Izzet Safer
14
 */
15
public class MarkTaskIncompleteHandler extends AbstractHandler {
16
17
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
18
19
	private MarkTaskIncompleteAction incompleteAction = null;
20
	
21
	public MarkTaskIncompleteHandler() {
22
		incompleteAction = new MarkTaskIncompleteAction();		
23
	}
24
	
25
	public Object execute(ExecutionEvent event) throws ExecutionException {
26
		String taskHandle = event.getParameter(PARAMETER_TASK_HANDLE_ID);
27
28
		if (taskHandle == null) {
29
			return null;
30
		}
31
		
32
		ITask task = TasksUiPlugin.getTaskListManager().getTaskList().findTask((String)taskHandle);
33
		if (task != null) {
34
			incompleteAction.run(task);
35
		}
36
		
37
		return Boolean.TRUE;
38
	}
39
}
(-)src/org/eclipse/mylar/internal/tasks/ui/actions/NewLocalSubTaskAction.java (+109 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.tasks.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.tasks.ui.TaskListImages;
21
import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil;
22
import org.eclipse.mylar.internal.tasks.ui.views.TaskInputDialog;
23
import org.eclipse.mylar.internal.tasks.ui.views.TaskListView;
24
import org.eclipse.mylar.tasks.core.ITask;
25
import org.eclipse.mylar.tasks.core.Task;
26
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
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
	public NewLocalSubTaskAction() {
41
		this(null);
42
	}
43
	
44
	public NewLocalSubTaskAction(TaskListView view) {
45
		this.view = view;
46
		setText(TaskInputDialog.LABEL_SHELL);			//TODO form to be done
47
		setToolTipText(TaskInputDialog.LABEL_SHELL);	//TODO form to be done
48
		setId(ID);
49
		setImageDescriptor(TaskListImages.TASK_NEW);
50
	}
51
52
	@Override
53
	public void run() {
54
		String taskHandle = TasksUiPlugin.getTaskListManager().genUniqueTaskHandle();
55
		ITask parentTask = null; 
56
		
57
		Object selectedObject = null;
58
		if (view != null) {
59
			selectedObject = ((IStructuredSelection) view.getViewer().getSelection()).getFirstElement();
60
		}
61
		
62
		if (selectedObject instanceof ITask) {
63
			parentTask = (ITask) selectedObject;		
64
		} else {
65
			MessageDialog.openInformation(Display.getCurrent().getActiveShell(), TasksUiPlugin.TITLE_DIALOG, 
66
					"The new subtask cannot be added, please choose a task.");
67
			return;
68
		}
69
70
		addNewLocalSubTask(taskHandle, DESCRIPTION_DEFAULT, parentTask, true);
71
	}
72
73
	public ITask run(String taskHandle, String taskName, String parentHandle) {		
74
		if (taskHandle == null || taskHandle.equals("")) 
75
			taskHandle = TasksUiPlugin.getTaskListManager().genUniqueTaskHandle();
76
	 		
77
		if (parentHandle == null || parentHandle.equals("")) return null;
78
79
		ITask parentTask = TasksUiPlugin.getTaskListManager().getTaskList().findTask(parentHandle);
80
		if (parentTask == null) return null;	
81
82
		return addNewLocalSubTask(taskHandle, taskName, parentTask, false);		
83
	}
84
	
85
	private ITask addNewLocalSubTask(String taskHandle, String taskName, ITask parentTask, boolean edit) {
86
		ITask newSubTask = new Task(taskHandle, taskName, true);
87
//		newTask.setUrl(getDefaultIssueURL());
88
		
89
		Calendar reminderCalendar = GregorianCalendar.getInstance();
90
		TasksUiPlugin.getTaskListManager().setScheduledToday(reminderCalendar);
91
		TasksUiPlugin.getTaskListManager().setReminder(newSubTask, reminderCalendar.getTime());
92
93
		parentTask.addSubTask(newSubTask);
94
		
95
		if (edit) TaskUiUtil.openEditor(newSubTask, true);
96
		
97
		if (view != null) {
98
			view.getViewer().refresh();
99
			
100
			if (edit) {
101
				view.setInRenameAction(true);
102
				view.getViewer().editElement(newSubTask, 4);
103
				view.setInRenameAction(false);
104
			}
105
		}
106
		
107
		return newSubTask;
108
	}
109
}
(-)src/org/eclipse/mylar/internal/tasks/ui/commands/MarkTaskCompleteHandler.java (+39 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasks.ui.commands;
2
3
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.tasks.ui.actions.MarkTaskCompleteAction;
9
import org.eclipse.mylar.tasks.core.ITask;
10
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
11
12
/**
13
 * @author Izzet Safer
14
 */
15
public class MarkTaskCompleteHandler extends AbstractHandler {
16
17
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
18
19
	private MarkTaskCompleteAction completeAction = null;
20
	
21
	public MarkTaskCompleteHandler() {
22
		completeAction = new MarkTaskCompleteAction();		
23
	}
24
	
25
	public Object execute(ExecutionEvent event) throws ExecutionException {
26
		String taskHandle = event.getParameter(PARAMETER_TASK_HANDLE_ID);
27
28
		if (taskHandle == null) {
29
			return null;
30
		}
31
		
32
		ITask task = TasksUiPlugin.getTaskListManager().getTaskList().findTask((String)taskHandle);
33
		if (task != null) {
34
			completeAction.run(task);
35
		}
36
		
37
		return Boolean.TRUE;
38
	}
39
}
(-)src/org/eclipse/mylar/internal/tasks/ui/commands/NewLocalTaskHandler.java (+92 lines)
Added Link Here
1
package org.eclipse.mylar.internal.tasks.ui.commands;
2
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.mylar.context.core.ContextCorePlugin;
7
import org.eclipse.mylar.internal.tasks.ui.actions.MarkTaskIncompleteAction;
8
import org.eclipse.mylar.internal.tasks.ui.actions.NewLocalTaskAction;
9
import org.eclipse.mylar.internal.tasks.ui.actions.TaskActivateAction;
10
import org.eclipse.mylar.internal.tasks.ui.actions.TaskDeactivateAction;
11
import org.eclipse.mylar.internal.tasks.ui.views.TaskListView;
12
import org.eclipse.mylar.tasks.core.ITask;
13
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
14
15
/**
16
 * @author Izzet Safer
17
 */
18
public class NewLocalTaskHandler extends AbstractHandler {
19
20
	private static final String PARAMETER_TASK_NAME_ID = "taskName"; //$NON-NLS-1$
21
	private static final String PARAMETER_TASK_HANDLE_ID = "taskHandle"; //$NON-NLS-1$
22
	private static final String PARAMETER_CATEGORY_NAME_ID = "categoryName"; //$NON-NLS-1$
23
	private static final String PARAMETER_ACTIVATE_TASK_ID = "activateTask"; //$NON-NLS-1$
24
	private static final String PARAMETER_RESET_CONTEXT_ID = "resetContext"; //$NON-NLS-1$
25
	
26
	private static final boolean activateTaskDefault = true;
27
	private static final boolean resetContextDefault = true;
28
	
29
	private NewLocalTaskAction newAction = null; 
30
	private TaskActivateAction activateAction = null;
31
	private TaskDeactivateAction deactivateAction = null;
32
	private MarkTaskIncompleteAction incompleteAction = null;
33
	
34
	public NewLocalTaskHandler () {
35
		newAction = new NewLocalTaskAction();
36
		activateAction = new TaskActivateAction();
37
		deactivateAction = new TaskDeactivateAction();
38
		incompleteAction = new MarkTaskIncompleteAction();
39
	}
40
	
41
	public Object execute(ExecutionEvent event) throws ExecutionException {				
42
		Object returnValue = null;
43
44
		final String taskName = event.getParameter(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 String taskHandle = event.getParameter(PARAMETER_TASK_HANDLE_ID);
48
49
		// will use root when null
50
		final String categoryName = event.getParameter(PARAMETER_CATEGORY_NAME_ID);
51
		
52
		final boolean activateTask = event.getParameter(PARAMETER_ACTIVATE_TASK_ID) == null ? activateTaskDefault 
53
				: Boolean.parseBoolean(event.getParameter(PARAMETER_ACTIVATE_TASK_ID));
54
55
		// delete the context associated with the task if an existing task is used
56
		final boolean resetContext = event.getParameter(PARAMETER_RESET_CONTEXT_ID) == null ? resetContextDefault 
57
				: Boolean.parseBoolean(event.getParameter(PARAMETER_RESET_CONTEXT_ID));
58
		
59
		if (taskName == null) {
60
			return returnValue;
61
		} else {
62
			ITask newTask = null;
63
			if (taskHandle != null) {
64
				newTask = TasksUiPlugin.getTaskListManager().getTaskList().findTask((String)taskHandle);
65
				if (newTask != null && resetContext) {
66
					//TODO: do this using ContextClearAction
67
					ContextCorePlugin.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
				newTask = newAction.run(taskHandle == null ? "" : taskHandle, 
77
						taskName, categoryName == null ? "" : categoryName);
78
			}			
79
			
80
			returnValue = (newTask == null) ? null : newTask.getHandleIdentifier();
81
			
82
			if (activateTask) activateAction.run(newTask);
83
			else deactivateAction.run(newTask);	
84
		}
85
		
86
		try {
87
			TaskListView.getFromActivePerspective().getViewer().refresh();
88
		} catch (Exception ex) {}
89
		
90
		return returnValue;
91
	}
92
}

Return to bug 145884