Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchris.poon2012-08-21 18:16:05 -0400
committerSam Davis2015-05-20 13:36:53 -0400
commite3d912eacc50ad636c8865d8fe6831a4564dd767 (patch)
tree5c262104669185ff681a3f038b8f5b9c7e0f3abe /org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks
parent65b8a30a5f8c1e576f74187bff37b1d253abcd45 (diff)
downloadorg.eclipse.mylyn.tasks-e3d912eacc50ad636c8865d8fe6831a4564dd767.tar.gz
org.eclipse.mylyn.tasks-e3d912eacc50ad636c8865d8fe6831a4564dd767.tar.xz
org.eclipse.mylyn.tasks-e3d912eacc50ad636c8865d8fe6831a4564dd767.zip
334937: provide API for canceling a task switch
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334937 Change-Id: I0962f312b692de78be778d8ecb5dd11f8efdc815 Signed-off-by: chris.poon <chris.poon@tasktop.com>
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java39
1 files changed, 32 insertions, 7 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java
index b9659b8ab..e5e215843 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java
@@ -41,11 +41,12 @@ import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITaskActivationListener;
import org.eclipse.mylyn.tasks.core.ITaskActivityListener;
import org.eclipse.mylyn.tasks.core.ITaskActivityManager2;
+import org.eclipse.mylyn.tasks.core.TaskActivationAdapter;
import org.eclipse.osgi.util.NLS;
/**
* Manages task elapsed time, scheduling, due dates, and the date ranges
- *
+ *
* @since 2.1
* @author Rob Elves
*/
@@ -68,7 +69,7 @@ public class TaskActivityManager implements ITaskActivityManager2 {
// Map of Calendar (hour) to Tasks active during that hour
private final SortedMap<Calendar, Set<AbstractTask>> activeTasks = Collections.synchronizedSortedMap(new TreeMap<Calendar, Set<AbstractTask>>());
- // For a given task maps Calendar Hour to duration of time spent (milliseconds) with task active
+ // For a given task maps Calendar Hour to duration of time spent (milliseconds) with task active
private final Map<AbstractTask, SortedMap<Calendar, Long>> taskElapsedTimeMap = new ConcurrentHashMap<AbstractTask, SortedMap<Calendar, Long>>();
private final Map<String, SortedMap<Calendar, Long>> workingSetElapsedTimeMap = new ConcurrentHashMap<String, SortedMap<Calendar, Long>>();
@@ -149,7 +150,7 @@ public class TaskActivityManager implements ITaskActivityManager2 {
/**
* Get the user specified first day of the week (Calendar.SUNDAY | Calendar.MONDAY)
- *
+ *
* @see http://en.wikipedia.org/wiki/Days_of_the_week#First_day_of_the_week
*/
public int getWeekStartDay() {
@@ -158,7 +159,7 @@ public class TaskActivityManager implements ITaskActivityManager2 {
/**
* Set the first day of the week (Calendar.SUNDAY | Calendar.MONDAY)
- *
+ *
* @see http://en.wikipedia.org/wiki/Days_of_the_week#First_day_of_the_week
* @param startDay
* (Calendar.SUNDAY | Calendar.MONDAY)
@@ -457,7 +458,12 @@ public class TaskActivityManager implements ITaskActivityManager2 {
}
public void activateTask(ITask task) {
- deactivateActiveTask();
+ if (activeTask != null) {
+ if (!shouldDeactivateTask(activeTask)) {
+ return;
+ }
+ deactivateTaskInternal(activeTask);
+ }
taskList.addTaskIfAbsent(task);
@@ -493,10 +499,13 @@ public class TaskActivityManager implements ITaskActivityManager2 {
}
public void deactivateTask(ITask task) {
- if (task == null) {
+ if (task == null || (task.isActive() && !shouldDeactivateTask(task))) {
return;
}
+ deactivateTaskInternal(task);
+ }
+ protected void deactivateTaskInternal(ITask task) {
if (task.isActive() && task == activeTask) {
// notify that a task is about to be deactivated
initTaskListeners();
@@ -526,6 +535,22 @@ public class TaskActivityManager implements ITaskActivityManager2 {
}
}
+ protected boolean shouldDeactivateTask(ITask task) {
+ for (ITaskActivationListener listener : new ArrayList<ITaskActivationListener>(activationListeners)) {
+ try {
+ if (listener instanceof TaskActivationAdapter) {
+ if (!((TaskActivationAdapter) listener).canDeactivateTask(task)) {
+ return false;
+ }
+ }
+ } catch (Throwable t) {
+ StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
+ "Task activity listener failed: " + listener, t)); //$NON-NLS-1$
+ }
+ }
+ return true;
+ }
+
/**
* returns active tasks from start to end (exclusive) where both are snapped to the beginning of the hour
*/
@@ -934,4 +959,4 @@ public class TaskActivityManager implements ITaskActivityManager2 {
Assert.isNotNull(task);
return task.equals(getActiveTask());
}
-} \ No newline at end of file
+}

Back to the top