Verify tree model by checking for missing tasks on initialization

pull/14/head
Sam Bosley 12 years ago
parent df36dcc808
commit 113e671550

@ -61,6 +61,7 @@ public abstract class NewOrderedListUpdater<LIST> {
protected void initialize(LIST list, Filter filter) {
treeRoot = buildTreeModel(getSerializedTree(list, filter));
verifyTreeModel(list, filter);
}
protected String serializedTreeFromFilter(Filter filter) {
@ -82,6 +83,27 @@ public abstract class NewOrderedListUpdater<LIST> {
return array.toString();
}
private void verifyTreeModel(LIST list, Filter filter) {
boolean addedThings = false;
TodorooCursor<Task> tasks = taskService.fetchFiltered(filter.getSqlQuery(), null, Task.ID);
try {
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
Long id = tasks.getLong(0);
if (idToNode.containsKey(id))
continue;
addedThings = true;
Node newNode = new Node(id, treeRoot, 0);
treeRoot.children.add(newNode);
idToNode.put(id, newNode);
}
} finally {
tasks.close();
}
if (addedThings)
writeSerialization(list, serializeTree());
}
public Long[] getOrderedIds() {
ArrayList<Long> ids = new ArrayList<Long>();
orderedIdHelper(treeRoot, ids);
@ -240,8 +262,12 @@ public abstract class NewOrderedListUpdater<LIST> {
}
public void onAddTask(LIST list, Filter filter, long taskId) {
if (idToNode.containsKey(taskId))
return;
Node newNode = new Node(taskId, treeRoot, 0);
treeRoot.children.add(newNode);
idToNode.put(taskId, newNode);
writeSerialization(list, serializeTree());
applyToFilter(filter);
}

@ -53,6 +53,7 @@ public class SubtasksUpdater extends NewOrderedListUpdater<TagData> {
} else {
order = list.getValue(TagData.TAG_ORDERING);
}
if (order == null || "[]".equals(order)) { //$NON-NLS-1$
order = serializedTreeFromFilter(filter);
writeSerialization(list, order);

Loading…
Cancel
Save