ItEr15S12RFComportamentoGraficoPlanificadorItEr14S13: Shrinking as required is implemented now.
This commit is contained in:
parent
1278219c08
commit
101c7609fe
3 changed files with 117 additions and 19 deletions
|
|
@ -86,12 +86,6 @@ 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ public class DependencyRegistry {
|
|||
private final DirectedGraph<TaskBean, DependencyBean> graph = new SimpleDirectedGraph<TaskBean, DependencyBean>(
|
||||
DependencyBean.class);
|
||||
|
||||
private Map<TaskBean, RulesEnforcer> rulesEnforcersByTask = new HashMap<TaskBean, RulesEnforcer>();
|
||||
private Map<TaskBean, DependencyRulesEnforcer> rulesEnforcersByTask = new HashMap<TaskBean, DependencyRulesEnforcer>();
|
||||
|
||||
private List<RulesEnforcer> getOutgoing(TaskBean task) {
|
||||
ArrayList<RulesEnforcer> result = new ArrayList<RulesEnforcer>();
|
||||
private List<DependencyRulesEnforcer> getOutgoing(TaskBean task) {
|
||||
ArrayList<DependencyRulesEnforcer> result = new ArrayList<DependencyRulesEnforcer>();
|
||||
for (DependencyBean dependencyBean : graph.outgoingEdgesOf(task)) {
|
||||
result.add(rulesEnforcersByTask
|
||||
.get(dependencyBean.getDestination()));
|
||||
|
|
@ -36,10 +36,36 @@ public class DependencyRegistry {
|
|||
return result;
|
||||
}
|
||||
|
||||
private class RulesEnforcer {
|
||||
private class ParentShrinkingEnforcer {
|
||||
|
||||
private final TaskContainerBean container;
|
||||
|
||||
private ParentShrinkingEnforcer(final TaskContainerBean container) {
|
||||
if (container == null)
|
||||
throw new IllegalArgumentException("container cannot be null");
|
||||
this.container = container;
|
||||
for (TaskBean subtask : this.container.getTasks()) {
|
||||
subtask.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Date newBeginDate = container
|
||||
.getSmallestBeginDateFromChildren();
|
||||
container.setBeginDate(newBeginDate);
|
||||
Date newEndDate = container
|
||||
.getBiggestDateFromChildren();
|
||||
container.setEndDate(newEndDate);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class DependencyRulesEnforcer {
|
||||
private final TaskBean task;
|
||||
|
||||
private RulesEnforcer(TaskBean task) {
|
||||
private DependencyRulesEnforcer(TaskBean task) {
|
||||
if (task == null)
|
||||
throw new IllegalArgumentException("task cannot be null");
|
||||
this.task = task;
|
||||
|
|
@ -47,8 +73,8 @@ public class DependencyRegistry {
|
|||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
RulesEnforcer.this.update();
|
||||
updateOutgoing(RulesEnforcer.this.task);
|
||||
DependencyRulesEnforcer.this.update();
|
||||
updateOutgoing(DependencyRulesEnforcer.this.task);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -69,16 +95,18 @@ public class DependencyRegistry {
|
|||
}
|
||||
|
||||
public void applyAllRestrictions() {
|
||||
for (RulesEnforcer rulesEnforcer : rulesEnforcersByTask.values()) {
|
||||
for (DependencyRulesEnforcer rulesEnforcer : rulesEnforcersByTask
|
||||
.values()) {
|
||||
rulesEnforcer.update();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(TaskBean task) {
|
||||
graph.addVertex(task);
|
||||
rulesEnforcersByTask.put(task, new RulesEnforcer(task));
|
||||
rulesEnforcersByTask.put(task, new DependencyRulesEnforcer(task));
|
||||
if (task instanceof TaskContainerBean) {
|
||||
TaskContainerBean container = (TaskContainerBean) task;
|
||||
new ParentShrinkingEnforcer(container);
|
||||
for (TaskBean child : container.getTasks()) {
|
||||
add(child);
|
||||
add(new DependencyBean(child, container,
|
||||
|
|
@ -90,7 +118,7 @@ public class DependencyRegistry {
|
|||
}
|
||||
|
||||
public void remove(TaskBean task) {
|
||||
List<RulesEnforcer> outgoing = getOutgoing(task);
|
||||
List<DependencyRulesEnforcer> outgoing = getOutgoing(task);
|
||||
graph.removeVertex(task);
|
||||
rulesEnforcersByTask.remove(task);
|
||||
update(outgoing);
|
||||
|
|
@ -100,8 +128,8 @@ public class DependencyRegistry {
|
|||
update(getOutgoing(task));
|
||||
}
|
||||
|
||||
private void update(List<RulesEnforcer> outgoing) {
|
||||
for (RulesEnforcer rulesEnforcer : outgoing) {
|
||||
private void update(List<DependencyRulesEnforcer> outgoing) {
|
||||
for (DependencyRulesEnforcer rulesEnforcer : outgoing) {
|
||||
rulesEnforcer.update();
|
||||
}
|
||||
}
|
||||
|
|
@ -119,7 +147,7 @@ public class DependencyRegistry {
|
|||
getEnforcer(destination).update();
|
||||
}
|
||||
|
||||
private RulesEnforcer getEnforcer(TaskBean destination) {
|
||||
private DependencyRulesEnforcer getEnforcer(TaskBean destination) {
|
||||
return rulesEnforcersByTask.get(destination);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package org.zkoss.ganttz.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -11,6 +14,51 @@ import java.util.List;
|
|||
*/
|
||||
public class TaskContainerBean extends TaskBean {
|
||||
|
||||
private static <T> List<T> removeNulls(Collection<T> elements) {
|
||||
ArrayList<T> result = new ArrayList<T>();
|
||||
for (T e : elements) {
|
||||
if (e != null) {
|
||||
result.add(e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static <T> T getSmallest(Collection<T> elements,
|
||||
Comparator<T> comparator) {
|
||||
List<T> withoutNulls = removeNulls(elements);
|
||||
if (withoutNulls.isEmpty())
|
||||
throw new IllegalArgumentException("at least one required");
|
||||
T result = null;
|
||||
for (T element : withoutNulls) {
|
||||
result = result == null ? element : (comparator.compare(result,
|
||||
element) < 0 ? result : element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static <T extends Comparable<? super T>> T getSmallest(
|
||||
Collection<T> elements) {
|
||||
return getSmallest(elements, new Comparator<T>() {
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static <T extends Comparable<? super T>> T getBiggest(
|
||||
Collection<T> elements) {
|
||||
return getSmallest(elements, new Comparator<T>() {
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<TaskBean> tasks = new ArrayList<TaskBean>();
|
||||
|
||||
public void add(TaskBean task) {
|
||||
|
|
@ -21,4 +69,32 @@ public class TaskContainerBean extends TaskBean {
|
|||
return tasks;
|
||||
}
|
||||
|
||||
public Date getSmallestBeginDateFromChildren() {
|
||||
if (tasks.isEmpty())
|
||||
return getBeginDate();
|
||||
return getSmallest(getStartDates());
|
||||
}
|
||||
|
||||
private List<Date> getStartDates() {
|
||||
ArrayList<Date> result = new ArrayList<Date>();
|
||||
for (TaskBean taskBean : tasks) {
|
||||
result.add(taskBean.getBeginDate());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Date> getEndDates() {
|
||||
ArrayList<Date> result = new ArrayList<Date>();
|
||||
for (TaskBean taskBean : tasks) {
|
||||
result.add(taskBean.getEndDate());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Date getBiggestDateFromChildren() {
|
||||
if (tasks.isEmpty())
|
||||
return getEndDate();
|
||||
return getBiggest(getEndDates());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue