use of com.liferay.faces.alloy.component.column.Column in project liferay-faces-alloy by liferay.
the class ColumnRenderer method processEvent.
@Override
public void processEvent(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
Column column = (Column) componentSystemEvent.getComponent();
UIComponent parent = column.getParent();
if ((parent instanceof DataTable) && column.isAjax()) {
RendererUtil.addDefaultAjaxBehavior(column, column.getExecute(), column.getProcess(), "@parent", column.getRender(), column.getUpdate(), "@parent");
}
}
use of com.liferay.faces.alloy.component.column.Column in project liferay-faces-alloy by liferay.
the class ColumnRenderer method encodeBegin.
@Override
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
UIComponent parent = uiComponent.getParent();
if (!((parent instanceof HtmlDataTable) || (parent instanceof HtmlPanelGrid))) {
responseWriter.startElement("div", uiComponent);
String clientId = uiComponent.getClientId(facesContext);
responseWriter.writeAttribute("id", clientId, null);
Column column = (Column) uiComponent;
StringBuilder classNames = new StringBuilder();
String size = column.getSize();
size = getColumnCSSClassSize(size);
Integer span = column.getSpan();
if (span != null) {
if ((span < 1) || (span > Column.COLUMNS)) {
throw new IOException("span number must be between 1 and " + Column.COLUMNS);
}
}
Integer width = column.getWidth();
if (width != null) {
if ((width < 1) || (width > 100)) {
throw new IOException("width must be between 1 and 100");
}
span = getColumnUnitSize(width);
}
classNames.append("col-");
classNames.append(size);
classNames.append("-");
classNames.append(span);
Integer offset = column.getOffset();
if (offset != null) {
if ((offset < 1) || (offset > Column.COLUMNS)) {
throw new IOException("offset must be between 1 and " + Column.COLUMNS);
}
}
Integer offsetWidth = column.getOffsetWidth();
if (offsetWidth != null) {
if ((offsetWidth < 1) || (offsetWidth > 100)) {
throw new IOException("offsetWidth must be between 1 and 100");
}
offset = getColumnUnitSize(offsetWidth);
}
if (offset != null) {
classNames.append(" ");
classNames.append("col-");
classNames.append(size);
classNames.append("-offset-");
classNames.append(offset);
}
RendererUtil.encodeStyleable(responseWriter, column, classNames.toString());
}
}
use of com.liferay.faces.alloy.component.column.Column in project liferay-faces-alloy by liferay.
the class DataTableRenderer method encodeHeader.
protected void encodeHeader(FacesContext facesContext, ResponseWriter responseWriter, DataTable dataTable, DataTableInfo dataTableInfo) throws IOException {
UIComponent headerFacet = dataTable.getFacet("header");
if ((headerFacet != null) || dataTableInfo.isHeaderFacetOrTextPresentInColumn()) {
responseWriter.startElement("thead", null);
responseWriter.writeAttribute("class", "table-columns", null);
}
int totalRenderedColumns = dataTableInfo.getTotalRenderedColumns();
int colspan = totalRenderedColumns;
String selectionMode = dataTable.getSelectionMode();
if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
colspan++;
}
String headerClass = dataTable.getHeaderClass();
if (headerFacet != null) {
responseWriter.startElement("tr", null);
responseWriter.startElement("th", null);
if (headerClass == null) {
responseWriter.writeAttribute("class", "facet", "headerClass");
} else {
responseWriter.writeAttribute("class", headerClass.concat(" facet"), "headerClass");
}
if (totalRenderedColumns > 1) {
responseWriter.writeAttribute("colspan", colspan, null);
}
responseWriter.writeAttribute("scope", "colgroup", null);
encodeRecurse(facesContext, headerFacet);
responseWriter.endElement("th");
responseWriter.endElement("tr");
}
if (dataTableInfo.isHeaderFacetOrTextPresentInColumn()) {
responseWriter.startElement("tr", null);
List<UIComponent> children = dataTable.getChildren();
if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
responseWriter.startElement("th", null);
if ("checkbox".equals(selectionMode)) {
responseWriter.startElement("input", null);
String checkboxClientId = dataTable.getClientId(facesContext).concat("_selectAll");
responseWriter.writeAttribute("id", checkboxClientId, null);
responseWriter.writeAttribute("type", "checkbox", null);
responseWriter.endElement("input");
}
responseWriter.endElement("th");
}
for (UIComponent child : children) {
if (child instanceof UIColumn) {
UIColumn uiColumn = (UIColumn) child;
if (uiColumn.isRendered()) {
responseWriter.startElement("th", null);
if (child instanceof HtmlColumn) {
HtmlColumn htmlColumn = (HtmlColumn) child;
String columnHeaderClass = htmlColumn.getHeaderClass();
String sortClass = null;
Column alloyColumn = null;
if (child instanceof Column) {
alloyColumn = (Column) htmlColumn;
String sortOrder = alloyColumn.getSortOrder();
if ("ASCENDING".equals(sortOrder)) {
sortClass = " table-sortable-column table-sorted";
} else if ("DESCENDING".equals(sortOrder)) {
sortClass = " table-sortable-column table-sorted table-sorted-desc";
}
}
if (columnHeaderClass != null) {
if (sortClass != null) {
columnHeaderClass = columnHeaderClass.concat(sortClass);
}
responseWriter.writeAttribute("class", columnHeaderClass, "columnHeaderClass");
} else if (headerClass != null) {
if (sortClass != null) {
headerClass = headerClass.concat(sortClass);
}
responseWriter.writeAttribute("class", headerClass, "headerClass");
} else if (sortClass != null) {
responseWriter.writeAttribute("class", sortClass, null);
}
responseWriter.writeAttribute("scope", "col", null);
if (alloyColumn != null) {
String headerText = alloyColumn.getHeaderText();
if (headerText != null) {
encodeHeaderText(facesContext, responseWriter, dataTable, alloyColumn, headerText);
}
}
UIComponent columnHeaderFacet = htmlColumn.getFacet("header");
if (columnHeaderFacet != null) {
encodeRecurse(facesContext, columnHeaderFacet);
}
}
responseWriter.endElement("th");
}
}
}
responseWriter.endElement("tr");
}
if ((headerFacet != null) || dataTableInfo.isHeaderFacetOrTextPresentInColumn()) {
responseWriter.endElement("thead");
}
}
use of com.liferay.faces.alloy.component.column.Column in project liferay-faces-alloy by liferay.
the class DataTableRenderer method decodeSortCriteria.
protected void decodeSortCriteria(FacesContext facesContext, Map<String, String> requestParameterMap, DataTable dataTable, String dataTableClientId) {
Object dataTableValue = dataTable.getValue();
if ((dataTableValue != null) && (dataTableValue instanceof Sortable)) {
String sortColumnClientIdParamName = dataTableClientId.concat("_sortColumnClientId");
String sortColumnClientId = requestParameterMap.get(sortColumnClientIdParamName);
if (sortColumnClientId != null) {
List<Column> alloySortColumns = new ArrayList<Column>();
String eventMetaKeyParamName = dataTableClientId.concat("_eventMetaKey");
boolean eventMetaKey = BooleanHelper.toBoolean(requestParameterMap.get(eventMetaKeyParamName));
boolean multiColumnSort = dataTable.isMultiColumnSort();
List<UIComponent> children = dataTable.getChildren();
for (UIComponent child : children) {
if (child instanceof Column) {
Column alloyColumn = (Column) child;
String alloyColumndId = alloyColumn.getClientId(facesContext);
String alloyColumnSortOrder = alloyColumn.getSortOrder();
Map<String, Object> alloyColumnAttributes = alloyColumn.getAttributes();
if (alloyColumndId.equals(sortColumnClientId)) {
// Toggle the value from ascending->descending or from descending->ascending.
SortCriterion.Order sortCriterionOrder;
if ("ASCENDING".equals(alloyColumnSortOrder)) {
sortCriterionOrder = SortCriterion.Order.DESCENDING;
} else {
sortCriterionOrder = SortCriterion.Order.ASCENDING;
}
// Set the state of the column so that the sort indicator will appear correctly.
alloyColumn.setSortOrder(sortCriterionOrder.toString());
alloyColumnAttributes.put("sortTime", System.currentTimeMillis());
// Add the sort criterion to the list of sort criteria.
alloySortColumns.add(alloyColumn);
} else {
if (multiColumnSort && eventMetaKey) {
if (alloyColumnSortOrder != null) {
alloySortColumns.add(alloyColumn);
}
} else {
alloyColumn.setSortOrder(null);
alloyColumnAttributes.remove("sortTime");
}
}
}
}
Collections.sort(alloySortColumns, new ColumnSortTimeComparator());
List<SortCriterion> sortCriteria = new ArrayList<SortCriterion>();
for (Column alloyColumn : alloySortColumns) {
String alloyColumnFieldName = getAlloyColumnFieldName(alloyColumn);
String alloyColumnSortOrder = alloyColumn.getSortOrder();
SortCriterion.Order sortCriterionOrder;
if ("ASCENDING".equals(alloyColumnSortOrder)) {
sortCriterionOrder = SortCriterion.Order.ASCENDING;
} else {
sortCriterionOrder = SortCriterion.Order.DESCENDING;
}
SortCriterion sortCriterion = new SortCriterion(alloyColumnFieldName, sortCriterionOrder);
sortCriteria.add(sortCriterion);
}
if (logger.isDebugEnabled()) {
for (SortCriterion sortCriterion : sortCriteria) {
logger.debug("sortCriterion columnId=[{0}], order=[{1}]", sortCriterion.getColumnId(), sortCriterion.getOrder());
}
}
Sortable sortable = (Sortable) dataTableValue;
sortable.setSortCriteria(sortCriteria);
}
}
}
Aggregations