use of org.apache.myfaces.tobago.internal.renderkit.CommandMap in project myfaces-tobago by apache.
the class SheetRenderer method encodeHeaderRows.
private void encodeHeaderRows(final FacesContext facesContext, final AbstractUISheet sheet, final TobagoResponseWriter writer, final List<AbstractUIColumnBase> columns) throws IOException {
final Selectable selectable = sheet.getSelectable();
final Grid grid = sheet.getHeaderGrid();
final boolean autoLayout = sheet.isAutoLayout();
final boolean multiHeader = grid.getRowCount() > 1;
int offset = 0;
for (int i = 0; i < grid.getRowCount(); i++) {
writer.startElement(HtmlElements.TR);
final AbstractUIRow row = ComponentUtils.findChild(sheet, AbstractUIRow.class);
if (row != null) {
writer.writeClassAttribute(row.getCustomClass());
}
for (int j = 0; j < columns.size(); j++) {
final AbstractUIColumnBase column = columns.get(j);
if (!column.isRendered() || column instanceof AbstractUIRow) {
offset++;
} else {
final Cell cell = grid.getCell(j - offset, i);
if (cell instanceof OriginCell) {
writer.startElement(HtmlElements.TH);
if (cell.getColumnSpan() > 1) {
writer.writeAttribute(HtmlAttributes.COLSPAN, cell.getColumnSpan());
}
if (cell.getRowSpan() > 1) {
writer.writeAttribute(HtmlAttributes.ROWSPAN, cell.getRowSpan());
}
final TextAlign align;
final UIComponent cellComponent = cell.getComponent();
if (multiHeader && cell.getColumnSpan() > 1) {
align = TextAlign.center;
} else if (column instanceof AbstractUIColumn) {
align = ((AbstractUIColumn) column).getAlign();
} else {
align = null;
}
writer.writeClassAttribute(BootstrapClass.textAlign(align), column.getCustomClass());
writer.startElement(HtmlElements.SPAN);
boolean sortable = false;
boolean ascending = false;
boolean descending = false;
String tip = ComponentUtils.getStringAttribute(column, Attributes.tip);
// sorter icons should only displayed when there is only 1 column and not input
CommandMap behaviorCommands = null;
if (cell.getColumnSpan() == 1 && cellComponent instanceof AbstractUIOut) {
sortable = ComponentUtils.getBooleanAttribute(column, Attributes.sortable);
if (sortable) {
AbstractUILink sortCommand = (AbstractUILink) ComponentUtils.getFacet(column, Facets.sorter);
if (sortCommand == null) {
// assign id to column
column.getClientId(facesContext);
final String sorterId = column.getId() + "_" + AbstractUISheet.SORTER_ID;
sortCommand = (AbstractUILink) ComponentUtils.createComponent(facesContext, Tags.link.componentType(), RendererTypes.Link, sorterId);
sortCommand.setTransient(true);
final AjaxBehavior reloadBehavior = createReloadBehavior(sheet);
sortCommand.addClientBehavior("click", reloadBehavior);
ComponentUtils.setFacet(column, Facets.sorter, sortCommand);
}
writer.writeIdAttribute(sortCommand.getClientId(facesContext));
behaviorCommands = getBehaviorCommands(facesContext, sortCommand);
ComponentUtils.removeFacet(column, Facets.sorter);
if (tip == null) {
tip = "";
} else {
tip += " - ";
}
tip += ResourceUtils.getString(facesContext, "sheet.sorting");
final SheetState sheetState = sheet.getSheetState(facesContext);
if (column.getId().equals(sheetState.getSortedColumnId())) {
final String sortTitle;
if (sheetState.isAscending()) {
sortTitle = ResourceUtils.getString(facesContext, "sheet.ascending");
ascending = true;
} else {
sortTitle = ResourceUtils.getString(facesContext, "sheet.descending");
descending = true;
}
tip += " - " + sortTitle;
}
}
}
writer.writeClassAttribute(sortable ? TobagoClass.SORTABLE : null, ascending ? TobagoClass.ASCENDING : null, descending ? TobagoClass.DESCENDING : null);
writer.writeAttribute(HtmlAttributes.TITLE, tip, true);
encodeBehavior(writer, behaviorCommands);
if (column instanceof AbstractUIColumnSelector && selectable.isMulti()) {
writer.startElement(HtmlElements.INPUT);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.CHECKBOX);
writer.writeClassAttribute(TobagoClass.SELECTED);
writer.writeAttribute(HtmlAttributes.TITLE, ResourceUtils.getString(facesContext, "sheet.selectAll"), true);
writer.endElement(HtmlElements.INPUT);
} else {
cellComponent.encodeAll(facesContext);
}
writer.endElement(HtmlElements.SPAN);
if (!autoLayout) {
if (column.isResizable()) {
encodeResizing(writer, sheet, j - offset + cell.getColumnSpan() - 1);
}
}
writer.endElement(HtmlElements.TH);
}
}
}
if (!autoLayout) {
// Add two filler columns. The second one get the size of the scrollBar via JavaScript.
encodeHeaderFiller(writer, sheet);
encodeHeaderFiller(writer, sheet);
}
writer.endElement(HtmlElements.TR);
}
}
use of org.apache.myfaces.tobago.internal.renderkit.CommandMap in project myfaces-tobago by apache.
the class TreeSelectRenderer method encodeBeginInternal.
@Override
public void encodeBeginInternal(final FacesContext facesContext, final T component) throws IOException {
final AbstractUITree tree = ComponentUtils.findAncestor(component, AbstractUITree.class);
final AbstractUITreeNodeBase node = ComponentUtils.findAncestor(component, AbstractUITreeNodeBase.class);
final AbstractUIData data = ComponentUtils.findAncestor(node, AbstractUIData.class);
final TobagoResponseWriter writer = getResponseWriter(facesContext);
if (data instanceof AbstractUITreeListbox) {
writer.write(StringUtils.defaultString(component.getLabel()));
return;
}
final String id = component.getClientId(facesContext);
final String currentValue = getCurrentValue(facesContext, component);
final boolean checked;
if (component.isValueStoredInState()) {
checked = data.getSelectedState().isSelected(node.getPath());
} else {
checked = "true".equals(currentValue);
}
final boolean folder = data.isFolder();
final Selectable selectable = data.getSelectable();
final boolean showFormCheck = component.isShowCheckbox() && selectable != Selectable.none && (!selectable.isLeafOnly() || !folder);
writer.startElement(HtmlElements.TOBAGO_TREE_SELECT);
writer.writeClassAttribute(component.getCustomClass(), showFormCheck ? BootstrapClass.FORM_CHECK_INLINE : null, showFormCheck && selectable.isMulti() ? BootstrapClass.FORM_CHECK : null, showFormCheck && selectable.isSingle() ? BootstrapClass.FORM_CHECK : null);
HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
if (showFormCheck) {
writer.startElement(HtmlElements.INPUT);
writer.writeClassAttribute(BootstrapClass.FORM_CHECK_INPUT);
if (selectable.isSingle()) {
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.RADIO);
writer.writeNameAttribute(getClientIdWithoutRowIndex(data, id));
} else {
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.CHECKBOX);
writer.writeNameAttribute(id);
}
writer.writeAttribute(HtmlAttributes.VALUE, id, false);
// TODO: ID must be at the outer tag
writer.writeIdAttribute(id);
writer.writeAttribute(HtmlAttributes.CHECKED, checked);
writer.endElement(HtmlElements.INPUT);
}
final String label = component.getLabel();
writer.startElement(HtmlElements.LABEL);
writer.writeClassAttribute(showFormCheck ? BootstrapClass.FORM_CHECK_LABEL : null);
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, component);
if (title != null) {
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
writer.writeAttribute(HtmlAttributes.FOR, id, false);
writer.writeText(label);
writer.endElement(HtmlElements.LABEL);
if (showFormCheck) {
final CommandMap behaviorCommands = getBehaviorCommands(facesContext, component);
if (behaviorCommands != null) {
Map<ClientBehaviors, Command> other = behaviorCommands.getOther();
if (other != null) {
Command change = other.get(ClientBehaviors.change);
change.setExecute(change.getExecute() + " " + tree.getBaseClientId(facesContext));
change.setRender(change.getRender() + " " + tree.getBaseClientId(facesContext));
}
}
encodeBehavior(writer, behaviorCommands);
}
writer.endElement(HtmlElements.TOBAGO_TREE_SELECT);
}
use of org.apache.myfaces.tobago.internal.renderkit.CommandMap in project myfaces-tobago by apache.
the class RendererBase method encodeBehavior.
/**
* Renders the tobago-behavior tag.
*
* @since 5.0
*/
protected void encodeBehavior(final TobagoResponseWriter writer, final FacesContext facesContext, final ClientBehaviorHolder holder) throws IOException {
if (holder != null) {
final CommandMap behaviorCommands = getBehaviorCommands(facesContext, holder);
encodeBehavior(writer, behaviorCommands);
}
}
use of org.apache.myfaces.tobago.internal.renderkit.CommandMap in project myfaces-tobago by apache.
the class RendererBase method encodeBehavior.
/**
* Renders the tobago-behavior tag.
*
* @since 5.0
*/
protected void encodeBehavior(final TobagoResponseWriter writer, final CommandMap behaviorCommands) throws IOException {
if (behaviorCommands != null) {
final Command click = behaviorCommands.getClick();
if (click != null) {
encodeBehavior(writer, ClientBehaviors.click, click);
}
final Map<ClientBehaviors, Command> other = behaviorCommands.getOther();
if (other != null) {
for (Map.Entry<ClientBehaviors, Command> entry : other.entrySet()) {
encodeBehavior(writer, entry.getKey(), entry.getValue());
}
}
}
}
use of org.apache.myfaces.tobago.internal.renderkit.CommandMap in project myfaces-tobago by apache.
the class JsonUtilsUnitTest method testCommandMap.
@Test
public void testCommandMap() {
CommandMap map = new CommandMap();
map.addCommand(ClientBehaviors.blur, new Command("doit", null, false, "field", "execute", "render", "Do \"you\" want?", 100, new Collapse(Collapse.Operation.hide, "box"), false));
final String expected = ("{'blur':" + "{'clientId':'doit'," + "'transition':false," + "'target':'field'," + "'execute':'execute'," + "'render':'render'," + "'collapse':{'transition':'hide','forId':'box'}," + "'confirmation':'Do \\'you\\' want?'," + "'delay':100}}").replaceAll("'", "\"");
Assertions.assertEquals(expected, JsonUtils.encode(map), "command map");
}
Aggregations