001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wicket.extensions.markup.html.tree.table;
018:
019: import javax.swing.tree.TreeNode;
020:
021: import org.apache.wicket.Component;
022: import org.apache.wicket.MarkupContainer;
023: import org.apache.wicket.Response;
024: import org.apache.wicket.util.string.Strings;
025:
026: /**
027: * Convenience class for creating non-interactive lightweight (IRenderable
028: * based) columns.
029: *
030: * @author Matej Knopp
031: */
032: public abstract class AbstractRenderableColumn extends AbstractColumn {
033: private boolean contentAsTooltip = false;
034:
035: private boolean escapeContent = true;
036:
037: /**
038: * Creates the column
039: *
040: * @param location
041: * Specifies how the column should be aligned and what his size
042: * should be
043: *
044: * @param header
045: * Header caption
046: */
047: public AbstractRenderableColumn(ColumnLocation location,
048: String header) {
049: super (location, header);
050: }
051:
052: /**
053: * Returns the string value for the provided node.
054: *
055: * @param node
056: * Determines the position in tree
057: * @return The
058: */
059: public abstract String getNodeValue(TreeNode node);
060:
061: /**
062: * Returns whether the content should also be visible as tooltip of the
063: * cell.
064: *
065: * @return whether the content should also be visible as tooltip
066: */
067: public boolean isContentAsTooltip() {
068: return contentAsTooltip;
069: }
070:
071: /**
072: * Returns whether the special html characters of content will be escaped.
073: *
074: * @return Whether html characters should be escaped
075: */
076: public boolean isEscapeContent() {
077: return escapeContent;
078: }
079:
080: /**
081: * @see IColumn#newCell(MarkupContainer, String, TreeNode, int)
082: */
083: public Component newCell(MarkupContainer parent, String id,
084: TreeNode node, int level) {
085: return null;
086: }
087:
088: /**
089: * @see IColumn#newCell(TreeNode, int)
090: */
091: public IRenderable newCell(TreeNode node, int level) {
092: return new IRenderable() {
093: private static final long serialVersionUID = 1L;
094:
095: public void render(TreeNode node, Response response) {
096: String content = getNodeValue(node);
097:
098: // escape if necessary
099: if (isEscapeContent()) {
100: content = Strings.escapeMarkup(content).toString();
101: }
102:
103: response.write("<span");
104: if (isContentAsTooltip()) {
105: response.write(" title=\"" + content + "\"");
106: }
107: response.write(">");
108: response.write(content);
109: response.write("</span>");
110: }
111: };
112: }
113:
114: /**
115: * Sets whether the content should also be visible as tooltip (html title
116: * attribute) of the cell.
117: *
118: * @param contentAsTooltip
119: * whether the content should also be visible as tooltip
120: */
121: public void setContentAsTooltip(boolean contentAsTooltip) {
122: this .contentAsTooltip = contentAsTooltip;
123: }
124:
125: /**
126: * Sets whether the special html characters of content should be escaped.
127: *
128: * @param escapeContent
129: * Whether to espcape html characters
130: */
131: public void setEscapeContent(boolean escapeContent) {
132: this.escapeContent = escapeContent;
133: }
134: }
|