diff options
author | mkersten | 2007-09-24 23:58:34 +0000 |
---|---|---|
committer | mkersten | 2007-09-24 23:58:34 +0000 |
commit | 4eeaeee67411a527b7e993a824902058ca21ce64 (patch) | |
tree | 5284cfe3dfeb1ab8ab9af13ef25f5271a3c71274 | |
parent | f1e085258546c561511244c613ccac91ea64a854 (diff) | |
download | org.eclipse.mylyn.tasks-4eeaeee67411a527b7e993a824902058ca21ce64.tar.gz org.eclipse.mylyn.tasks-4eeaeee67411a527b7e993a824902058ca21ce64.tar.xz org.eclipse.mylyn.tasks-4eeaeee67411a527b7e993a824902058ca21ce64.zip |
Progress on recursion safety
4 files changed, 100 insertions, 45 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTaskContainer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTaskContainer.java index b96eb097a..ec9ca6ff7 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTaskContainer.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTaskContainer.java @@ -22,6 +22,13 @@ import org.eclipse.mylyn.tasks.core.AbstractTask.PriorityLevel; */ public abstract class AbstractTaskContainer extends PlatformObject implements Comparable<AbstractTaskContainer> { + /** + * @since 2.1 + * + * TODO: consider removing in 3.0 if handled by content provider + */ + public static final int MAX_SUBTASK_DEPTH = 10; + private String handleIdentifier = ""; private Set<AbstractTask> children = new CopyOnWriteArraySet<AbstractTask>(); @@ -61,17 +68,32 @@ public abstract class AbstractTaskContainer extends PlatformObject implements Co return Collections.unmodifiableSet(children); } + /** + * Maxes out at a depth of 10. + * + * TODO: review policy + */ public boolean contains(String handle) { - for (AbstractTask child : children) { - if (handle.equals(child.getHandleIdentifier())) { - return true; - } else if(child.getChildren() != null && child.getChildren().size() > 0){ - if(child.contains(handle)){ + return containsHelper(handle, 0); + } + + private boolean containsHelper(String handle, int depth) { + if (depth >= MAX_SUBTASK_DEPTH) { +// StatusHandler.fail(new Throwable("Max child depth reached for task: " + handle), "", false); + return false; + } else { + depth++; + for (AbstractTask child : children) { + if (handle.equals(child.getHandleIdentifier())) { return true; + } else if (child.getChildren() != null && child.getChildren().size() > 0) { + if (((AbstractTaskContainer)child).containsHelper(handle, depth)) { + return true; + } } } + return false; } - return false; } public String getSummary() { diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskList.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskList.java index 3c2bdd110..edce7bef6 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskList.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskList.java @@ -688,30 +688,36 @@ public class TaskList { /** Note: use getNextTaskNum for new task construction */ public int findLargestTaskId() { int max = 0; - max = Math.max(largestTaskIdHelper(tasks.values()), max); + max = Math.max(largestTaskIdHelper(tasks.values(), 0, 0), max); for (AbstractTaskCategory cat : getTaskContainers()) { - max = Math.max(largestTaskIdHelper(cat.getChildren()), max); + max = Math.max(largestTaskIdHelper(cat.getChildren(), 0, 0), max); } return max; } - private int largestTaskIdHelper(Collection<AbstractTask> tasks) { - int ihandle = 0; - int max = 0; - for (AbstractTask task : tasks) { - if (task instanceof LocalTask) { - String string = task.getHandleIdentifier().substring(task.getHandleIdentifier().lastIndexOf('-') + 1, - task.getHandleIdentifier().length()); - try { - ihandle = Integer.parseInt(string); - } catch (NumberFormatException nfe) { + private int largestTaskIdHelper(Collection<AbstractTask> tasks, int lastMax, int depth) { + if (depth >= AbstractTaskContainer.MAX_SUBTASK_DEPTH) { + return lastMax; + } else { + depth++; + int ihandle = 0; + int max = 0; + for (AbstractTask task : tasks) { + if (task instanceof LocalTask) { + String string = task.getHandleIdentifier().substring(task.getHandleIdentifier().lastIndexOf('-') + 1, + task.getHandleIdentifier().length()); + try { + ihandle = Integer.parseInt(string); + } catch (NumberFormatException nfe) { + // ignore + } + max = Math.max(ihandle, max); + ihandle = largestTaskIdHelper(task.getChildren(), max, depth); + max = Math.max(ihandle, max); } } - max = Math.max(ihandle, max); - ihandle = largestTaskIdHelper(task.getChildren()); - max = Math.max(ihandle, max); + return max; } - return max; } /** diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/CustomTaskListDecorationDrawer.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/CustomTaskListDecorationDrawer.java index 8847f3394..332f0993f 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/CustomTaskListDecorationDrawer.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/CustomTaskListDecorationDrawer.java @@ -150,17 +150,26 @@ class CustomTaskListDecorationDrawer implements Listener { } private boolean hasIncoming(AbstractTaskContainer container) { - for (AbstractTask task : container.getChildren()) { - if (task != null) { - AbstractTask containedRepositoryTask = task; - if (containedRepositoryTask.getSynchronizationState() == RepositoryTaskSyncState.INCOMING) { - return true; - } else if (task.getChildren() != null && task.getChildren().size() > 0 && hasIncoming(task)) { - return true; + return hasIncomingHelper(container, 0); + } + + private boolean hasIncomingHelper(AbstractTaskContainer container, int depth) { + if (depth >= AbstractTaskContainer.MAX_SUBTASK_DEPTH) { + return false; + } else { + depth++; + for (AbstractTask task : container.getChildren()) { + if (task != null) { + AbstractTask containedRepositoryTask = task; + if (containedRepositoryTask.getSynchronizationState() == RepositoryTaskSyncState.INCOMING) { + return true; + } else if (task.getChildren() != null && task.getChildren().size() > 0 && hasIncomingHelper(task, depth)) { + return true; + } } } + return false; } - return false; } private void drawActivationImage(final int activationImageOffset, Event event, Image image) { diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskElementLabelProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskElementLabelProvider.java index 9d2f3e497..af45d66df 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskElementLabelProvider.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskElementLabelProvider.java @@ -126,8 +126,8 @@ public class TaskElementLabelProvider extends LabelProvider implements IColorPro ((Person) element).getRepositoryUrl()); // for (TaskRepository repository : TasksUiPlugin.getRepositoryManager().getAllRepositories()) { - if (repository != null && - !repository.isAnonymous() + if (repository != null + && !repository.isAnonymous() && (repository.getUserName() != null && repository.getUserName().equalsIgnoreCase( element.getHandleIdentifier()))) { compositeDescriptor.icon = TasksUiImages.PERSON_ME; @@ -339,16 +339,25 @@ public class TaskElementLabelProvider extends LabelProvider implements IColorPro return false; } - for (AbstractTaskContainer child : container.getChildren()) { - if (child instanceof AbstractTask && ((AbstractTask) child).isActive()) { - return true; - } else { - if (showHasActiveChild(child)) { + return showHasActiveChildHelper(container, 0); + } + + private boolean showHasActiveChildHelper(AbstractTaskContainer container, int depth) { + if (depth >= AbstractTaskContainer.MAX_SUBTASK_DEPTH) { + return false; + } else { + depth++; + for (AbstractTaskContainer child : container.getChildren()) { + if (child instanceof AbstractTask && ((AbstractTask) child).isActive()) { return true; + } else { + if (showHasActiveChildHelper(child, depth)) { + return true; + } } } + return false; } - return false; } private boolean showHasChildrenPastDue(AbstractTaskContainer container) { @@ -356,16 +365,25 @@ public class TaskElementLabelProvider extends LabelProvider implements IColorPro return false; } - for (AbstractTaskContainer child : container.getChildren()) { - if (child instanceof AbstractTask && ((AbstractTask) child).isPastReminder() - && !((AbstractTask) child).isCompleted()) { - return true; - } else { - if (showHasChildrenPastDue(child)) { + return showHasChildrenPastDueHelper(container, 0); + } + + private boolean showHasChildrenPastDueHelper(AbstractTaskContainer container, int depth) { + if (depth >= AbstractTaskContainer.MAX_SUBTASK_DEPTH) { + return false; + } else { + depth++; + for (AbstractTaskContainer child : container.getChildren()) { + if (child instanceof AbstractTask && ((AbstractTask) child).isPastReminder() + && !((AbstractTask) child).isCompleted()) { return true; + } else { + if (showHasChildrenPastDueHelper(child, depth)) { + return true; + } } } + return false; } - return false; } } |