ItEr06S03ArquitecturaClientesItEr05S03: Fixing bug. When a task is removed the task detail wasn't removed.

This commit is contained in:
Óscar González Fernández 2009-04-29 17:40:02 +02:00 committed by Javier Moran Rua
parent 8c47fb0216
commit b1555cb111
3 changed files with 35 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package org.zkoss.ganttz; package org.zkoss.ganttz;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -12,6 +13,7 @@ import org.zkoss.zk.ui.HtmlMacroComponent;
public class ListDetails extends HtmlMacroComponent { public class ListDetails extends HtmlMacroComponent {
private static Log LOG = LogFactory.getLog(ListDetails.class); private static Log LOG = LogFactory.getLog(ListDetails.class);
private TaskRemovedListener taskRemovedListener;
public ListDetails() { public ListDetails() {
LOG.info("constructing list details"); LOG.info("constructing list details");
@ -21,6 +23,26 @@ public class ListDetails extends HtmlMacroComponent {
return (Planner) getParent(); return (Planner) getParent();
} }
private List<TaskDetail> getTaskDetails() {
List<Object> children = getInsertionPoint().getChildren();
return Planner.findComponentsOfType(TaskDetail.class, children);
}
public void taskRemoved(Task taskRemoved) {
List<TaskDetail> taskDetails = getTaskDetails();
for (TaskDetail taskDetail : taskDetails) {
if (taskDetail.getTaskId().equals(taskRemoved.getId())) {
removeDetail(taskDetail);
return;
}
}
throw new RuntimeException("not found taskDetail for " + taskRemoved);
}
private void removeDetail(TaskDetail taskDetail) {
getInsertionPoint().getChildren().remove(taskDetail);
}
public void addTask() { public void addTask() {
TaskDetail taskDetail = new TaskDetail(); TaskDetail taskDetail = new TaskDetail();
String newId = UUID.randomUUID().toString(); String newId = UUID.randomUUID().toString();
@ -29,7 +51,7 @@ public class ListDetails extends HtmlMacroComponent {
taskDetail.setDynamicProperty("length", "30 days"); taskDetail.setDynamicProperty("length", "30 days");
taskDetail.setDynamicProperty("taskName", Labels taskDetail.setDynamicProperty("taskName", Labels
.getLabel("task.new_task_name")); .getLabel("task.new_task_name"));
Component insertionPoint = getFellow("insertionPoint"); Component insertionPoint = getInsertionPoint();
taskDetail.setParent(insertionPoint); taskDetail.setParent(insertionPoint);
taskDetail.afterCompose(); taskDetail.afterCompose();
Task task = new Task(); Task task = new Task();
@ -38,4 +60,8 @@ public class ListDetails extends HtmlMacroComponent {
task.setId(newId); task.setId(newId);
} }
private Component getInsertionPoint() {
return getFellow("insertionPoint");
}
} }

View file

@ -25,7 +25,7 @@ public class Planner extends XulElement implements AfterCompose {
public Planner() { public Planner() {
} }
private TaskList getTaskList() { TaskList getTaskList() {
List<Object> children = findOneComponentOfType(GanttPanel.class) List<Object> children = findOneComponentOfType(GanttPanel.class)
.getChildren(); .getChildren();
return Planner.findComponentsOfType(TaskList.class, children).get(0); return Planner.findComponentsOfType(TaskList.class, children).get(0);
@ -77,6 +77,11 @@ public class Planner extends XulElement implements AfterCompose {
return findComponentsOfType(DependencyList.class, children).get(0); return findComponentsOfType(DependencyList.class, children).get(0);
} }
private ListDetails getDetails() {
List<Object> children = getChildren();
return Planner.findComponentsOfType(ListDetails.class, children).get(0);
}
@Override @Override
public void afterCompose() { public void afterCompose() {
TaskList taskList = getTaskList(); TaskList taskList = getTaskList();
@ -91,6 +96,8 @@ public class Planner extends XulElement implements AfterCompose {
@Override @Override
public void taskRemoved(Task taskRemoved) { public void taskRemoved(Task taskRemoved) {
dependencyRegistry.remove(taskRemoved.getTaskBean()); dependencyRegistry.remove(taskRemoved.getTaskBean());
getDetails().taskRemoved(taskRemoved);
getGanntPanel().invalidate();
} }
}; };
taskList.addTaskRemovedListener(taskRemovedListener); taskList.addTaskRemovedListener(taskRemovedListener);

View file

@ -203,7 +203,6 @@ public class Task extends Div {
// Command action to do // Command action to do
void doUpdatePosition(String leftX, String topY) { void doUpdatePosition(String leftX, String topY) {
System.out.println("leftX:" + getLeft() + "newLeft:" + leftX); System.out.println("leftX:" + getLeft() + "newLeft:" + leftX);
setTop(topY);
this.taskBean.setBeginDate(getMapper().toDate(stripPx(leftX))); this.taskBean.setBeginDate(getMapper().toDate(stripPx(leftX)));
} }