1 19 20 package org.netbeans.modules.tasklist.suggestions; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.ListIterator ; 28 import java.util.Map ; 29 30 import org.netbeans.modules.tasklist.core.TaskList; 31 import org.netbeans.modules.tasklist.core.TaskListView; 32 import org.netbeans.modules.tasklist.core.TaskNode; 33 import org.netbeans.modules.tasklist.core.Task; 34 import org.netbeans.modules.tasklist.client.SuggestionManager; 35 36 import org.openide.nodes.Node; 37 import org.openide.util.NbBundle; 38 39 40 46 public class SuggestionList extends TaskList { 47 48 52 private static final int MAX_INLINE = 20; 53 54 static final Object CATEGORY_NODE_SEED = new Object (); 55 56 private final int groupTreshold; 57 58 59 public SuggestionList() { 60 this(MAX_INLINE); 61 } 62 63 public SuggestionList(int groupTreshold) { 64 this.groupTreshold = groupTreshold; 65 } 66 67 synchronized SuggestionImpl getCategoryTask(SuggestionType type, 68 boolean create) { 69 SuggestionImpl category = null; 70 if (categoryTasks != null) { 71 category = (SuggestionImpl)categoryTasks.get(type); 72 } 73 if (create && (category == null)) { 74 category = new SuggestionImpl(null, 75 type.getLocalizedName(),type, null, CATEGORY_NODE_SEED); 76 category.setType(type.getName()); 77 category.setIcon(type.getIconImage()); 78 category.setVisitable(false); 79 SuggestionManagerImpl manager = 82 (SuggestionManagerImpl)SuggestionManager.getDefault(); 83 if (manager.isExpandedType(type)) { 84 } 96 97 if (categoryTasks == null) { 98 categoryTasks = new HashMap (20); 99 } 100 categoryTasks.put(type, category); 101 SuggestionImpl after = findAfter(type); 103 if (after != null) { 104 addCategory(category, after); 105 } else { 106 addCategory(category, false); 107 } 108 } 109 return category; 110 } 111 112 120 private void addCategory(Task task, Task after) { 121 if (task.getParent() == null) { appendTask(task); 123 } else { 124 Task parent = task.getParent(); 125 parent.removeSubtask(task); 127 parent.addSubtask(task, after); 128 } 129 } 130 131 132 137 private void addCategory(Task task, boolean append) { if (task.getParent() == null) { 139 appendTask(task); 140 } else { 141 Task parent = task.getParent(); 143 parent.removeSubtask(task); 144 parent.addSubtask(task, append); 145 } 146 } 147 148 149 private Map categoryTasks = null; 150 151 153 SuggestionImpl findAfter(SuggestionType type) { 154 SuggestionImpl after = null; 155 int pos = type.getPosition(); 156 Iterator it = getTasks().iterator(); 157 int i = 0; 158 while (it.hasNext()) { 159 i++; 160 SuggestionImpl s = (SuggestionImpl)it.next(); 161 int spos = s.getSType().getPosition(); 162 if (spos > pos) { 163 break; 164 } else { 165 after = s; 166 } 167 } 168 169 if (i == getTasks().size()) { 171 return null; 172 } else { 173 return after; 174 } 175 } 176 177 180 synchronized void removeCategory(SuggestionImpl category, boolean force) { 181 if ((category != null) && (force || !category.hasSubtasks())) { 183 category.getParent().removeSubtask(category); 184 categoryTasks.remove(category.getSType()); 185 } 186 } 187 188 synchronized void removeCategory(SuggestionType type) { 189 if (getTasks().size() == 0) { 190 categoryTasks = null; 191 return; 192 } 193 Iterator ti = getTasks().iterator(); 194 ArrayList removeTasks = new ArrayList (50); 195 while (ti.hasNext()) { 196 SuggestionImpl suggestion = (SuggestionImpl)ti.next(); 197 if (suggestion.getSType() == type) { 198 removeTasks.add(suggestion); 199 } 200 } 201 addRemove(null, removeTasks, false, null, null); 202 if (categoryTasks != null) { 203 categoryTasks.remove(type); 204 } 205 } 206 207 208 209 public Collection getCategoryTasks() { 210 if (categoryTasks != null) { 211 return categoryTasks.values(); 212 } 213 return null; 214 } 215 216 void clearCategoryTasks() { 217 categoryTasks = null; } 219 220 221 226 final int getGroupTreshold() { 227 return groupTreshold; } 229 230 } 231 | Popular Tags |