📄 htmlview.java
字号:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.extremecomponents.table.view;import java.math.BigDecimal;import java.util.Iterator;import java.util.List;import org.apache.commons.lang.StringUtils;import org.extremecomponents.table.bean.Column;import org.extremecomponents.table.bean.Export;import org.extremecomponents.table.bean.Form;import org.extremecomponents.table.bean.Row;import org.extremecomponents.table.bean.Table;import org.extremecomponents.table.core.BaseModel;import org.extremecomponents.table.core.TableConstants;import org.extremecomponents.table.core.TableModel;import org.extremecomponents.table.core.TableModelUtils;import org.extremecomponents.table.core.TableResourceBundle;import org.extremecomponents.table.handler.ExportHandler;import org.extremecomponents.util.ExtremeUtils;import org.extremecomponents.util.HtmlBuilder;/** * The default implementation of the table. The notion is that you can easily * plug in different parts of the view as needed or desired. * * @author Jeff Johnston */public class HtmlView extends HtmlBuilder implements View { public final static String TOOLBAR = "toolbar"; public final static String SEPARATOR = "separator"; public final static String STATUS_BAR = "statusBar"; public final static String FILTER_BUTTONS = "filterButtons"; public final static String FORM_BUTTONS = "formButtons"; public final static String FILTER = "filter"; public final static String TITLE = "title"; public final static String TABLE_TOTAL_TITLE = "tableTotalTitle"; public final static String TABLE_TOTALS = "tableTotal"; public final static String TABLE_TOTALS_EMPTY = "tableTotalEmpty"; public final static String TABLE_BODY = "tableBody"; public final static String LAST_PAGE = "lastPage"; public final static String LAST_PAGE_DISABLED = "lastPageDisabled"; public final static String FIRST_PAGE = "firstPage"; public final static String FIRST_PAGE_DISABLED = "firstPageDisabled"; public final static String PREV_PAGE = "prevPage"; public final static String PREV_PAGE_DISABLED = "prevPageDisabled"; public final static String NEXT_PAGE = "nextPage"; public final static String NEXT_PAGE_DISABLED = "nextPageDisabled"; public final static String SEARCH_ARROW_IMAGE = "searchArrow"; public final static String SEARCH_IMAGE = "search"; public final static String CLEAR_IMAGE = "clear"; public void beforeBody(BaseModel model) { div().styleClass("eXtremeTable").close(); toolbarPlacement(model); tableStart(model); statusBar(model); filter(model); header(model); formStart(model); tbody(1).styleClass(TABLE_BODY).close(); } public void body(BaseModel model, Column column) { if (column.isFirstColumn()) { tr(1); if (model.getRowHandler().isRowEven()) { rowStyleAndJavascript(model, Row.EVEN); } else { rowStyleAndJavascript(model, Row.ODD); } close(); } append(column.getValue()); if (column.isLastColumn()) { trEnd(1); } } public Object afterBody(BaseModel model) { totals(model); tbodyEnd(1); tableEnd(model); newline().divEnd(); return toString(); } private void rowStyleAndJavascript(BaseModel model, String defaultStyleClass) { Row row = model.getRowHandler().getRow(); String styleClass = row.getStyleClass(); String style = row.getStyle(); if (StringUtils.isBlank(styleClass)) { styleClass = defaultStyleClass; } styleClass(styleClass); style(style); onclick(row.getOnclick()); boolean highlightRow = row.highlightRow(); if (highlightRow) { String highlightClass = row.getHighlightClass(); if (StringUtils.isNotBlank(row.getOnmouseover())) { onmouseover("this.className='" + highlightClass + "'; " + row.getOnmouseover()); } else { onmouseover("this.className='" + highlightClass + "'"); } if (StringUtils.isNotBlank(row.getOnmouseout())) { onmouseout("this.className='" + highlightClass + "'; " + row.getOnmouseout()); } else { onmouseout("this.className='" + styleClass + "'"); } } else { onmouseover(row.getOnmouseover()); onmouseout(row.getOnmouseout()); } } public void toolbarPlacement(BaseModel model) { boolean showPagination = model.getTableHandler().getTable().showPagination(); boolean showExports = model.getExportHandler().showExports(); if (!showPagination && !showExports && StringUtils.isBlank(model.getTableHandler().getTable().getTitle())) { return; } table(0).border("0").cellPadding("0").cellSpacing("0"); width(model.getTableHandler().getTable().getWidth()).close(); tr(1).close(); td(2).styleClass(TITLE).close(); title(model); tdEnd(); td(2).align("right").close(); toolbar(model); tdEnd(); trEnd(1); tableEnd(0); newline(); } public void title(BaseModel model) { String title = model.getTableHandler().getTable().getTitle(); if (StringUtils.isNotBlank(title)) { span().close().append(title).spanEnd(); } } /** * The pagination and export will display together. */ public void toolbar(BaseModel model) { boolean showPagination = model.getTableHandler().getTable().showPagination(); boolean showExports = model.getExportHandler().showExports(); if (!showPagination && !showExports) { return; } table(2).border("0").cellPadding("0").cellSpacing("1").styleClass(TOOLBAR).close(); tr(3).close(); toolbarFormStart(model); if (showPagination) { toolbarPaginationIcons(model); String separator = TableModelUtils.getImage(model, "separator"); td(4).rowSpan("2").styleClass(SEPARATOR).close().img(separator).tdEnd(); rowsDisplayedDroplist(model); if (showExports) { td(4).rowSpan("2").styleClass(SEPARATOR).close().img(separator).tdEnd(); } } if (showExports) { toolbarExportIcons(model); } trEnd(3); tr(3).close(); formEnd(); trEnd(3); tableEnd(2); newline(); tabs(2); } /** * Get the HTML for the start of the form <form>tag. The filter will need to * be wrapped in a form tag so that it can be submitted. */ private void toolbarFormStart(BaseModel model) { form(); name(model.getTableHandler().prefixWithTableId() + "toolbar"); String action = model.getTableHandler().getTable().getAction(); if (StringUtils.isNotEmpty(action)) { action(action); } close(); String hiddenFields = model.getRegistry().getFormHiddenFields(true, true, false, false); if (StringUtils.isNotEmpty(hiddenFields)) { append(hiddenFields); } } public void toolbarPaginationIcons(BaseModel model) { int page = model.getLimit().getPage(); int totalPages = TableModelUtils.getTotalPages(model); td(4).close(); if (!TableModelUtils.isFirstPageEnabled(page)) { String firstPageImage = TableModelUtils.getImage(model, FIRST_PAGE_DISABLED); img(firstPageImage); } else { String firstPageImage = TableModelUtils.getImage(model, FIRST_PAGE); String firstPageTooltip = model.getResourceBundle().getResource( TableResourceBundle.TOOLBAR_FIRST_PAGE_TOOLTIP); paginationImage(model, 1, firstPageImage, firstPageTooltip); } tdEnd(); // prev page td(4).close(); if (!TableModelUtils.isPrevPageEnabled(page)) { String prevPageImage = TableModelUtils.getImage(model, PREV_PAGE_DISABLED); img(prevPageImage); } else { String prevPageImage = TableModelUtils.getImage(model, PREV_PAGE); String prevPageTooltip = model.getResourceBundle().getResource( TableResourceBundle.TOOLBAR_PREV_PAGE_TOOLTIP); paginationImage(model, page - 1, prevPageImage, prevPageTooltip); } tdEnd(); // next page td(4).close(); if (!TableModelUtils.isNextPageEnabled(page, totalPages)) { String nextPageImage = TableModelUtils.getImage(model, NEXT_PAGE_DISABLED); img(nextPageImage); } else { String nextPageImage = TableModelUtils.getImage(model, NEXT_PAGE); String nextPageTooltip = model.getResourceBundle().getResource( TableResourceBundle.TOOLBAR_NEXT_PAGE_TOOLTIP); paginationImage(model, page + 1, nextPageImage, nextPageTooltip); } tdEnd(); td(4).close(); if (!TableModelUtils.isLastPageEnabled(page, totalPages)) { String lastPageImage = TableModelUtils.getImage(model, LAST_PAGE_DISABLED); img(lastPageImage); } else { String lastPageImage = TableModelUtils.getImage(model, LAST_PAGE); String lastPageTooltip = model.getResourceBundle().getResource( TableResourceBundle.TOOLBAR_LAST_PAGE_TOOLTIP); paginationImage(model, totalPages, lastPageImage, lastPageTooltip); } tdEnd(); } public void paginationImage(BaseModel model, int page, String image, String tooltip) { a(); quote(); String action = model.getTableHandler().getTable().getAction(); if (StringUtils.isNotEmpty(action)) { append(action); } question().append(model.getTableHandler().prefixWithTableId()).append(TableConstants.PAGE).equals().append( "" + page); append(model.getRegistry().getURLParameterString(true, true, false, true)); quote().close(); img(image, tooltip); aEnd(); } public void toolbarExportIcons(BaseModel model) { for (Iterator iter = model.getExportHandler().getExports().iterator(); iter.hasNext();) { td(4).close(); Export export = (Export) iter.next(); exportImage(model, export); tdEnd(); } } public void rowsDisplayedDroplist(BaseModel model) { int rowsDisplayed = model.getTableHandler().getTable().getRowsDisplayed(); int medianRowsDisplayed = model.getTableHandler().getTable().getMedianRowsDisplayed(); int maxRowsDisplayed = model.getTableHandler().getTable().getMaxRowsDisplayed(); int currentRowsDisplayed = model.getLimit().getCurrentRowsDisplayed(); td(4).width("20").close(); newline(); tabs(4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -