writer.startElement(HtmlElements.TBODY, sheet);
for (int i = 0; i < grid.getRowCount(); i++) {
writer.startElement(HtmlElements.TR, null);
for (int j = 0; j < grid.getColumnCount(); j++) {
final Cell cell = grid.getCell(j, i);
if (cell instanceof OriginCell) {
writer.startElement(HtmlElements.TD, null);
if (cell.getColumnSpan() > 1) {
writer.writeAttribute(HtmlAttributes.COLSPAN, cell.getColumnSpan());
}
if (cell.getRowSpan() > 1) {
writer.writeAttribute(HtmlAttributes.ROWSPAN, cell.getRowSpan());
}
final UIComponent cellComponent = (UIComponent) cell.getComponent();
final boolean pure = !(cellComponent instanceof UIOut);
writer.startElement(HtmlElements.DIV, null);
writer.writeClassAttribute(Classes.create(sheet, "headerCell"));
writer.startElement(HtmlElements.SPAN, null);
final Style headerStyle = new Style();
Measure headerHeight = Measure.valueOf(20).multiply(cell.getRowSpan());
if (!pure) {
headerHeight = headerHeight.subtract(6); // XXX todo
}
headerStyle.setHeight(headerHeight);
writer.writeStyleAttribute(headerStyle);
final AbstractUIColumn column = renderedColumnList.get(j);
String sorterImage = null;
Markup markup = Markup.NULL;
String tip = (String) column.getAttributes().get(Attributes.TIP);
if (cell.getColumnSpan() == 1) {
final boolean sortable = ComponentUtils.getBooleanAttribute(column, Attributes.SORTABLE);
if (sortable) {
UICommand sortCommand = (UICommand) column.getFacet(Facets.SORTER);
if (sortCommand == null) {
final String columnId = column.getClientId(facesContext);
final String sorterId = columnId.substring(columnId.lastIndexOf(":") + 1) + "_" + UISheet.SORTER_ID;
sortCommand = (UICommand) CreateComponentUtils.createComponent(
facesContext, UICommand.COMPONENT_TYPE, RendererTypes.LINK, sorterId);
column.getFacets().put(Facets.SORTER, sortCommand);
}
final CommandMap map = new CommandMap();
final Command click = new Command(sortCommand.getClientId(facesContext),
null, null, null, new String[]{sheet.getClientId(facesContext)}, null, null, null, null, null);
map.setClick(click);
writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
if (tip == null) {
tip = "";
} else {
tip += " - ";
}
tip += ResourceManagerUtils.getPropertyNotNull(facesContext, "tobago", "sheetTipSorting");
markup = markup.add(Markup.SORTABLE);
final SheetState sheetState = sheet.getSheetState(facesContext);
if (column.getId().equals(sheetState.getSortedColumnId())) {
final String sortTitle;
if (sheetState.isAscending()) {
sorterImage = contextPath + resourceManager.getImage(facesContext, "image/ascending.gif");
sortTitle = ResourceManagerUtils.getPropertyNotNull(facesContext, "tobago", "sheetAscending");
markup = markup.add(Markup.ASCENDING);
} else {
sorterImage = contextPath + resourceManager.getImage(facesContext, "image/descending.gif");
sortTitle = ResourceManagerUtils.getPropertyNotNull(facesContext, "tobago", "sheetDescending");
markup = markup.add(Markup.DESCENDING);
}
if (sortTitle != null) {
tip += " - " + sortTitle;
}
}
}
}
if (j == 0) {
markup = markup.add(Markup.FIRST);
}
if (pure) {
markup = markup.add(Markup.PURE);
}
writer.writeClassAttribute(Classes.create(sheet, "header", markup));
writer.writeAttribute(HtmlAttributes.TITLE, tip, true);
if (column instanceof UIColumnSelector) {
renderColumnSelectorHeader(facesContext, writer, sheet);
} else {
RenderUtils.encode(facesContext, cellComponent);
final AbstractUIMenu dropDownMenu = FacetUtils.getDropDownMenu(column);
// render sub menu popup button
if (dropDownMenu != null && dropDownMenu.isRendered()) {
writer.startElement(HtmlElements.SPAN, column);
writer.writeClassAttribute(Classes.create(column, "menu"));
writer.startElement(HtmlElements.IMG, column);
final String menuImage
= ResourceManagerUtils.getImageWithPath(facesContext, "image/sheetSelectorMenu.gif");
writer.writeAttribute(HtmlAttributes.TITLE, "", false);
writer.writeAttribute(HtmlAttributes.SRC, menuImage, false);
writer.endElement(HtmlElements.IMG);
ToolBarRendererBase.renderDropDownMenu(facesContext, writer, dropDownMenu);
writer.endElement(HtmlElements.SPAN);
}
}
if (sorterImage != null) {
writer.startElement(HtmlElements.IMG, null);
writer.writeAttribute(HtmlAttributes.SRC, sorterImage, false);
writer.writeAttribute(HtmlAttributes.ALT, "", false);
writer.endElement(HtmlElements.IMG);
}
writer.endElement(HtmlElements.SPAN);
if (renderedColumnList.get(j).isResizable()) {
encodeResizing(writer, sheet, j + cell.getColumnSpan() - 1);
}
writer.endElement(HtmlElements.DIV);
writer.endElement(HtmlElements.TD);
}