⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treecell.java

📁 exTreme taglib的使用
💻 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.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.bean.TreeNode;import org.extremecomponents.table.core.TableModelUtils;import org.extremecomponents.table.core.TreeModelUtils;import org.extremecomponents.util.HtmlBuilder;/** * Will generate a simple cell to display. *  * @author Paul Horn */public final 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";    public String html() {        HtmlBuilder html = new HtmlBuilder();        html.append(startTD());        String value = column.getValueAsString();        if (StringUtils.isNotBlank(value)) {            try {                buildNodeCell(html, value);            } catch (Exception e) {                logger.error("TreeCell.html() Problem", e);            }        } else {            html.append("&nbsp;");        }        html.append(endTD());        return html.toString();    }    private void buildNodeCell(HtmlBuilder html, String value)            throws Exception {        html.table(0).cellPadding("0").cellSpacing("0").border("0").close().tr(1).close();        TreeNode node = (TreeNode) model.getCurrentCollectionBean();        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(html, node, value);        } else {            html.td(2).close().nbsp().nbsp().nbsp().tdEnd();            html.td(2).close().nbsp().append(value).tdEnd();        }        html.trEnd(1).tableEnd(0);    }    private void buildLink(HtmlBuilder html, TreeNode node, String value)            throws Exception {        html.td(2).close();        html.a().quote();        String action = model.getTableHandler().getTable().getAction();        if (StringUtils.isNotEmpty(action)) {            html.append(action);        }        html.append(getQueryString(node));        html.quote().close();        if (node.isOpen()) {            html.img(TableModelUtils.getImage(model, MINUS_IMAGE));        } else {            html.img(TableModelUtils.getImage(model, PLUS_IMAGE));        }        html.aEnd();        html.tdEnd().td(2).close().nbsp().append(value).tdEnd();    }    private String getQueryString(TreeNode node)            throws Exception {        HtmlBuilder html = new HtmlBuilder();        html.append(model.getRegistry().getURLParameterString(true, true, false, false));        String identifier = BeanUtils.getProperty(node, model.getTreeHandler().getTree().getIdentifier());        String currentCellOpenKey = TreeModelUtils.getNodeKey(model, identifier);        if (!node.isOpen()) {            html.ampersand().append(currentCellOpenKey).equals().append("true");        }        Map openNodes = model.getTreeHandler().getOpenNodes();        Object[] keys = openNodes.keySet().toArray();        for (int i = 0; i < keys.length; i++) {            if (keys[i].equals(currentCellOpenKey)) {                continue;            }            html.ampersand().append(keys[i]).equals().append("true");        }        if (html.length() == 0) {            return "";        }        return "?" + StringUtils.substringAfter(html.toString(), "&");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -