ItEr22S12CUVistaRecursosTempoPorProxectoItEr21S07: Rendering the data to be shown

This commit is contained in:
Óscar González Fernández 2009-08-22 16:08:28 +02:00
parent f56f511be8
commit dcab89f93e
7 changed files with 192 additions and 102 deletions

View file

@ -2,77 +2,98 @@ package org.zkoss.ganttz.resourceload;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.zkoss.ganttz.data.resourceload.ResourceLoad;
import org.zkoss.ganttz.data.resourceload.ResourceLoadLevel;
import org.zkoss.zk.au.out.AuInvoke;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.joda.time.LocalDate;
import org.zkoss.ganttz.IDatesMapper;
import org.zkoss.ganttz.TimeTracker;
import org.zkoss.ganttz.data.resourceload.LoadPeriod;
import org.zkoss.ganttz.data.resourceload.LoadTimeLine;
import org.zkoss.ganttz.util.zoom.IZoomLevelChangedListener;
import org.zkoss.ganttz.util.zoom.ZoomLevel;
import org.zkoss.zul.Div;
import org.zkoss.zul.impl.XulElement;
/**
* This class wraps ResourceLoad data inside an specific HTML Div component.
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
public class ResourceLoadComponent extends Div implements AfterCompose {
public class ResourceLoadComponent extends XulElement {
private static final int HEIGHT_PER_ROW = 10;
private final ResourceLoad resourceLoad;
private List<ResourceLoadInterval> children;
public static ResourceLoadComponent create(TimeTracker timeTracker,
LoadTimeLine loadLine) {
return new ResourceLoadComponent(timeTracker, loadLine);
}
public class ResourceLoadInterval extends Div {
private final LoadTimeLine loadLine;
private final TimeTracker timeTracker;
private IZoomLevelChangedListener zoomChangedListener;
private int length;
private ResourceLoadLevel loadLevel;
private int loadPercentage;
private ResourceLoadComponent(final TimeTracker timeTracker,
final LoadTimeLine loadLine) {
this.loadLine = loadLine;
this.timeTracker = timeTracker;
createChildren(loadLine, timeTracker.getMapper());
zoomChangedListener = new IZoomLevelChangedListener() {
public ResourceLoadInterval(int length, int loadPercentage) {
this.length = length;
this.loadPercentage = loadPercentage;
this.loadLevel= ResourceLoadLevel.getFromPercentage(loadPercentage);
@Override
public void zoomLevelChanged(ZoomLevel detailLevel) {
getChildren().clear();
createChildren(loadLine, timeTracker.getMapper());
}
};
this.timeTracker.addZoomListener(zoomChangedListener);
}
private void createChildren(LoadTimeLine loadLine, IDatesMapper mapper) {
List<Div> divs = createDivsForPeriods(mapper, loadLine.getLoadPeriods());
for (Div div : divs) {
appendChild(div);
}
public int getLenght() {
return this.length;
}
public ResourceLoadLevel getLoadLevel() {
return this.loadLevel;
}
}
public ResourceLoadComponent(ResourceLoad resourceLoad) {
setHeight(HEIGHT_PER_ROW + "px");
setContext("idContextMenuTaskAssigment");
this.resourceLoad = resourceLoad;
// Added some example ResourceLoadIntervals
this.children = new ArrayList<ResourceLoadInterval>();
setId(UUID.randomUUID().toString());
}
protected String calculateClass() {
return "box";
}
protected void updateClass() {
response(null, new AuInvoke(this, "setClass",
new Object[] { calculateClass() }));
}
public void afterCompose() {
}
public String getResourceLoadName() {
return this.resourceLoad.getName();
return loadLine.getConceptName();
}
public List<ResourceLoadInterval> getChildren() {
return this.children;
private static List<Div> createDivsForPeriods(IDatesMapper datesMapper,
List<LoadPeriod> loadPeriods) {
List<Div> result = new ArrayList<Div>();
for (LoadPeriod loadPeriod : loadPeriods) {
result.add(createDivForPeriod(datesMapper, loadPeriod));
}
return result;
}
public void addInterval(int length, int plannificationPercentage) {
this.children.add(new ResourceLoadInterval(length, plannificationPercentage));
private static Div createDivForPeriod(IDatesMapper datesMapper,
LoadPeriod loadPeriod) {
Div result = new Div();
result.setClass(String.format("taskassignmentinterval %s", loadPeriod
.getLoadLevel().getCategory()));
result.setLeft(forCSS(getStartPixels(datesMapper, loadPeriod)));
result.setWidth(forCSS(getWidthPixels(datesMapper, loadPeriod)));
return result;
}
private static int getWidthPixels(IDatesMapper datesMapper,
LoadPeriod loadPeriod) {
LocalDate start = loadPeriod.getStart();
LocalDate end = loadPeriod.getEnd();
return datesMapper
.toPixels(toMilliseconds(end) - toMilliseconds(start));
}
private static long toMilliseconds(LocalDate localDate) {
return localDate.toDateMidnight().getMillis();
}
private static String forCSS(int pixels) {
return String.format("%dpx", pixels);
}
private static int getStartPixels(IDatesMapper datesMapper,
LoadPeriod loadPeriod) {
return datesMapper.toPixels(loadPeriod.getStart().toDateMidnight()
.toDate());
}
}

View file

@ -1,20 +1,43 @@
package org.zkoss.ganttz.resourceload;
import java.util.List;
import org.zkoss.ganttz.data.resourceload.LoadTimeLine;
import org.zkoss.ganttz.data.resourceload.LoadTimelinesGroup;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Div;
import org.zkoss.zul.Label;
import org.zkoss.zul.impl.XulElement;
public class ResourceLoadLeftPane extends XulElement {
public ResourceLoadLeftPane() {
appendChild(createFakeRow());
appendChild(createFakeRow());
public ResourceLoadLeftPane(List<LoadTimelinesGroup> groups) {
for (LoadTimelinesGroup loadTimelinesGroup : groups) {
LoadTimeLine principal = loadTimelinesGroup.getPrincipal();
appendChild(createFirstLevel(principal));
for (LoadTimeLine loadTimeLine : loadTimelinesGroup.getChildren()) {
appendChild(createSecondLevel(loadTimeLine));
}
}
}
private Div createFakeRow() {
private Component createFirstLevel(LoadTimeLine principal) {
Div result = createLabelWithName(principal);
result.setSclass("firstlevel");
return result;
}
private Component createSecondLevel(LoadTimeLine loadTimeLine) {
Div result = createLabelWithName(loadTimeLine);
result.setSclass("secondlevel");
return result;
}
private Div createLabelWithName(LoadTimeLine principal) {
Div result = new Div();
Label label = new Label();
label.setValue("test");
label.setValue(principal.getConceptName());
result.appendChild(label);
return result;
}

View file

@ -1,8 +1,11 @@
package org.zkoss.ganttz.resourceload;
import java.util.ArrayList;
import java.util.List;
import org.zkoss.ganttz.data.resourceload.ResourceLoad;
import org.zkoss.ganttz.TimeTracker;
import org.zkoss.ganttz.data.resourceload.LoadTimeLine;
import org.zkoss.ganttz.data.resourceload.LoadTimelinesGroup;
import org.zkoss.zul.impl.XulElement;
/**
@ -11,32 +14,22 @@ import org.zkoss.zul.impl.XulElement;
*/
public class ResourceLoadList extends XulElement {
private List<ResourceLoad> resourceLoads;
public ResourceLoadList(List<ResourceLoad> resourceLoads) {
this.resourceLoads = resourceLoads;
insertFakeData();
public ResourceLoadList(TimeTracker timeTracker,
List<LoadTimelinesGroup> groups) {
for (LoadTimelinesGroup l : groups) {
ArrayList<LoadTimeLine> toInsert = new ArrayList<LoadTimeLine>();
toInsert.add(l.getPrincipal());
toInsert.addAll(l.getChildren());
insertAsComponents(timeTracker, toInsert);
}
}
private void insertFakeData() {
ResourceLoadComponent rlc1 = new ResourceLoadComponent(
new ResourceLoad("ResourceLoad 1"));
ResourceLoadComponent rlc2 = new ResourceLoadComponent(
new ResourceLoad("ResourceLoad 1"));
rlc1.addInterval(40, 100);
rlc1.addInterval(20, 80);
rlc1.addInterval(30, 150);
rlc1.addInterval(10, 0);
rlc2.addInterval(10, 100);
rlc2.addInterval(20, 60);
rlc2.addInterval(30, 100);
rlc2.addInterval(20, 0);
rlc2.addInterval(20, 60);
appendChild(rlc1);
appendChild(rlc2);
private void insertAsComponents(TimeTracker timetracker,
List<LoadTimeLine> children) {
for (LoadTimeLine loadTimeLine : children) {
appendChild(ResourceLoadComponent.create(timetracker, loadTimeLine));
}
}
}

View file

@ -1,11 +1,11 @@
package org.zkoss.ganttz.resourceload;
import java.util.Collections;
import java.util.List;
import org.zkoss.ganttz.Planner;
import org.zkoss.ganttz.TimeTracker;
import org.zkoss.ganttz.TimeTrackerComponent;
import org.zkoss.ganttz.data.resourceload.ResourceLoad;
import org.zkoss.ganttz.data.resourceload.LoadTimelinesGroup;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zul.impl.XulElement;
@ -17,11 +17,14 @@ public class ResourcesLoadPanel extends XulElement implements AfterCompose {
private ResourceLoadList resourceLoadList;
public ResourcesLoadPanel(TimeTracker timeTracker) {
private final List<LoadTimelinesGroup> groups;
public ResourcesLoadPanel(List<LoadTimelinesGroup> groups,
TimeTracker timeTracker) {
this.groups = groups;
timeTrackerComponent = timeTrackerForResourcesLoadPanel(timeTracker);
resourceLoadList = new ResourceLoadList(Collections
.<ResourceLoad> emptyList());
leftPane = new ResourceLoadLeftPane();
resourceLoadList = new ResourceLoadList(timeTracker, groups);
leftPane = new ResourceLoadLeftPane(groups);
appendChild(timeTrackerComponent);
appendChild(leftPane);
appendChild(resourceLoadList);

View file

@ -2,12 +2,11 @@
<%@ taglib uri="http://www.zkoss.org/dsp/zk/core" prefix="z" %>
<c:set var="self" value="${requestScope.arg.self}"/>
<div id="${self.uuid}" class="row_resourceload"
z.autoz="true" ${self.outerAttrs}" >
z.autoz="true" ${self.outerAttrs}">
<span class="resourceload_name" id="${self.uuid}!real">${self.resourceLoadName}</span>
<c:forEach var="child" items="${self.children}">
<div id="loadinterval${child.uuid}" style="width: ${child.lenght}%;"
class="taskassignmentinterval ${child.loadLevel}"></div>
${z:redraw(child, null)}
</c:forEach>
</div>

View file

@ -3,10 +3,14 @@ package org.navalplanner.web.planner;
import static org.navalplanner.web.I18nHelper._;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.LocalDate;
import org.zkoss.ganttz.TaskEditFormComposer;
import org.zkoss.ganttz.adapters.AutoAdapter;
import org.zkoss.ganttz.adapters.DomainDependency;
@ -18,6 +22,10 @@ import org.zkoss.ganttz.data.GanttDiagramGraph;
import org.zkoss.ganttz.data.ITaskFundamentalProperties;
import org.zkoss.ganttz.data.Task;
import org.zkoss.ganttz.data.TaskLeaf;
import org.zkoss.ganttz.data.resourceload.LoadLevel;
import org.zkoss.ganttz.data.resourceload.LoadPeriod;
import org.zkoss.ganttz.data.resourceload.LoadTimeLine;
import org.zkoss.ganttz.data.resourceload.LoadTimelinesGroup;
import org.zkoss.ganttz.extensions.ICommand;
import org.zkoss.ganttz.extensions.ICommandOnTask;
import org.zkoss.ganttz.extensions.IContext;
@ -65,8 +73,9 @@ public class DataForPlanner {
@Override
public void show() {
loadPanel = new ResourcesLoadPanel(context
.getTimeTracker());
loadPanel = new ResourcesLoadPanel(
createFakeDataForResourcesLoad(), context
.getTimeTracker());
parent.appendChild(loadPanel);
loadPanel.afterCompose();
}
@ -92,6 +101,45 @@ public class DataForPlanner {
});
}
private List<LoadTimelinesGroup> createFakeDataForResourcesLoad() {
List<LoadTimelinesGroup> result = new ArrayList<LoadTimelinesGroup>();
LoadTimeLine resource1 = new LoadTimeLine("resource1",
createFakePeriodsStartingAt(new LocalDate(2009, 2, 3), Duration
.standardDays(20), Duration.standardDays(90), 3));
LoadTimeLine task1 = new LoadTimeLine("task1",
createFakePeriodsStartingAt(new LocalDate(2009, 5, 4), Duration
.standardDays(20), Duration.standardDays(70), 3));
LoadTimeLine task2 = new LoadTimeLine("task2",
createFakePeriodsStartingAt(new LocalDate(2009, 4, 1), Duration
.standardDays(20), Duration.standardDays(90), 3));
LoadTimeLine task3 = new LoadTimeLine("task3",
createFakePeriodsStartingAt(new LocalDate(2009, 6, 1), Duration
.standardDays(20), Duration.standardDays(40), 4));
LoadTimeLine resource2 = new LoadTimeLine(
"resource1",
createFakePeriodsStartingAt(new LocalDate(2009, 10, 1),
Duration.standardDays(20), Duration.standardDays(90), 2));
result.add(new LoadTimelinesGroup(resource1, Arrays
.asList(task1, task2)));
result.add(new LoadTimelinesGroup(resource2, Arrays.asList(task3)));
return result;
}
private List<LoadPeriod> createFakePeriodsStartingAt(LocalDate start,
Duration separation, Duration periodLength, int numberOfPeriods) {
DateTime current = start.toDateMidnight().toDateTime();
List<LoadPeriod> result = new ArrayList<LoadPeriod>();
for (int i = 0; i < numberOfPeriods; i++) {
DateTime previous = current.plus(separation);
current = previous.plus(periodLength);
result
.add(new LoadPeriod(previous.toLocalDate(), current
.toLocalDate(), new LoadLevel(
(int) (Math.random() * 150))));
}
return result;
}
private void addCommands(
PlannerConfiguration<ITaskFundamentalProperties> configuration) {
configuration
@ -137,7 +185,8 @@ public class DataForPlanner {
}
});
configuration.setEditTaskCommand(new ICommandOnTask<ITaskFundamentalProperties>() {
configuration
.setEditTaskCommand(new ICommandOnTask<ITaskFundamentalProperties>() {
@Override
public void doAction(
@ -177,11 +226,12 @@ public class DataForPlanner {
final ITaskFundamentalProperties child1 = createTask(_("child 1"), now,
end);
containerChildren.add(child1);
final DefaultFundamentalProperties child2 = createTask(_("another"), now,
end);
final DefaultFundamentalProperties child2 = createTask(_("another"),
now, end);
containerChildren.add(child2);
list.add(container);
final ITaskFundamentalProperties first = createTask(_("task1"), now, end);
final ITaskFundamentalProperties first = createTask(_("task1"), now,
end);
final ITaskFundamentalProperties second = createTask(_("task2"), now,
end);
list.add(first);

View file

@ -343,24 +343,25 @@ tr.z-vbox-sep {
.taskassignmentinterval {
float:left;
height:10px;
position:relative;
position:absolute;
}
.FULL_PLANIFICATED {
.FULL_LOAD {
background-color:green;
}
.PLANIFICATED {
.SOME_LOAD {
background-color:orange;
}
.OVER_PLANIFICATED {
.OVERLOAD {
background-color:red;
}
.NOT_PLANIFICATED {
.NO_LOAD {
background-color:#007bbe;
}
.row_resourceload {
height: 10px;
border: solid 1px #000000;