Tasklist code cleanup. BLD200401181900
authorpkuzel@netbeans.org
Fri, 16 Jan 2004 21:26:02 +0000
changeset 399523fd1ef35cab
parent 3994 6049287bf405
child 3996 23feb1b748ef
Tasklist code cleanup.
suggestions_framework/src/org/netbeans/modules/tasklist/suggestions/SuggestionList.java
tasklist.core/src/org/netbeans/modules/tasklist/core/Task.java
tasklist.core/src/org/netbeans/modules/tasklist/core/TaskList.java
tasklist.docscan/src/org/netbeans/modules/tasklist/docscan/SourceTasksList.java
     1.1 --- a/suggestions_framework/src/org/netbeans/modules/tasklist/suggestions/SuggestionList.java	Fri Jan 16 19:27:24 2004 +0000
     1.2 +++ b/suggestions_framework/src/org/netbeans/modules/tasklist/suggestions/SuggestionList.java	Fri Jan 16 21:26:02 2004 +0000
     1.3 @@ -24,6 +24,7 @@
     1.4  import org.netbeans.modules.tasklist.core.TaskList;
     1.5  import org.netbeans.modules.tasklist.core.TaskListView;
     1.6  import org.netbeans.modules.tasklist.core.TaskNode;
     1.7 +import org.netbeans.modules.tasklist.core.Task;
     1.8  import org.netbeans.modules.tasklist.client.SuggestionManager;
     1.9  
    1.10  import org.openide.nodes.Node;
    1.11 @@ -36,8 +37,6 @@
    1.12   *
    1.13   * @author Tor Norbye
    1.14   */
    1.15 -
    1.16 -
    1.17  public class SuggestionList extends TaskList {
    1.18  
    1.19      /** Number of tasks we allow before for a type before dropping
    1.20 @@ -100,13 +99,65 @@
    1.21              // Add the category in the given position
    1.22              SuggestionImpl after = findAfter(type);
    1.23              if (after != null) { 
    1.24 -                add(category, after, false);
    1.25 +                add(category, after);
    1.26              } else {
    1.27 -                add(category, false, false);
    1.28 +                add(category, false);
    1.29              }
    1.30          }
    1.31          return category;
    1.32      }
    1.33 +
    1.34 +    /** Add a task to the task list.
    1.35 +     * @param task The task to be added.
    1.36 +     * @param after The task which will be immediately before
    1.37 +     * the new subtask after the addition (e.g. add
    1.38 +     * this subtask directly AFTER the specified
    1.39 +     * task)
    1.40 +     * @deprecated use Task.addSubtask(Task subtask, Task after) instead
    1.41 +     */
    1.42 +    private void add(Task task, Task after) {
    1.43 +        if (root == null) {
    1.44 +            root = getRoot();
    1.45 +        }
    1.46 +        if (task.getParent() == null) {
    1.47 +            task.setParent(root);
    1.48 +        }
    1.49 +        Task parent = task.getParent();
    1.50 +        // User insert: prepend to the list
    1.51 +        parent.addSubtask(task, after);
    1.52 +
    1.53 +        markChanged();
    1.54 +    }
    1.55 +
    1.56 +
    1.57 +    /** Add a task to the task list.
    1.58 +     * @param task The task to be added.
    1.59 +     * @param append If true, append the item to the list, otherwise prepend
    1.60 +     * @deprecated use Task.addSubtask(Task subtask, boolean append) instead
    1.61 +     */
    1.62 +    private void add(Task task, boolean append) {
    1.63 +
    1.64 +        // Q: what's this? why it not it added to root
    1.65 +        // instead of task.getParent?
    1.66 +        // A: it's probably because tasklist is flat
    1.67 +        // but tasks can form hierarchy sharing one tasklist
    1.68 +
    1.69 +        if (root == null) {
    1.70 +            root = getRoot();
    1.71 +        }
    1.72 +        if (task.getParent() == null) {
    1.73 +            task.setParent(root);
    1.74 +        }
    1.75 +
    1.76 +        // it's really funny contruct
    1.77 +        Task parent = task.getParent();
    1.78 +        parent.addSubtask(task, append);
    1.79 +
    1.80 +        notifyAdded(task);
    1.81 +        markChanged();
    1.82 +    }
    1.83 +
    1.84 +
    1.85      private Map categoryTasks = null;
    1.86  
    1.87      /** Return the task that we need to put this new category type
    1.88 @@ -138,7 +189,7 @@
    1.89      synchronized void removeCategory(SuggestionImpl category, boolean force) {
    1.90          //SuggestionImpl category = (SuggestionImpl)s.getParent();
    1.91          if ((category != null) && (force || !category.hasSubtasks())) {
    1.92 -            remove(category);
    1.93 +            category.getParent().removeSubtask(category);
    1.94              categoryTasks.remove(category.getSType());
    1.95          }
    1.96      }
     2.1 --- a/tasklist.core/src/org/netbeans/modules/tasklist/core/Task.java	Fri Jan 16 19:27:24 2004 +0000
     2.2 +++ b/tasklist.core/src/org/netbeans/modules/tasklist/core/Task.java	Fri Jan 16 21:26:02 2004 +0000
     2.3 @@ -327,15 +327,6 @@
     2.4      }
     2.5  
     2.6      /**
     2.7 -     * This method is here only for the benefit of the XMLEncoder,
     2.8 -     * such that task trees can be persisted. Do not use it directly;
     2.9 -     * use addSubtask instead.
    2.10 -     */
    2.11 -    public void setSubtasks(LinkedList subtasks) {
    2.12 -        this.subtasks = subtasks;
    2.13 -    }
    2.14 -
    2.15 -    /**
    2.16       * Add subtask to this task. The task will be prepended
    2.17       * to the task list.
    2.18       *
    2.19 @@ -424,19 +415,16 @@
    2.20          updatedStructure();
    2.21      }
    2.22  
    2.23 -    /**
    2.24 -     * Removes this task from the task list
    2.25 -     */
    2.26 -    public void remove() {
    2.27 -        assert parent != null : "parent == null";
    2.28 -
    2.29 -        getParent().removeSubtask(this);
    2.30 -    }
    2.31 -
    2.32      /** Remove a particular subtask
    2.33       * @param subtask The subtask to be removed */
    2.34      public void removeSubtask(Task subtask) {
    2.35  	//subtask.list = null;
    2.36 +
    2.37 +//        if (subtask.getAnnotation() != null) {
    2.38 +//            subtask.getAnnotation().detach();
    2.39 +//            subtask.setAnnotation(null);
    2.40 +//        }
    2.41 +
    2.42          // We need the list reference later, when looking for a reincarnation
    2.43          // of the task. So instead use the zombie field to mark deleted items.
    2.44          subtask.zombie = true;
    2.45 @@ -452,33 +440,15 @@
    2.46          }
    2.47      }
    2.48  
    2.49 -    /** For use with list iterators
    2.50 -	@param it Iterator, which should just have returned the next parameter
    2.51 -	@param item The item which was most recently next()'ed out of the iterator
    2.52 +    /**
    2.53 +     * Indicate whether or not this task has any subtasks
    2.54 +     * @return true iff the item has any subtasks
    2.55       */
    2.56 -    public void removeSubtask(ListIterator it, Task item) { // Remove publicness
    2.57 -        if (it == null) {
    2.58 -            return;
    2.59 -        }
    2.60 -	item.list = null;
    2.61 -        it.remove();
    2.62 -
    2.63 -        // XXX is the following allowed?
    2.64 -        if (subtasks.size() == 0) {
    2.65 -            subtasks = null;
    2.66 -        }
    2.67 -        if (!silentUpdate && !item.silentUpdate) {
    2.68 -            updatedStructure();
    2.69 -        }
    2.70 -    }
    2.71 -
    2.72 -    /** Indicate whether or not this task has any subtasks
    2.73 -     * @return true iff the item has any subtasks */
    2.74 -    public boolean hasSubtasks() {
    2.75 +    public final boolean hasSubtasks() {
    2.76          return ((subtasks != null) && (subtasks.size() != 0));
    2.77      }
    2.78  
    2.79 -    public Task getParent() {
    2.80 +    public final Task getParent() {
    2.81          return parent;
    2.82      }
    2.83  
    2.84 @@ -490,7 +460,11 @@
    2.85          return isParentOf(nextLevel);  // recursion
    2.86      }
    2.87  
    2.88 -    public void setParent(Task parent) {
    2.89 +    /**
    2.90 +     * XXX make paskage private or even private
    2.91 +     * @deprecated iCalSupport should use addSubtask
    2.92 +     */
    2.93 +    public final void setParent(Task parent) {
    2.94          this.parent = parent;
    2.95          // Should we broadcast this change??? Probably not, it's always
    2.96          // manipulated as part of add/deletion operations which are tracked
     3.1 --- a/tasklist.core/src/org/netbeans/modules/tasklist/core/TaskList.java	Fri Jan 16 19:27:24 2004 +0000
     3.2 +++ b/tasklist.core/src/org/netbeans/modules/tasklist/core/TaskList.java	Fri Jan 16 21:26:02 2004 +0000
     3.3 @@ -27,7 +27,7 @@
     3.4  import org.openide.util.NbBundle;
     3.5  
     3.6  /**
     3.7 - * This class models hierarchical tasklist.
     3.8 + * This class models flat list or hierarchical tasks.
     3.9   *
    3.10   * @author Tor Norbye
    3.11   * @author Tim Lebedkov
    3.12 @@ -35,11 +35,12 @@
    3.13  public class TaskList implements ObservableList, TaskListener {
    3.14  
    3.15      // List category
    3.16 -    public final static String USER_CATEGORY = "usertasks"; // NOI18N
    3.17 +    final static String USER_CATEGORY = "usertasks"; // NOI18N
    3.18  
    3.19 +    // data holder
    3.20      protected Task root = null;
    3.21      
    3.22 -    protected ArrayList listeners = null;
    3.23 +    private ArrayList listeners = null;
    3.24      
    3.25      /** Has the options set changed such that we need to save */
    3.26      protected boolean needSave = false;
    3.27 @@ -116,8 +117,12 @@
    3.28              it = removeList.listIterator();
    3.29              while (it.hasNext()) {
    3.30                  Task task = (Task) it.next();
    3.31 +                if (parent != null) {
    3.32 +                    parent.removeSubtask(task);
    3.33 +                } else {
    3.34 +                    root.removeSubtask(task);
    3.35 +                }
    3.36                  modified = true;
    3.37 -                remove(task);
    3.38              }
    3.39          }
    3.40  
    3.41 @@ -144,101 +149,7 @@
    3.42          setSilentUpdate(false, true, modified);
    3.43      }
    3.44  
    3.45 -    /** 
    3.46 -     * Add a task to the task list.
    3.47 -     * @param task The task to be added. 
    3.48 -     * @deprecated use getRoot().addSubtask(task) instead
    3.49 -     */
    3.50 -    public void add(Task task) {
    3.51 -        add(task, false, true);
    3.52 -    }
    3.53 -
    3.54 -    /** Add a task to the task list.
    3.55 -     * @param task The task to be added.
    3.56 -     * @param append If true, append the item to the list, otherwise prepend
    3.57 -     * @param show If true, show the task in the list
    3.58 -     * @deprecated use Task.addSubtask(Task subtask, boolean append) instead
    3.59 -     */
    3.60 -    public void add(Task task, boolean append, boolean show) {
    3.61 -        if (root == null) {
    3.62 -            root = getRoot();
    3.63 -        }
    3.64 -        if (task.getParent() == null) {
    3.65 -            task.setParent(root);
    3.66 -        }
    3.67 -        Task parent = task.getParent();
    3.68 -        // User insert: prepend to the list
    3.69 -        parent.addSubtask(task, append);
    3.70 -
    3.71 -        needSave = true;
    3.72 -
    3.73 -        // Show the new item
    3.74 -        // XXX fix this
    3.75 -        if (show) {
    3.76 -            notifySelected(task);
    3.77 -        }
    3.78 -
    3.79 -        notifyAdded(task);
    3.80 -
    3.81 -        // TODO make this smarter later on, such that I only save when necessary
    3.82 -        save();
    3.83 -    }
    3.84 -
    3.85 -    /** Add a task to the task list.
    3.86 -     * @param task The task to be added.
    3.87 -     * @param after The task which will be immediately before
    3.88 -     * the new subtask after the addition (e.g. add
    3.89 -     * this subtask directly AFTER the specified
    3.90 -     * task)
    3.91 -     * @param show If true, show the task in the list
    3.92 -     * @deprecated use Task.addSubtask(Task subtask, Task after) instead
    3.93 -     */
    3.94 -    public void add(Task task, Task after, boolean show) {
    3.95 -        if (root == null) {
    3.96 -            root = getRoot();
    3.97 -        }
    3.98 -        if (task.getParent() == null) {
    3.99 -            task.setParent(root);
   3.100 -        }
   3.101 -        Task parent = task.getParent();
   3.102 -        // User insert: prepend to the list
   3.103 -        parent.addSubtask(task, after);
   3.104 -
   3.105 -        needSave = true;
   3.106 -
   3.107 -        // Show the new item
   3.108 -        // XXX fix this
   3.109 -        if (show) {
   3.110 -            notifySelected(task);
   3.111 -        }
   3.112 -
   3.113 -        // TODO make this smarter later on, such that I only save when necessary
   3.114 -        save();
   3.115 -    }
   3.116 -
   3.117 -
   3.118 -    /** 
   3.119 -     * Remove a task from the list.
   3.120 -     * @param task The task to be removed. 
   3.121 -     * @deprecated use Task.remove() instead
   3.122 -     */
   3.123 -    public void remove(Task task) {
   3.124 -        Task pt = task.getParent();
   3.125 -        if (task.getParent() != null) {
   3.126 -            task.getParent().removeSubtask(task);
   3.127 -        } else {
   3.128 -            root.removeSubtask(task);
   3.129 -        }
   3.130 -        needSave = true;
   3.131 -
   3.132 -        // Ensure that we're not showing any markers for this item
   3.133 -        notifyRemoved(pt, task);
   3.134 -
   3.135 -        // TODO make this smarter later on, such that I only save when necessary
   3.136 -        save();
   3.137 -    }
   3.138 -
   3.139 -    /** 
   3.140 +    /**
   3.141       * Notify the task list that some aspect of it has been changed, so
   3.142       * it should save itself soon. Eventually calls save 
   3.143       */
   3.144 @@ -317,6 +228,7 @@
   3.145          listeners.remove(listener);
   3.146      }
   3.147  
   3.148 +    /** Fire TaskListener.changedTask */
   3.149      public void notifyChanged(Task task) {
   3.150          if (listeners != null) {
   3.151              int n = listeners.size();
   3.152 @@ -327,6 +239,7 @@
   3.153          }
   3.154      }
   3.155  
   3.156 +    /** Fire TaskListener.addedTask */
   3.157      protected void notifyAdded(Task task) {
   3.158          if (listeners != null) {
   3.159              int n = listeners.size();
   3.160 @@ -338,6 +251,7 @@
   3.161      }
   3.162  
   3.163      /**
   3.164 +     * Fire TaskListener.selectedTask
   3.165       * @deprecated splitting model from the view
   3.166       */
   3.167      public void notifySelected(Task task) {
   3.168 @@ -351,6 +265,7 @@
   3.169      }
   3.170  
   3.171      /**
   3.172 +     * Fire TaskListener.warpedTask
   3.173       * @deprecated splitting model from the view
   3.174       */
   3.175      public void notifyWarped(Task task) {
   3.176 @@ -363,6 +278,7 @@
   3.177          }
   3.178      }
   3.179  
   3.180 +    /** Fire TaskListener.structureChanged */
   3.181      public void notifyStructureChanged(Task task) {
   3.182          if (listeners != null) {
   3.183              int n = listeners.size();
   3.184 @@ -373,7 +289,8 @@
   3.185          }
   3.186      }
   3.187  
   3.188 -    public void notifyRemoved(Task pt, Task task) {
   3.189 +    /** Fire TaskListener.removedTask */
   3.190 +    protected final void fireRemoved(Task pt, Task task) {
   3.191          if (listeners != null) {
   3.192              int n = listeners.size();
   3.193              for (int i = 0; i < n; i++) {
   3.194 @@ -404,41 +321,11 @@
   3.195          return translators;
   3.196      }
   3.197  
   3.198 -    ///* For debugging purposes:
   3.199 -    public void print() {
   3.200 -        System.err.println("\nTask List:\n-------------");
   3.201 -        if (root == null) {
   3.202 -            return;
   3.203 -        }
   3.204 -        recursivePrint(root, 0);
   3.205 -        System.err.println("\n\n");
   3.206 -    }
   3.207 -
   3.208 -    private void recursivePrint(Task node, int depth) {
   3.209 -        if (depth > 20) { // probably invalid list
   3.210 -            Thread.dumpStack();
   3.211 -            return;
   3.212 -        }
   3.213 -        for (int i = 0; i < depth; i++) {
   3.214 -            System.err.print("   ");
   3.215 -        }
   3.216 -        System.err.println(node);
   3.217 -        if (node.getSubtasks() != null) {
   3.218 -            List l = node.getSubtasks();
   3.219 -            ListIterator it = l.listIterator();
   3.220 -            while (it.hasNext()) {
   3.221 -                Task task = (Task) it.next();
   3.222 -                recursivePrint(task, depth + 1);
   3.223 -            }
   3.224 -        }
   3.225 -    }
   3.226 -    // */
   3.227 -
   3.228 -    /** 
   3.229 +    /**
   3.230       * Remove all the tasks in this tasklist 
   3.231       */
   3.232      public void clear() {
   3.233 -        getRoot().clear();
   3.234 +        if (root != null) root.clear();
   3.235      }
   3.236  
   3.237      /**
   3.238 @@ -451,16 +338,20 @@
   3.239          return getRoot().getSubtasks();
   3.240      }
   3.241  
   3.242 +    // TaskListener implementation delegates events
   3.243 +
   3.244      /**
   3.245       * @deprecated
   3.246       */
   3.247      public void selectedTask(Task task) {
   3.248 +        notifySelected(task);
   3.249      }
   3.250      
   3.251      /**
   3.252       * @deprecated
   3.253       */
   3.254      public void warpedTask(Task task) {
   3.255 +        notifyWarped(task);
   3.256      }
   3.257  
   3.258      public void addedTask(Task task) {
   3.259 @@ -468,7 +359,7 @@
   3.260      }
   3.261      
   3.262      public void removedTask(Task pt, Task task) {
   3.263 -        notifyRemoved(pt, task);
   3.264 +        fireRemoved(pt, task);
   3.265      }
   3.266  
   3.267      public void changedTask(Task task) {
   3.268 @@ -478,4 +369,36 @@
   3.269      public void structureChanged(Task task) {
   3.270          notifyStructureChanged(task);
   3.271      }
   3.272 +
   3.273 +//    ///* For debugging purposes:
   3.274 +//    public void print() {
   3.275 +//        System.err.println("\nTask List:\n-------------");
   3.276 +//        if (root == null) {
   3.277 +//            return;
   3.278 +//        }
   3.279 +//        recursivePrint(root, 0);
   3.280 +//        System.err.println("\n\n");
   3.281 +//    }
   3.282 +//
   3.283 +//    private void recursivePrint(Task node, int depth) {
   3.284 +//        if (depth > 20) { // probably invalid list
   3.285 +//            Thread.dumpStack();
   3.286 +//            return;
   3.287 +//        }
   3.288 +//        for (int i = 0; i < depth; i++) {
   3.289 +//            System.err.print("   ");
   3.290 +//        }
   3.291 +//        System.err.println(node);
   3.292 +//        if (node.getSubtasks() != null) {
   3.293 +//            List l = node.getSubtasks();
   3.294 +//            ListIterator it = l.listIterator();
   3.295 +//            while (it.hasNext()) {
   3.296 +//                Task task = (Task) it.next();
   3.297 +//                recursivePrint(task, depth + 1);
   3.298 +//            }
   3.299 +//        }
   3.300 +//    }
   3.301 +//    // */
   3.302 +
   3.303 +
   3.304  }
     4.1 --- a/tasklist.docscan/src/org/netbeans/modules/tasklist/docscan/SourceTasksList.java	Fri Jan 16 19:27:24 2004 +0000
     4.2 +++ b/tasklist.docscan/src/org/netbeans/modules/tasklist/docscan/SourceTasksList.java	Fri Jan 16 21:26:02 2004 +0000
     4.3 @@ -23,7 +23,6 @@
     4.4  
     4.5  
     4.6  /**
     4.7 - * Lists suggestions for current project or source file.
     4.8   * Filters out inproper suggestions not targeted to this list.
     4.9   *
    4.10   * @author Petr Kuzel
    4.11 @@ -51,21 +50,4 @@
    4.12          super.addRemove(filtered, removeList, append, parent, after);
    4.13      }
    4.14  
    4.15 -    public void add(Task task) {
    4.16 -        if (task.getSeed() instanceof SourceTaskProvider) {
    4.17 -            super.add(task);
    4.18 -        }
    4.19 -    }
    4.20 -
    4.21 -    public void add(Task task, boolean append, boolean show) {
    4.22 -        if (task.getSeed() instanceof SourceTaskProvider) {
    4.23 -            super.add(task, append, show);
    4.24 -        }
    4.25 -    }
    4.26 -
    4.27 -    public void add(Task task, Task after, boolean show) {
    4.28 -        if (task.getSeed() instanceof SourceTaskProvider) {
    4.29 -            super.add(task, after, show);
    4.30 -        }
    4.31 -    }
    4.32  }