}
@Override
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
final AbstractUITree tree = (AbstractUITree) component;
final String clientId = tree.getClientId(facesContext);
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
final Style style = new Style(facesContext, tree);
final Style scrollDivStyle = new Style();
writer.startElement(HtmlElements.DIV, tree);
scrollDivStyle.setWidth(Measure.valueOf(6 * 160)); // todo: depth * width of a select
scrollDivStyle.setHeight(style.getHeight() // todo: what, when there is no scrollbar?
.subtract(15)); // todo: scrollbar height
scrollDivStyle.setPosition(Position.ABSOLUTE);
writer.writeStyleAttribute(scrollDivStyle);
writer.startElement(HtmlElements.DIV, tree);
writer.writeClassAttribute(Classes.create(tree));
writer.writeStyleAttribute(style);
writer.startElement(HtmlElements.INPUT, tree);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
writer.writeNameAttribute(clientId);
writer.writeIdAttribute(clientId);
writer.writeAttribute(HtmlAttributes.VALUE, ";", false);
writer.endElement(HtmlElements.INPUT);
writer.startElement(HtmlElements.INPUT, tree);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
writer.writeNameAttribute(clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_MARKED);
writer.writeIdAttribute(clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_MARKED);
writer.writeAttribute(HtmlAttributes.VALUE, "", false);
writer.endElement(HtmlElements.INPUT);
if (tree.getSelectableAsEnum().isSupportedByTreeListbox()) {
writer.startElement(HtmlElements.INPUT, tree);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
writer.writeNameAttribute(clientId + AbstractUITree.SELECT_STATE);
writer.writeIdAttribute(clientId + AbstractUITree.SELECT_STATE);
writer.writeAttribute(HtmlAttributes.VALUE, ";", false);
writer.endElement(HtmlElements.INPUT);
}
List<Integer> thisLevel = new ArrayList<Integer>();
thisLevel.add(0);
List<Integer> nextLevel = new ArrayList<Integer>();
for (int level = 0; level < 7; level++) { // XXX not a fix value!!!
writer.startElement(HtmlElements.DIV, null);
writer.writeClassAttribute(Classes.create(tree, "level"));
Style levelStyle = new Style();
levelStyle.setLeft(Measure.valueOf(level * 160)); // xxx 160 should be configurable
writer.writeStyleAttribute(levelStyle);
// at the start of each div there is an empty and disabled select tag to show empty area.
// this is not needed for the 1st level.
if (level > 0) {
writer.startElement(HtmlElements.SELECT, null);
writer.writeAttribute(HtmlAttributes.DISABLED, true);
writer.writeAttribute(HtmlAttributes.SIZE, 9); // must be > 1, but the real size comes from the layout
writer.writeClassAttribute(Classes.create(tree, "select"));
writer.endElement(HtmlElements.SELECT);
}
for(Integer rowIndex : thisLevel) {
encodeSelectBox(facesContext, tree, writer, rowIndex, nextLevel);
}
thisLevel.clear();
List<Integer> swap = thisLevel;
thisLevel = nextLevel;
nextLevel = swap;
writer.endElement(HtmlElements.DIV);
}
writer.endElement(HtmlElements.DIV);
writer.endElement(HtmlElements.DIV);
tree.setRowIndex(-1);
}