📄 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.base.BaseModel;import org.extremecomponents.table.bean.Column;import org.extremecomponents.table.bean.Export;import org.extremecomponents.table.bean.Form;import org.extremecomponents.table.bean.Table;import org.extremecomponents.table.core.ParameterRegistry;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.table.handler.FilterHandler;import org.extremecomponents.table.handler.PaginationHandler;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 void beforeBody(BaseModel model) { div().styleClass("eXtremeTable").close(); toolbarPlacement(model); tableStart(model); statusBar(model); filter(model); header(model); tbody(1).styleClass(TABLE_BODY).close(); formStart(model); } public void body(BaseModel model, Column column, boolean startRow, boolean endRow) { if (startRow) { tr(1).close(); } append(column.getValue()); if (endRow) { trEnd(1); } } public Object afterBody(BaseModel model) { totals(model); tbodyEnd(1); tableEnd(model); newline().divEnd(); return toString(); } public void toolbarPlacement(BaseModel model) { boolean showPagination = model.getTableHandler().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().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 = model.getTableHandler().getTable().getImage("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().prefixWithCollection() + "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) { PaginationHandler paginationHandler = model.getPaginationHandler(); int page = paginationHandler.getPage(); int totalPages = paginationHandler.getTotalPages(); td(4).close(); if (!paginationHandler.isFirstPageEnabled(page)) { String firstPageImage = model.getTableHandler().getTable().getImage(PaginationHandler.FIRST_PAGE_DISABLED); img(firstPageImage, PaginationHandler.FIRST); } else { String firstPageImage = model.getTableHandler().getTable().getImage(PaginationHandler.FIRST_PAGE); paginationImage(model, 1, firstPageImage, PaginationHandler.FIRST); } tdEnd(); //prev page td(4).close(); if (!paginationHandler.isPrevPageEnabled(page)) { String prevPageImage = model.getTableHandler().getTable().getImage(PaginationHandler.PREV_PAGE_DISABLED); img(prevPageImage, PaginationHandler.PREV); } else { String prevPageImage = model.getTableHandler().getTable().getImage(PaginationHandler.PREV_PAGE); paginationImage(model, page - 1, prevPageImage, PaginationHandler.PREV); } tdEnd(); //next page td(4).close(); if (!paginationHandler.isNextPageEnabled(page, totalPages)) { String nextPageImage = model.getTableHandler().getTable().getImage(PaginationHandler.NEXT_PAGE_DISABLED); img(nextPageImage, PaginationHandler.NEXT); } else { String nextPageImage = model.getTableHandler().getTable().getImage(PaginationHandler.NEXT_PAGE); paginationImage(model, page + 1, nextPageImage, PaginationHandler.NEXT); } tdEnd(); td(4).close(); if (!paginationHandler.isLastPageEnabled(page, totalPages)) { String lastPageImage = model.getTableHandler().getTable().getImage(PaginationHandler.LAST_PAGE_DISABLED); img(lastPageImage, PaginationHandler.LAST); } else { String lastPageImage = model.getTableHandler().getTable().getImage(PaginationHandler.LAST_PAGE); paginationImage(model, totalPages, lastPageImage, PaginationHandler.LAST); } 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().prefixWithCollection()).append(ParameterRegistry.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 initialRowsDisplayed = Integer.parseInt(model.getTableHandler().getTable().getInitialRowsDisplayed()); int rowsDisplayed = Integer.parseInt(model.getTableHandler().getTable().getRowsDisplayed()); int totalRows = model.getTableHandler().getTotalRows(); td(4).width("20").close(); newline(); tabs(4); select().name(model.getTableHandler().prefixWithCollection() + ParameterRegistry.ROWS_DISPLAYED); StringBuffer onchange = new StringBuffer(); onchange.append(TableModelUtils.doPaginationJavaScript(model)); onchange(onchange.toString()); close(); newline(); tabs(4); if (initialRowsDisplayed != 0) { option().value(String.valueOf(initialRowsDisplayed)); if (rowsDisplayed == initialRowsDisplayed) { append(" selected"); } close(); append(String.valueOf(initialRowsDisplayed)); optionEnd(); } if (totalRows >= 50 || rowsDisplayed == 50) { option().value(String.valueOf(50)); if (rowsDisplayed == 50) { append(" selected"); } close(); append(String.valueOf(50)); optionEnd(); } if (totalRows >= 100 || rowsDisplayed == 100) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -