📄 columnhandler.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.handler;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import org.apache.commons.lang.StringUtils;import org.extremecomponents.table.bean.Column;import org.extremecomponents.table.cell.Cell;import org.extremecomponents.table.core.BaseModel;import org.extremecomponents.table.core.TableModelUtils;/** * The first pass over the table just loads up the column properties. The * properties will be loaded up and held here. * * @author Jeff Johnston */public class ColumnHandler { private BaseModel model; private List columns = new ArrayList(); // keeps columns in order private Map lookup = new HashMap(); // fast lookup capability private Column firstColumn; private Column lastColumn; public ColumnHandler(BaseModel model) { this.model = model; } public void addAutoGenerateColumn(Column column) { column.addAttribute(Column.IS_AUTO_GENERATE_COLUMN, "true"); addColumn(column); } public void addColumn(Column column) { if (!isViewAllowed(column)) { return; } if (firstColumn == null) { firstColumn = column; } lastColumn = column; columns.add(column); lookup.put(column.getProperty(), column); } public Column getColumn(String property) { return (Column) lookup.get(property); } public int columnCount() { return columns.size(); } public List getColumns() { return columns; } public boolean hasMetatData() { return columnCount() > 0; } public boolean isFirstColumn(String property) { return firstColumn.getProperty().equals(property); } public boolean isLastColumn(String property) { return lastColumn.getProperty().equals(property); } public List getFilterColumns() { boolean cleared = model.getLimit().isCleared(); for (Iterator iter = columns.iterator(); iter.hasNext();) { Column column = (Column) iter.next(); String value = model.getLimit().getFilterSet().getValue(column.getProperty()); if (cleared || StringUtils.isEmpty(value)) { value = ""; } Cell cell = TableModelUtils.buildFilterCell(model, column, value); column.setValue(cell.html()); cell.destroy(); } return columns; } public List getHeaderColumns() { for (Iterator iter = columns.iterator(); iter.hasNext();) { Column column = (Column) iter.next(); Cell cell = TableModelUtils.buildHeaderCell(model, column, column.getTitle()); boolean invokeExport = model.getExportHandler().invokeExport(); if (!invokeExport) { column.setValue(cell.html()); } else { column.setValue(column.getTitle()); } cell.destroy(); } return columns; } private boolean isViewAllowed(Column column) { String view = model.getTableHandler().getTable().getView(); boolean invokeExport = model.getExportHandler().invokeExport(); if (invokeExport) { view = model.getExportHandler().getCurrentExport().getView(); } boolean allowView = allowView(column, view); boolean denyView = denyView(column, view); if (allowView & !denyView) { return true; } return false; } private boolean allowView(Column column, String view) { String viewsAllowed = column.getViewsAllowed(); if (StringUtils.isBlank(viewsAllowed)) { return true; } String split[] = StringUtils.split(viewsAllowed, ","); for (int i = 0; i < split.length; i++) { if (view.equals(split[i])) { return true; } } return false; } private boolean denyView(Column column, String view) { String viewsDenied = column.getViewsDenied(); if (StringUtils.isBlank(viewsDenied)) { return false; } String split[] = StringUtils.split(viewsDenied, ","); for (int i = 0; i < split.length; i++) { if (view.equals(split[i])) { return true; } } return false; } public void destroy() { columns.clear(); columns = null; lookup.clear(); lookup = null; firstColumn = null; lastColumn = null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -