📄 treecell.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.tree.cell;import java.util.Map;import org.apache.commons.beanutils.BeanUtils;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.extremecomponents.table.cell.BaseCell;import org.extremecomponents.table.core.ParameterRegistry;import org.extremecomponents.tree.bean.TreeNode;import org.extremecomponents.tree.core.TreeModel;import org.extremecomponents.tree.core.TreeModelUtils;import org.extremecomponents.util.HtmlBuilder;/** * Will generate a simple cell to display. * * @author Jeff Johnston */public class TreeCell extends BaseCell { private static Log logger = LogFactory.getLog(TreeCell.class); public static final String PLUS_IMAGE = "plus"; public static final String MINUS_IMAGE = "minus"; String plus; String minus; public String html() { HtmlBuilder html = new HtmlBuilder(); html.append(startTD()); Object value = column.getValue(); if ((value != null) && StringUtils.isNotEmpty(value.toString())) { try { TreeModel treeModel = (TreeModel) model; TreeNode node = (TreeNode) value; html.append(buildNodeCell(treeModel, node)); } catch (Exception e) { logger.error("TreeCell.html() Problem", e); } } else { html.append(" "); } html.append(endTD()); return html.toString(); } public String value() { Object obj = column.getPropertyValue(); if (obj != null) { return obj.toString(); } return ""; } private String buildNodeCell(TreeModel model, TreeNode node) throws Exception { HtmlBuilder html = new HtmlBuilder(); String val = null; if (StringUtils.isNotBlank(model.getExtendedValue())) { val = model.getExtendedValue(); } else if (StringUtils.isNotBlank(column.getProperty())) { val = BeanUtils.getProperty(node, column.getProperty()); } if (StringUtils.isBlank(val)) { val = ""; } plus = model.getTableHandler().getTable().getImage(PLUS_IMAGE); minus = model.getTableHandler().getTable().getImage(MINUS_IMAGE); html.table(0).cellPadding("0").cellSpacing("0").border("0").close().tr(1).close(); for (int i = 0; i < node.getDepth(); i++) { html.td(2).close().nbsp().nbsp().nbsp().tdEnd(); } if ((node.getChildren() != null) && (node.getChildren().size() > 0)) { buildLink(model, node, val, html); } else { html.td(2).close().nbsp().nbsp().nbsp().tdEnd(); //Image buffer html.td(2).close().nbsp().append(val).tdEnd(); } html.trEnd(1).tableEnd(0); return html.toString(); } private void buildLink(TreeModel model, TreeNode node, String val, HtmlBuilder html) throws Exception { String id = BeanUtils.getProperty(node, model.getIdentifier()); html.td(2).close(); html.a().quote(); String action = model.getTableHandler().getTable().getAction(); if (StringUtils.isNotEmpty(action)) { html.append(action); } String queryString = model.getRegistry().getURLParameterString(true, false, false, true); Map openNodes = model.getOpenNodes(); Object[] keys = openNodes.keySet().toArray(); String currentCellOpenKey = TreeModelUtils.getNodeKey(model, id); boolean whatThe = false; if (StringUtils.isNotBlank(queryString)) { html.question().append(queryString); whatThe = true; } for (int i = 0; i < keys.length; i++) { if (keys[i].equals(currentCellOpenKey)) { continue; } if (whatThe) { html.ampersand(); } else { html.question(); whatThe = true; } html.append(keys[i]).equals().append("true"); } html.append(model.getRegistry().getParameterString(ParameterRegistry.SORT)); if (node.isOpen()) { html.quote().title("Close").close(); html.img(minus).aEnd(); } else { if (whatThe) { html.ampersand(); } else { html.question(); whatThe = true; } html.append(currentCellOpenKey).equals().append("true"); html.quote().title("Open").close(); html.img(plus).aEnd(); } html.tdEnd().td(2).close().nbsp().append(val).tdEnd(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -