ItEr24S09CUVistaRecursosTempoPorProxectoItEr23S11: The components are shown and hidden when the tree nodes are expanded and collapsed
Alignment is pending
This commit is contained in:
parent
74d2d96827
commit
33bc83c794
3 changed files with 70 additions and 12 deletions
|
|
@ -39,6 +39,7 @@ public class ResourceLoadLeftPane extends HtmlMacroComponent {
|
|||
@Override
|
||||
public void render(Treeitem item, Object data) throws Exception {
|
||||
LoadTimeLine line = (LoadTimeLine) data;
|
||||
item.setOpen(true);
|
||||
Treerow row = new Treerow();
|
||||
Treecell cell = new Treecell();
|
||||
Component component = createComponent(line);
|
||||
|
|
@ -76,12 +77,11 @@ public class ResourceLoadLeftPane extends HtmlMacroComponent {
|
|||
}
|
||||
|
||||
private void collapse(LoadTimeLine line) {
|
||||
// TODO do collapse
|
||||
resourceLoadList.collapse(line);
|
||||
}
|
||||
|
||||
private void expand(LoadTimeLine line) {
|
||||
// TODO do expand
|
||||
|
||||
resourceLoadList.expand(line);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
package org.zkoss.ganttz.resourceload;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.zkoss.ganttz.data.resourceload.LoadTimeLine;
|
||||
import org.zkoss.ganttz.data.resourceload.LoadTimelinesGroup;
|
||||
import org.zkoss.ganttz.timetracker.TimeTracker;
|
||||
import org.zkoss.ganttz.timetracker.zoom.IZoomLevelChangedListener;
|
||||
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
|
||||
import org.zkoss.ganttz.util.MutableTreeModel;
|
||||
import org.zkoss.zk.au.out.AuInvoke;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zul.impl.XulElement;
|
||||
|
||||
/**
|
||||
|
|
@ -19,18 +23,40 @@ public class ResourceLoadList extends XulElement {
|
|||
|
||||
private final IZoomLevelChangedListener zoomListener;
|
||||
|
||||
private Map<LoadTimeLine, ResourceLoadComponent> fromTimeLineToComponent = new HashMap<LoadTimeLine, ResourceLoadComponent>();
|
||||
|
||||
private final MutableTreeModel<LoadTimeLine> timelinesTree;
|
||||
|
||||
public ResourceLoadList(TimeTracker timeTracker,
|
||||
List<LoadTimelinesGroup> groups) {
|
||||
MutableTreeModel<LoadTimeLine> timelinesTree) {
|
||||
this.timelinesTree = timelinesTree;
|
||||
zoomListener = adjustTimeTrackerSizeListener();
|
||||
timeTracker.addZoomListener(zoomListener);
|
||||
for (LoadTimelinesGroup l : groups) {
|
||||
ArrayList<LoadTimeLine> toInsert = new ArrayList<LoadTimeLine>();
|
||||
toInsert.add(l.getPrincipal());
|
||||
toInsert.addAll(l.getChildren());
|
||||
insertAsComponents(timeTracker, toInsert);
|
||||
LoadTimeLine current = timelinesTree.getRoot();
|
||||
List<LoadTimeLine> toInsert = new ArrayList<LoadTimeLine>();
|
||||
fill(timelinesTree, current, toInsert);
|
||||
insertAsComponents(timeTracker, toInsert);
|
||||
}
|
||||
|
||||
private void fill(MutableTreeModel<LoadTimeLine> timelinesTree,
|
||||
LoadTimeLine current, List<LoadTimeLine> result) {
|
||||
final int length = timelinesTree.getChildCount(current);
|
||||
for (int i = 0; i < length; i++) {
|
||||
LoadTimeLine child = timelinesTree.getChild(current, i);
|
||||
result.add(child);
|
||||
fill(timelinesTree, child, result);
|
||||
}
|
||||
}
|
||||
|
||||
private List<LoadTimeLine> getChildrenOf(LoadTimeLine parent) {
|
||||
List<LoadTimeLine> result = new ArrayList<LoadTimeLine>();
|
||||
final int length = timelinesTree.getChildCount(parent);
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.add(timelinesTree.getChild(parent, i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private IZoomLevelChangedListener adjustTimeTrackerSizeListener() {
|
||||
return new IZoomLevelChangedListener() {
|
||||
|
||||
|
|
@ -47,7 +73,39 @@ public class ResourceLoadList extends XulElement {
|
|||
private void insertAsComponents(TimeTracker timetracker,
|
||||
List<LoadTimeLine> children) {
|
||||
for (LoadTimeLine loadTimeLine : children) {
|
||||
appendChild(ResourceLoadComponent.create(timetracker, loadTimeLine));
|
||||
ResourceLoadComponent component = ResourceLoadComponent.create(
|
||||
timetracker, loadTimeLine);
|
||||
appendChild(component);
|
||||
fromTimeLineToComponent.put(loadTimeLine, component);
|
||||
}
|
||||
}
|
||||
|
||||
public void collapse(LoadTimeLine line) {
|
||||
for (LoadTimeLine l : getChildrenOf(line)) {
|
||||
getComponentFor(l).detach();
|
||||
}
|
||||
}
|
||||
|
||||
private ResourceLoadComponent getComponentFor(LoadTimeLine l) {
|
||||
ResourceLoadComponent resourceLoadComponent = fromTimeLineToComponent
|
||||
.get(l);
|
||||
return resourceLoadComponent;
|
||||
}
|
||||
|
||||
public void expand(LoadTimeLine line) {
|
||||
ResourceLoadComponent parentComponent = getComponentFor(line);
|
||||
Component nextSibling = parentComponent.getNextSibling();
|
||||
for (LoadTimeLine loadTimeLine : getChildrenReverseOrderFor(line)) {
|
||||
ResourceLoadComponent child = getComponentFor(loadTimeLine);
|
||||
insertBefore(child, nextSibling);
|
||||
nextSibling = child;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<LoadTimeLine> getChildrenReverseOrderFor(LoadTimeLine line) {
|
||||
List<LoadTimeLine> childrenOf = getChildrenOf(line);
|
||||
Collections.reverse(childrenOf);
|
||||
return childrenOf;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class ResourcesLoadPanel extends XulElement implements AfterCompose {
|
|||
this.groups = groups;
|
||||
treeModel = createModelForTree();
|
||||
timeTrackerComponent = timeTrackerForResourcesLoadPanel(timeTracker);
|
||||
resourceLoadList = new ResourceLoadList(timeTracker, groups);
|
||||
resourceLoadList = new ResourceLoadList(timeTracker, treeModel);
|
||||
leftPane = new ResourceLoadLeftPane(treeModel, resourceLoadList);
|
||||
appendChild(timeTrackerComponent);
|
||||
appendChild(leftPane);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue