ItEr50S04ValidacionEProbasFuncionaisItEr49S04: Simplifying addTasks to a position using reload mechanism
This commit is contained in:
parent
b8f86c8fdf
commit
98f8a960e2
2 changed files with 12 additions and 108 deletions
|
|
@ -21,13 +21,10 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.zkoss.ganttz.data.Position;
|
||||
import org.zkoss.ganttz.data.Task;
|
||||
import org.zkoss.ganttz.data.TaskContainer;
|
||||
import org.zkoss.ganttz.data.TaskContainer.IExpandListener;
|
||||
|
|
@ -94,35 +91,6 @@ public class TaskContainerComponent extends TaskComponent implements
|
|||
super.remove();
|
||||
}
|
||||
|
||||
private void add(Integer insertionPosition,
|
||||
Collection<? extends Task> newTasks) {
|
||||
List<TaskComponent> taskComponents = new ArrayList<TaskComponent>();
|
||||
for (Task task : newTasks) {
|
||||
taskComponents.add(createChild(task));
|
||||
}
|
||||
|
||||
if (insertionPosition == null) {
|
||||
subtaskComponents.addAll(taskComponents);
|
||||
} else {
|
||||
subtaskComponents.addAll(insertionPosition, taskComponents);
|
||||
}
|
||||
|
||||
if (isExpanded()) {
|
||||
TaskComponent previous = insertionPosition == 0 ? this
|
||||
: subtaskComponents.get(insertionPosition - 1);
|
||||
addAllAt(previous.getRow(), taskComponents, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAllAt(TaskRow previous, List<TaskComponent> toAdd,
|
||||
boolean recolate) {
|
||||
for (TaskComponent subtaskComponent : toAdd) {
|
||||
taskList.addTaskComponent((TaskRow) previous.getNextSibling(),
|
||||
subtaskComponent, recolate);
|
||||
previous = subtaskComponent.getRow();
|
||||
}
|
||||
}
|
||||
|
||||
private List<TaskComponent> getCurrentComponents() {
|
||||
ListIterator<TaskComponent> listIterator = subtaskComponents
|
||||
.listIterator();
|
||||
|
|
@ -136,17 +104,6 @@ public class TaskContainerComponent extends TaskComponent implements
|
|||
return subtaskComponents;
|
||||
}
|
||||
|
||||
private static int find(List<TaskComponent> currentComponents, Task task) {
|
||||
int i = 0;
|
||||
for (TaskComponent t : currentComponents) {
|
||||
if (t.getTask().equals(task)) {
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean isExpanded() {
|
||||
return getTaskContainer().isExpanded();
|
||||
}
|
||||
|
|
@ -160,26 +117,4 @@ public class TaskContainerComponent extends TaskComponent implements
|
|||
return super.calculateClass() + " "
|
||||
+ (getTaskContainer().isExpanded() ? "expanded" : "closed");
|
||||
}
|
||||
|
||||
public void insert(Position position, Collection<? extends Task> newTasks) {
|
||||
if (position.getParent().equals(getTask())) {
|
||||
add(position.getInsertionPosition(), newTasks);
|
||||
} else {
|
||||
Task mostRemoteAncestor = position.getMostRemoteAncestor();
|
||||
Validate.isTrue(mostRemoteAncestor.equals(getTask()));
|
||||
position = position.pop();
|
||||
Task next = position.getMostRemoteAncestor();
|
||||
List<TaskComponent> currentComponents = getCurrentComponents();
|
||||
int find = find(currentComponents, next);
|
||||
TaskComponent taskComponent = currentComponents.get(find);
|
||||
if (taskComponent instanceof TaskContainerComponent) {
|
||||
TaskContainerComponent container = (TaskContainerComponent) taskComponent;
|
||||
container.insert(position, newTasks);
|
||||
} else {
|
||||
// TODO turn TaskComponent into container
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
return asDependencyComponents(Arrays.asList(dependency)).get(0);
|
||||
}
|
||||
|
||||
public synchronized void addTaskComponent(TaskRow beforeThis,
|
||||
private synchronized void addTaskComponent(TaskRow beforeThis,
|
||||
final TaskComponent taskComponent, boolean relocate) {
|
||||
insertBefore(taskComponent.getRow(), beforeThis);
|
||||
addContextMenu(taskComponent);
|
||||
|
|
@ -130,42 +130,17 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void addTaskComponent(
|
||||
final TaskComponent taskComponent, boolean relocate) {
|
||||
addTaskComponent(null, taskComponent, relocate);
|
||||
}
|
||||
|
||||
public void addTasks(Position position, Collection<? extends Task> newTasks) {
|
||||
publishAsComponents(newTasks);
|
||||
if (position.isAppendToTop()) {
|
||||
for (Task t : newTasks) {
|
||||
TaskComponent taskComponent = TaskComponent.asTaskComponent(t,
|
||||
this);
|
||||
addTaskComponent(taskComponent, true);
|
||||
taskComponent.publishTaskComponents(taskComponentByTask);
|
||||
}
|
||||
currentTotalTasks.addAll(newTasks);
|
||||
} else if (position.isAtTop()) {
|
||||
final int insertionPosition = position.getInsertionPosition();
|
||||
List<TaskComponent> topTaskComponents = getTopLevelTaskComponents();
|
||||
TaskRow beforeThis = insertionPosition < topTaskComponents.size() ? topTaskComponents
|
||||
.get(insertionPosition).getRow()
|
||||
: null;
|
||||
for (Task t : newTasks) {
|
||||
TaskComponent toAdd = TaskComponent.asTaskComponent(t, this);
|
||||
addTaskComponent(beforeThis, toAdd, true);
|
||||
toAdd.publishTaskComponents(taskComponentByTask);
|
||||
beforeThis = (TaskRow) toAdd.getRow().getNextSibling();
|
||||
}
|
||||
} else {
|
||||
Task mostRemoteAncestor = position.getMostRemoteAncestor();
|
||||
TaskComponent taskComponent = find(mostRemoteAncestor);
|
||||
if (taskComponent instanceof TaskContainerComponent) {
|
||||
TaskContainerComponent container = (TaskContainerComponent) taskComponent;
|
||||
container.insert(position, newTasks);
|
||||
} else {
|
||||
// TODO turn taskComponent into container
|
||||
}
|
||||
|
||||
currentTotalTasks.addAll(insertionPosition, newTasks);
|
||||
}
|
||||
// if the position is children of some already existent task when
|
||||
// reloading it will be added if the predicate tells so
|
||||
reload(true);
|
||||
}
|
||||
|
||||
TaskComponent find(Task task) {
|
||||
|
|
@ -223,16 +198,6 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
return getTimeTrackerComponent().getTimeTracker();
|
||||
}
|
||||
|
||||
private List<TaskComponent> getTopLevelTaskComponents() {
|
||||
List<TaskComponent> result = new ArrayList<TaskComponent>();
|
||||
for (TaskComponent taskComponent : getTaskComponents()) {
|
||||
if (taskComponent.isTopLevel()) {
|
||||
result.add(taskComponent);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<TaskComponent> getTaskComponents() {
|
||||
ArrayList<TaskComponent> result = new ArrayList<TaskComponent>();
|
||||
for (Object child : getChildren()) {
|
||||
|
|
@ -257,7 +222,11 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
|
||||
private void publishOriginalTasksAsComponents() {
|
||||
taskComponentByTask = new HashMap<Task, TaskComponent>();
|
||||
for (Task task : currentTotalTasks) {
|
||||
publishAsComponents(currentTotalTasks);
|
||||
}
|
||||
|
||||
private void publishAsComponents(Collection<? extends Task> newTasks) {
|
||||
for (Task task : newTasks) {
|
||||
TaskComponent taskComponent = TaskComponent.asTaskComponent(task,
|
||||
this);
|
||||
taskComponent.publishTaskComponents(taskComponentByTask);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue