Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2005-09-24 01:14:34 +0000
committermkersten2005-09-24 01:14:34 +0000
commitddef1c3ae72e7cbcc8ecb4cc8591640ccd9d4e18 (patch)
treeac4e8d149c83bbf6d5c7480662632567a21cfc8a
parent277670dcc1297b456d1ff5e0be471752cf395ca9 (diff)
downloadorg.eclipse.mylyn.tasks-ddef1c3ae72e7cbcc8ecb4cc8591640ccd9d4e18.tar.gz
org.eclipse.mylyn.tasks-ddef1c3ae72e7cbcc8ecb4cc8591640ccd9d4e18.tar.xz
org.eclipse.mylyn.tasks-ddef1c3ae72e7cbcc8ecb4cc8591640ccd9d4e18.zip
Patch for Bugzilla Bug 110061: previous task history should be persistent
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskHistoryTest.java30
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskActivationHistory.java368
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskListView.java6
3 files changed, 269 insertions, 135 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskHistoryTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskHistoryTest.java
index 7bbf9248f..ab5b26f75 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskHistoryTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/TaskHistoryTest.java
@@ -27,6 +27,7 @@ import org.eclipse.ui.PartInitException;
public class TaskHistoryTest extends TestCase {
protected TaskListManager manager = MylarTasklistPlugin.getTaskListManager();
+ protected TaskListView taskView = null;
protected Task task1 = null;
protected Task task2 = null;
@@ -37,6 +38,19 @@ public class TaskHistoryTest extends TestCase {
super.setUp();
MylarPlugin.getContextManager().resetActivityHistory();
+ try {
+ MylarTasklistPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.mylar.tasks.ui.views.TaskListView");
+ } catch (PartInitException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail("View not initialized");
+ }
+
+ assertNotNull(TaskListView.getDefault());
+ taskView = TaskListView.getDefault();
+
+ taskView.clearTaskHistory();
+
task1 = new Task(MylarTasklistPlugin.getTaskListManager().genUniqueTaskId(), "task 1", true);
task2 = new Task(MylarTasklistPlugin.getTaskListManager().genUniqueTaskId(), "task 2", true);
task3 = new Task(MylarTasklistPlugin.getTaskListManager().genUniqueTaskId(), "task 3", true);
@@ -50,25 +64,17 @@ public class TaskHistoryTest extends TestCase {
}
public void testHistory(){
-
+
(new TaskActivateAction(task1)).run();
+ taskView.addTaskToHistory(task1); //Simulate clicking on it rather than navigating next or previous
(new TaskActivateAction(task2)).run();
+ taskView.addTaskToHistory(task2);
(new TaskActivateAction(task3)).run();
+ taskView.addTaskToHistory(task3);
assertTrue(task3.isActive());
assertFalse(task2.isActive());
- try {
- MylarTasklistPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.mylar.tasks.ui.views.TaskListView");
- } catch (PartInitException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- fail("View not initialized");
- }
-
- assertNotNull(TaskListView.getDefault());
- TaskListView taskView = TaskListView.getDefault();
-
taskView.getPreviousTaskAction().run();
assertTrue(task2.isActive());
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskActivationHistory.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskActivationHistory.java
index 70b113d1d..5809c74ac 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskActivationHistory.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskActivationHistory.java
@@ -10,189 +10,317 @@
*******************************************************************************/
package org.eclipse.mylar.tasklist.ui.views;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.mylar.core.InteractionEvent;
import org.eclipse.mylar.core.MylarPlugin;
-import org.eclipse.mylar.core.internal.MylarContextManager;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
-
/**
- * @author Ken Sueda (interface)
- * @author Wesley Coelho (new implementation)
- *
- * Note: Getting the previous or next task involves iterating until one is found
- * because there could be any number of interaction events for the same task
- * in the history. However, n should be less than 10 or so in most cases so
- * this shouldn't be a performance problem.
- */
+* @author Ken Sueda (Original implementation)
+* @author Wesley Coelho (Added persistent tasks)
+*/
public class TaskActivationHistory {
- protected MylarContextManager manager = MylarPlugin.getContextManager();
- protected int currentIndex = -1;
- protected int stackPos = 0;
-
- public TaskActivationHistory() {
+ private List<ITask> history = new ArrayList<ITask>();
+ private int currentIndex = -1;
+ /** The number of tasks from the previous session to load into the history*/
+ private static final int PERSISTENT_HISTORY_SIZE = 5;
+
+ private boolean persistentHistoryLoaded = false;
+
+ public TaskActivationHistory() {
+
+
}
- public void addTask(ITask task) {
- clear();
+ /**
+ * Load in a number of saved history tasks from previous session.
+ * Should be called from constructor but ContextManager doesn't
+ * seem to be able to provide activity history at that point
+ * @author Wesley Coelho
+ */
+ protected void loadPersistentHistory(){
+ int tasksAdded = 0;
+
+ for(int i = MylarPlugin.getContextManager().getActivityHistory().getInteractionHistory().size() - 1; i >=0; i--){
+ ITask prevTask = getHistoryTaskAt(i);
+
+ if (prevTask != null && !isDuplicate(prevTask, i + 1)) {
+ history.add(0, prevTask);
+ currentIndex++;
+ tasksAdded++;
+ if (tasksAdded == PERSISTENT_HISTORY_SIZE){
+ break;
+ }
+ }
+ }
}
- public ITask getPreviousTask() {
- if (hasPrevious()){
- stackPos--;
- return getUniquePreviousTask(true);
- }
- else{
- return null;
+ /**
+ * Returns true if the specified task appears in the activity
+ * history between the starting index and the end of the history list.
+ * @author Wesley Coelho
+ */
+ protected boolean isDuplicate(ITask task, int startingIndex){
+ for (int i = startingIndex; i < MylarPlugin.getContextManager().getActivityHistory().getInteractionHistory().size(); i++){
+ ITask currTask = getHistoryTaskAt(i);
+ if(currTask != null && currTask.getHandle() == task.getHandle()){
+ return true;
+ }
}
+ return false;
}
-
- public boolean hasPrevious() {
- return getUniquePreviousTask(false) != null;
+
+ /**
+ * Returns the task corresponding to the interaction event history item at the specified position
+ * @author Wesley Coelho
+ */
+ protected ITask getHistoryTaskAt(int pos){
+ InteractionEvent event = MylarPlugin.getContextManager().getActivityHistory().getInteractionHistory().get(pos);
+ return MylarTasklistPlugin.getTaskListManager().getTaskForHandle(event.getStructureHandle(), false);
}
- protected ITask getUniquePreviousTask(boolean setIndex){
- int pos = currentIndex;
-
- if (pos == -1){
- pos = manager.getActivityHistory().getInteractionHistory().size() - 1;
- }
-
- while (pos >= 0){
- if (getHistoryTaskAt(pos) != null && !getHistoryTaskAt(pos).isActive()) {
-
- //Don't go back to this task if it's
- // a duplicate of something already backed through
- ITask proposedPrevTask = getHistoryTaskAt(pos);
- boolean anotherTaskReached = false;
- boolean duplicate = false;
- for(int i = pos; i < manager.getActivityHistory().getInteractionHistory().size() - 1; i++){
- ITask currTask = getHistoryTaskAt(i);
- if (currTask != proposedPrevTask){
- anotherTaskReached = true;
- continue;
- }
-
- if (anotherTaskReached && currTask == proposedPrevTask){
- duplicate = true;
- }
- }
- //---
-
-
- if (!duplicate){
- if(setIndex){
- currentIndex = pos;
- }
- return proposedPrevTask;
- }
+ public void addTask(ITask task) {
+ try {
+ if (!persistentHistoryLoaded){
+ loadPersistentHistory();
+ persistentHistoryLoaded = true;
}
- pos--;
+
+ if (hasNext()) {
+ for (int i = currentIndex+1; i < history.size();) {
+ history.remove(i);
+ }
+ }
+ if (history.remove(task)){
+ currentIndex--;
+ }
+ history.add(task);
+ currentIndex++;
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "could not add task to history", false);
}
-
- return null;
}
- public ITask getNextTask() {
- if (hasNext()) {
- for(int i = currentIndex; i < manager.getActivityHistory().getInteractionHistory().size(); i++){
- ITask task = getHistoryTaskAt(i);
- if(task != null && !task.isActive()){
- currentIndex = i;
- stackPos++;
- if (stackPos == 0){
- currentIndex = -1;
- }
- return task;
+ public ITask getPreviousTask() {
+ try {
+ if (hasPrevious()) {
+ if((currentIndex == 0 && !history.get(currentIndex).isActive())){
+ return history.get(currentIndex);
+ } else {
+ return history.get(--currentIndex);
}
+ } else {
+ return null;
}
- return null;
- } else {
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "could not get previous task from history", false);
return null;
}
}
- public boolean hasNext() {
- if (currentIndex == -1){
- return false;
- }
- else{
- for(int i = currentIndex; i < manager.getActivityHistory().getInteractionHistory().size(); i++){
- if(getHistoryTaskAt(i) != null && !getHistoryTaskAt(i).isActive()){
- return true;
- }
+ public boolean hasPrevious() {
+ try {
+ if (!persistentHistoryLoaded){
+ loadPersistentHistory();
+ persistentHistoryLoaded = true;
}
+
+ return (currentIndex == 0 && !history.get(currentIndex).isActive()) || currentIndex > 0;
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "could determine previous task", false);
return false;
- }
+ }
}
- /** Returns the task corresponding to the interaction event history item at the specified position */
- protected ITask getHistoryTaskAt(int pos){
- InteractionEvent event = manager.getActivityHistory().getInteractionHistory().get(pos);
- return MylarTasklistPlugin.getTaskListManager().getTaskForHandle(event.getStructureHandle(), false);
+ public ITask getNextTask() {
+ try {
+ if (hasNext()) {
+ return history.get(++currentIndex);
+ } else {
+ return null;
+ }
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "could not get next task", false);
+ return null;
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ return currentIndex < history.size() - 1;
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "could not get next task", false);
+ return false;
+ }
}
- /** Note: Doesn't really clear, just resets the history pointer*/
public void clear() {
- currentIndex = -1;
- stackPos = 0;
+ try {
+ history.clear();
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "could not clear history", false);
+ }
}
}
-
///**
-// * @author Ken Sueda
+// * @author Ken Sueda (interface)
+// * @author Wesley Coelho (new implementation)
+// *
+// * Note: Getting the previous or next task involves iterating until one is found
+// * because there could be any number of interaction events for the same task
+// * in the history. However, n should be less than 10 or so in most cases so
+// * this shouldn't be a performance problem.
// */
//public class TaskActivationHistory {
-// private List<ITask> history = new ArrayList<ITask>();
-// private int currentIndex = -1;
+//
+// protected MylarContextManager manager = MylarPlugin.getContextManager();
+// protected int currentIndex = -1;
+// protected int stackPos = 0;
//
// public TaskActivationHistory() {
-// }
//
+//
+// }
+//
// public void addTask(ITask task) {
-// if (hasNext()) {
-// for (int i = currentIndex+1; i < history.size();) {
-// history.remove(i);
-// }
-// }
-// history.add(task);
-// currentIndex++;
+// clear();
// }
//
// public ITask getPreviousTask() {
-// if (hasPrevious()) {
-// if((currentIndex == 0 && !history.get(currentIndex).isActive())){
-// return history.get(currentIndex);
-// } else {
-// return history.get(--currentIndex);
-// }
-// } else {
+// if (hasPrevious()){
+// stackPos--;
+// return getUniquePreviousTask(true);
+// }
+// else{
// return null;
-// }
+// }
+// }
+//
+// public boolean hasPrevious() {
+// return getUniquePreviousTask(false) != null;
// }
//
-// public boolean hasPrevious() {
-// return (currentIndex == 0 && !history.get(currentIndex).isActive()) || currentIndex > 0;
+// protected ITask getUniquePreviousTask(boolean setIndex){
+// int pos = currentIndex;
+//
+// if (pos == -1){
+// pos = manager.getActivityHistory().getInteractionHistory().size() - 1;
+// }
+//
+// while (pos >= 0){
+// if (getHistoryTaskAt(pos) != null && !getHistoryTaskAt(pos).isActive()) {
+//
+// //Don't go back to this task if it's
+// // a duplicate of something already backed through
+// ITask proposedPrevTask = getHistoryTaskAt(pos);
+// boolean anotherTaskReached = false;
+// boolean duplicate = false;
+// for(int i = pos; i < manager.getActivityHistory().getInteractionHistory().size() - 1; i++){
+// ITask currTask = getHistoryTaskAt(i);
+// if (currTask != proposedPrevTask){
+// anotherTaskReached = true;
+// continue;
+// }
+//
+// if (anotherTaskReached && currTask == proposedPrevTask){
+// duplicate = true;
+// }
+// }
+//
+// if (!duplicate){
+// if(setIndex){
+// currentIndex = pos;
+// }
+// return proposedPrevTask;
+// }
+// }
+// pos--;
+// }
+//
+// return null;
// }
//
// public ITask getNextTask() {
// if (hasNext()) {
-// return history.get(++currentIndex);
+// for(int i = currentIndex; i < manager.getActivityHistory().getInteractionHistory().size(); i++){
+// ITask task = getHistoryTaskAt(i);
+// if(task != null && !task.isActive()){
+// currentIndex = i;
+// stackPos++;
+// if (stackPos == 0){
+// currentIndex = -1;
+// }
+// else{
+//
+//// //See if there is another task further down (but before the starting point)
+//// //that is the same as this task. If so, the
+//// //current task would have been skipped on the
+//// //way back so we should move the pointer over.
+//// int tempStackPos = stackPos;
+//// ITask prevTask = task;
+//// for(int j = currentIndex; j < manager.getActivityHistory().getInteractionHistory().size();j++){
+//// ITask currTask = getHistoryTaskAt(j);
+////
+//// if (currTask == null){
+//// continue;
+//// }
+////
+//// if (currTask != prevTask){
+//// prevTask = currTask;
+//// tempStackPos++;
+//// }
+////
+//// if (tempStackPos > 0){
+//// break;
+//// }
+////
+//// if(currTask == task){
+//// currentIndex = j;
+//// }
+//// }
+// }
+// return task;
+// }
+// }
+// return null;
// } else {
// return null;
// }
// }
//
// public boolean hasNext() {
-// return currentIndex < history.size() - 1;
+// if (currentIndex == -1){
+// return false;
+// }
+// else{
+// for(int i = currentIndex; i < manager.getActivityHistory().getInteractionHistory().size(); i++){
+// if(getHistoryTaskAt(i) != null && !getHistoryTaskAt(i).isActive()){
+// return true;
+// }
+// }
+// return false;
+// }
+// }
+//
+// /** Returns the task corresponding to the interaction event history item at the specified position */
+// protected ITask getHistoryTaskAt(int pos){
+// InteractionEvent event = manager.getActivityHistory().getInteractionHistory().get(pos);
+// return MylarTasklistPlugin.getTaskListManager().getTaskForHandle(event.getStructureHandle(), false);
// }
//
+// /** Note: Doesn't really clear, just resets the history pointer*/
// public void clear() {
-// history.clear();
+// currentIndex = -1;
+// stackPos = 0;
// }
//}
+
+
+
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskListView.java
index 828584db8..13bfd639b 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskListView.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskListView.java
@@ -666,11 +666,11 @@ public class TaskListView extends ViewPart {
break;
}
}
- getViewer().refresh();
} catch (Exception e) {
- MylarPlugin.log(e, e.getMessage());
+ MylarPlugin.fail(e, e.getMessage(), true);
}
- }
+ getViewer().refresh();
+ }
}
public void addTaskToHistory(ITask task) {

Back to the top