ItEr15S12RFComportamentoGraficoPlanificadorItEr14S13: Container grows as needed when the contained tasks are moved. Shrinking when required is pending.

This commit is contained in:
Óscar González Fernández 2009-07-01 21:54:02 +02:00 committed by Javier Moran Rua
parent 6f3a245586
commit 1278219c08
10 changed files with 91 additions and 25 deletions

View file

@ -28,7 +28,7 @@ public class GanttPanel extends XulElement implements AfterCompose {
public void afterCompose() {
tasksLists.afterCompose();
dependencyList.setDependencies(tasksLists
.asDependencies(dependencyRegistry.getDependencies()));
.asDependencies(dependencyRegistry.getVisibleDependencies()));
timeTracker.afterCompose();
dependencyList.afterCompose();
}

View file

@ -86,6 +86,12 @@ public class ListDetails extends HtmlMacroComponent {
private TaskDetail addTask(TaskBean taskBean) {
TaskDetail taskDetail = TaskDetail.create(taskBean);
getInsertionPoint().appendChild(taskDetail);
if (taskBean instanceof TaskContainerBean) {
TaskContainerBean container = (TaskContainerBean) taskBean;
for (TaskBean t : container.getTasks()) {
addTask(t);
}
}
taskDetail.afterCompose();
return taskDetail;
}

View file

@ -10,7 +10,6 @@ import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zul.impl.XulElement;
import org.zkoss.zk.au.out.AuInvoke;
public class Planner extends XulElement implements AfterCompose {
@ -129,7 +128,7 @@ public class Planner extends XulElement implements AfterCompose {
}
public void addTaskContainer(TaskContainerBean newTaskContainer) {
getTaskList().addTaskContainer(newTaskContainer);
getTaskList().addTask(newTaskContainer);
dependencyRegistry.add(newTaskContainer);
}

View file

@ -17,6 +17,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.zkoss.ganttz.util.TaskBean;
import org.zkoss.ganttz.util.TaskContainerBean;
import org.zkoss.lang.Objects;
import org.zkoss.xml.HTMLs;
import org.zkoss.zk.au.AuRequest;
@ -127,11 +128,14 @@ public class Task extends Div implements AfterCompose {
};
public static Task asTask(TaskBean taskBean) {
if (taskBean instanceof TaskContainerBean) {
return TaskContainer.asTask((TaskContainerBean) taskBean);
}
return new Task(taskBean);
}
public Task(TaskBean taskBean) {
setHeight( HEIGHT_PER_TASK + "px");
setHeight(HEIGHT_PER_TASK + "px");
setContext("idContextMenuTaskAssigment");
this.taskBean = taskBean;
setColor(STANDARD_TASK_COLOR);

View file

@ -18,7 +18,6 @@ import org.zkoss.ganttz.util.MenuBuilder;
import org.zkoss.ganttz.util.TaskBean;
import org.zkoss.ganttz.util.WeakReferencedListeners;
import org.zkoss.ganttz.util.MenuBuilder.ItemAction;
import org.zkoss.ganttz.util.TaskContainerBean;
import org.zkoss.ganttz.util.WeakReferencedListeners.ListenerNotification;
import org.zkoss.ganttz.util.zoom.ZoomLevel;
import org.zkoss.ganttz.util.zoom.ZoomLevelChangedListener;
@ -36,7 +35,7 @@ import org.zkoss.zul.impl.XulElement;
*/
public class TaskList extends XulElement implements AfterCompose {
private static final int HEIGHT_PER_ROW = 20; /* 30 */
private static final int HEIGHT_PER_ROW = 20; /* 30 */
private List<WeakReference<DependencyAddedListener>> listeners = new LinkedList<WeakReference<DependencyAddedListener>>();
@ -80,10 +79,6 @@ public class TaskList extends XulElement implements AfterCompose {
addTask(Task.asTask(newTask), true);
}
public void addTaskContainer(TaskContainerBean newTaskContainer) {
addTask(TaskContainer.asTask(newTaskContainer), true);
}
public synchronized void addTask(final Task task, boolean relocate) {
task.setParent(this);
addContextMenu(task);

View file

@ -7,9 +7,7 @@ import java.util.Date;
* This class represents a dependency. Contains the source and the destination.
* It also specifies the type of the relationship. <br/>
* Created at Apr 24, 2009
*
* @author Óscar González Fernández <ogonzalez@igalia.com>
*
*/
public class DependencyBean {
@ -53,8 +51,10 @@ public class DependencyBean {
private final DependencyType type;
private final boolean visible;
public DependencyBean(TaskBean source, TaskBean destination,
DependencyType type) {
DependencyType type, boolean visible) {
if (source == null)
throw new IllegalArgumentException("source cannot be null");
if (destination == null)
@ -64,6 +64,12 @@ public class DependencyBean {
this.source = source;
this.destination = destination;
this.type = type;
this.visible = visible;
}
public DependencyBean(TaskBean source, TaskBean destination,
DependencyType type) {
this(source, destination, type, true);
}
@Override
@ -110,4 +116,8 @@ public class DependencyBean {
return type;
}
public boolean isVisible() {
return visible;
}
}

View file

@ -68,9 +68,25 @@ public class DependencyRegistry {
}
}
public void applyAllRestrictions() {
for (RulesEnforcer rulesEnforcer : rulesEnforcersByTask.values()) {
rulesEnforcer.update();
}
}
public void add(TaskBean task) {
graph.addVertex(task);
rulesEnforcersByTask.put(task, new RulesEnforcer(task));
if (task instanceof TaskContainerBean) {
TaskContainerBean container = (TaskContainerBean) task;
for (TaskBean child : container.getTasks()) {
add(child);
add(new DependencyBean(child, container,
DependencyType.END_END, false));
add(new DependencyBean(container, child,
DependencyType.START_START, false));
}
}
}
public void remove(TaskBean task) {
@ -111,9 +127,15 @@ public class DependencyRegistry {
return new ArrayList<TaskBean>(graph.vertexSet());
}
public List<DependencyBean> getDependencies() {
public List<DependencyBean> getVisibleDependencies() {
Set<DependencyBean> edgeSet = graph.edgeSet();
return new ArrayList<DependencyBean>(edgeSet);
ArrayList<DependencyBean> result = new ArrayList<DependencyBean>();
for (DependencyBean dependencyBean : edgeSet) {
if (dependencyBean.isVisible()) {
result.add(dependencyBean);
}
}
return result;
}
}

View file

@ -1,13 +1,24 @@
package org.zkoss.ganttz.util;
import java.util.ArrayList;
import java.util.List;
/**
* This class contains the information of a task container. It can be modified and
* notifies of the changes to the interested parties. <br/>
* This class contains the information of a task container. It can be modified
* and notifies of the changes to the interested parties. <br/>
* Created at Jul 1, 2009
*
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*
*/
public class TaskContainerBean extends TaskBean {
private List<TaskBean> tasks = new ArrayList<TaskBean>();
public void add(TaskBean task) {
tasks.add(task);
}
public List<TaskBean> getTasks() {
return tasks;
}
}

View file

@ -7,6 +7,7 @@ import org.zkoss.ganttz.util.DependencyBean;
import org.zkoss.ganttz.util.DependencyRegistry;
import org.zkoss.ganttz.util.DependencyType;
import org.zkoss.ganttz.util.TaskBean;
import org.zkoss.ganttz.util.TaskContainerBean;
/**
* Some test data for planner <br />
@ -39,22 +40,40 @@ public class DataForPlanner {
Date end = twoMonthsLater(now);
TaskBean first = null;
TaskBean second = null;
for (int i = 0; i < tasksToCreate; i++) {
TaskBean taskBean = new TaskBean();
for (int i = 0; i < tasksToCreate - 3; i++) {
String name = "tarefa " + (i + 1);
TaskBean taskBean = createTaskBean(name, now, end);
if (i == 0)
first = taskBean;
if (i == 1)
second = taskBean;
taskBean.setName("tarefa " + (i + 1));
taskBean.setBeginDate(now);
taskBean.setEndDate(end);
dependencyRegistry.add(taskBean);
}
TaskContainerBean container = new TaskContainerBean();
container.setBeginDate(now);
container.setEndDate(end);
container.setName("container");
TaskBean child1 = createTaskBean("child 1", now, end);
container.add(child1);
TaskBean child2 = createTaskBean("child 2", now, end);
container.add(child2);
dependencyRegistry.add(container);
dependencyRegistry.add(new DependencyBean(child1, child2,
DependencyType.END_START));
dependencyRegistry.add(new DependencyBean(first, second,
DependencyType.END_START));
dependencyRegistry.applyAllRestrictions();
return dependencyRegistry;
}
private TaskBean createTaskBean(String name, Date now, Date end) {
TaskBean taskBean = new TaskBean();
taskBean.setName(name);
taskBean.setBeginDate(now);
taskBean.setEndDate(end);
return taskBean;
}
private static Date twoMonthsLater(Date now) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(now);

View file

@ -12,7 +12,7 @@
</zscript>
<!-- choose lightLoad, mediumLoad or highLoad.
-->
<planner id="planner" self="@{define(content)}" dependencyRegistry="${plannerData.mediumLoad}">
<planner id="planner" self="@{define(content)}" dependencyRegistry="${plannerData.lightLoad}">
<div id="idContextMenuTaskAssigment"
use="org.zk.myhello.pages.MyHelloPageListener">
</div>