Author: knopp Date: Sun Jun 10 16:58:22 2007 New Revision: 545982 URL: http://svn.apache.org/viewvc?view=rev&rev=545982 Log: WICKET-633 - Tree components cleanup
New Tree components Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.html incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.html incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelTree.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.html incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkTree.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree-images.png (with props) incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree.css incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/folder-closed.gif (with props) incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/folder-open.gif (with props) incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/item.gif (with props) incubator/wicket/trunk/jdk-1.5/wicket-examples/velocity.log.1 Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/package.html incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/ModelBean.java incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.html incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.java incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/style.css Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java?view=diff&rev=545982&r1=545981&r2=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java Sun Jun 10 16:58:22 2007 @@ -236,7 +236,7 @@ protected void onBeforeRender() { - AbstractTree.this.attach(); + AbstractTree.this.onBeforeRender(); super.onBeforeRender(); } } @@ -573,7 +573,7 @@ { if (isNodeVisible(node)) { - invalidateNode(node, true); + invalidateNode(node, isForceRebuildOnSelectionChange()); } } @@ -584,9 +584,19 @@ { if (isNodeVisible(node)) { - invalidateNode(node, true); + invalidateNode(node, isForceRebuildOnSelectionChange()); } } + + /** + * Determines whether the TreeNode needs to be rebuilt if it is selected + * or deselected + * @return true if the node should be rebuilt after (de)selection, false otherwise + */ + protected boolean isForceRebuildOnSelectionChange() + { + return true; + } /** * Sets whether the root of the tree should be visible. @@ -1053,7 +1063,7 @@ } // - // State and Model's callbacks + // State and Model callbacks // /** Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.html URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.html?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.html (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.html Sun Jun 10 16:58:22 2007 @@ -0,0 +1,22 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<wicket:panel> +<table wicket:id="i" class="wicket-tree-content"><tr> +<a wicket:id="junctionLink"></a> +<td wicket:id="nodeComponent"></td> +</tr></table> +</wicket:panel> \ No newline at end of file Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.java?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.java (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/BaseTree.java Sun Jun 10 16:58:22 2007 @@ -0,0 +1,496 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.wicket.markup.html.tree; + +import javax.swing.tree.TreeNode; + +import org.apache.wicket.Component; +import org.apache.wicket.IClusterable; +import org.apache.wicket.IComponentBorder; +import org.apache.wicket.MarkupContainer; +import org.apache.wicket.RequestCycle; +import org.apache.wicket.ResourceReference; +import org.apache.wicket.Response; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxFallbackLink; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.behavior.AbstractBehavior; +import org.apache.wicket.behavior.HeaderContributor; +import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.markup.html.resources.CompressedResourceReference; +import org.apache.wicket.model.IModel; +import org.apache.wicket.util.lang.EnumeratedType; +import org.apache.wicket.util.string.Strings; + +/** + * An abstract Tree component that should serve as a base for custom Tree + * Components. + * + * It has one abstract method - [EMAIL PROTECTED] #newNodeComponent(String, IModel)} that + * needs to be overriden. + * + * @author Matej Knopp + */ +public abstract class BaseTree extends AbstractTree +{ + /** + * Construct. + * + * @param id + */ + public BaseTree(String id) + { + this(id, null); + } + + /** + * Construct. + * + * @param id + * @param model + */ + public BaseTree(String id, IModel model) + { + super(id, model); + + ResourceReference css = getCSS(); + if (css != null) + { + add(HeaderContributor.forCss(css)); + } + } + + // default stylesheet resource + private static final ResourceReference CSS = new CompressedResourceReference(BaseTree.class, + "res/base-tree.css"); + + /** + * Returns the stylesheet reference + * + * @return stylesheet reference + */ + protected ResourceReference getCSS() + { + return CSS; + } + + private static final long serialVersionUID = 1L; + + private static final String JUNCTION_LINK_ID = "junctionLink"; + private static final String NODE_COMPONENT_ID = "nodeComponent"; + + /** + * @see org.apache.wicket.markup.html.tree.AbstractTree#populateTreeItem(org.apache.wicket.markup.html.WebMarkupContainer, + * int) + */ + protected void populateTreeItem(WebMarkupContainer item, int level) + { + // add juunction link + TreeNode node = (TreeNode)item.getModelObject(); + Component junctionLink = newJunctionLink(item, JUNCTION_LINK_ID, node); + junctionLink.setComponentBorder(new JunctionBorder(node, level)); + item.add(junctionLink); + + // add node component + Component nodeComponent = newNodeComponent(NODE_COMPONENT_ID, item.getModel()); + item.add(nodeComponent); + + // add behavior that conditionally adds the "selected" CSS class name + item.add(new AbstractBehavior() + { + private static final long serialVersionUID = 1L; + + public void onComponentTag(Component component, ComponentTag tag) + { + TreeNode node = (TreeNode)component.getModelObject(); + if (getTreeState().isNodeSelected(node)) + { + CharSequence oldClass = tag.getString("class"); + if (Strings.isEmpty(oldClass)) + { + tag.put("class", getSelectedClass()); + } + else + { + tag.put("class", oldClass + " " + getSelectedClass()); + } + } + } + }); + } + + /** + * Returns the class name that will be added to row's CSS class for selected + * rows + * + * @return CSS class name + */ + protected String getSelectedClass() + { + return "selected"; + } + + /** + * Creates a new component for the given TreeNode. + * + * @param id + * component ID + * @param model + * model that returns the node + * @return component for node + */ + protected abstract Component newNodeComponent(String id, IModel model); + + /** + * Returns whether the provided node is last child of it's parent. + * + * @param node + * The node + * @return whether the provided node is the last child + */ + private static boolean isNodeLast(TreeNode node) + { + TreeNode parent = node.getParent(); + if (parent == null) + { + return true; + } + else + { + return parent.getChildAt(parent.getChildCount() - 1).equals(node); + } + } + + /** + * Class that wraps a link (or span) with a junction table cells. + * @author Matej Knopp + */ + private static class JunctionBorder implements IComponentBorder + { + private static final long serialVersionUID = 1L; + + private TreeNode node; + private int level; + + /** + * Construct. + * + * @param node + * @param level + */ + public JunctionBorder(TreeNode node, int level) + { + this.node = node; + this.level = level; + } + + public void renderAfter(Component component) + { + RequestCycle.get().getResponse().write("</td>"); + } + + public void renderBefore(Component component) + { + Response response = RequestCycle.get().getResponse(); + TreeNode parent = node.getParent(); + + CharSequence classes[] = new CharSequence[level]; + for (int i = 0; i < level; ++i) + { + if (isNodeLast(parent)) + { + classes[i] = "spacer"; + } + else + { + classes[i] = "line"; + } + + parent = parent.getParent(); + } + + for (int i = level - 1; i >= 0; --i) + { + response.write("<td class=\"" + classes[i] + "\"><span></span></td>"); + } + + if (isNodeLast(node)) + { + response.write("<td class=\"half-line\">"); + } + else + { + response.write("<td class=\"line\">"); + } + } + }; + + /** + * Creates the junction link for given node. Also (optionally) creates the + * junction image. If the node is a leaf (it has no children), the created + * junction link is non-functional. + * + * @param parent + * parent component of the link + * + * @param id + * wicket:id of the component + * + * @param imageId + * wicket:id of the image. this can be null, in that case image + * is not created. image is supposed to be placed on the link + * (link is parent of image) + * + * @param node + * tree node for which the link should be created. + * @return The link component + */ + protected Component newJunctionLink(MarkupContainer parent, final String id, final TreeNode node) + { + final MarkupContainer junctionLink; + + if (node.isLeaf() == false) + { + junctionLink = newLink(id, new ILinkCallback() + { + private static final long serialVersionUID = 1L; + + public void onClick(AjaxRequestTarget target) + { + if (isNodeExpanded(node)) + { + getTreeState().collapseNode(node); + } + else + { + getTreeState().expandNode(node); + } + onJunctionLinkClicked(target, node); + updateTree(target); + } + }); + junctionLink.add(new AbstractBehavior() + { + private static final long serialVersionUID = 1L; + + public void onComponentTag(Component component, ComponentTag tag) + { + if (isNodeExpanded(node)) + { + tag.put("class", "junction-open"); + } + else + { + tag.put("class", "junction-closed"); + } + } + }); + } + else + { + junctionLink = new WebMarkupContainer(id) + { + private static final long serialVersionUID = 1L; + + /** + * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag) + */ + protected void onComponentTag(ComponentTag tag) + { + super.onComponentTag(tag); + tag.setName("span"); + tag.put("class", "junction-corner"); + } + }; + + } + + return junctionLink; + } + + /** + * Callback function called after user clicked on an junction link. The node + * has already been expanded/collapsed (depending on previous status). + * + * @param target + * Request target - may be null on non-ajax call + * + * @param node + * Node for which this callback is relevant + */ + protected void onJunctionLinkClicked(AjaxRequestTarget target, TreeNode node) + { + } + + /** + * The type of junction links and node selection links. + * <dl> + * <dt>Regular link</dt> + * <dd>Non-ajax link, always refreshes the whole page. Works with + * javascript disabled.</dd> + * <dt>Ajax link</dt> + * <dd>Links that supports partial updates. Doesn't work with javascript + * disabled</dd> + * <dt>Ajax fallback link</dt> + * <dd>Link that supports partial updates. With javascript disabled acts + * like regular link. The drawback is that generated url (thus the entire + * html) is larger then using the other two</dd> + * </dl> + */ + public static final class LinkType extends EnumeratedType + { + + /** partial updates with no fallback. */ + public static final LinkType AJAX = new LinkType("AJAX"); + + /** + * partial updates that falls back to a regular link in case the client + * does not support javascript. + */ + public static final LinkType AJAX_FALLBACK = new LinkType("AJAX_FALLBACK"); + + /** + * non-ajax version that always re-renders the whole page. + */ + public static final LinkType REGULAR = new LinkType("REGULAR"); + + private static final long serialVersionUID = 1L; + + /** + * Construct. + * + * @param name + */ + public LinkType(String name) + { + super(name); + } + } + + /** + * Helper class for calling an action from a link. + * + * @author Matej Knopp + */ + public interface ILinkCallback extends IClusterable + { + /** + * Called when the click is executed. + * + * @param target + * The ajax request target + */ + void onClick(AjaxRequestTarget target); + } + + /** + * Creates a link of type specified by current linkType. When the links is + * clicked it calls the specified callback. + * + * @param id + * The component id + * @param callback + * The link call back + * @return The link component + */ + public MarkupContainer newLink(String id, final ILinkCallback callback) + { + if (getLinkType() == LinkType.REGULAR) + { + return new Link(id) + { + private static final long serialVersionUID = 1L; + + /** + * @see org.apache.wicket.markup.html.link.Link#onClick() + */ + public void onClick() + { + callback.onClick(null); + } + }; + } + else if (getLinkType() == LinkType.AJAX) + { + return new AjaxLink(id) + { + private static final long serialVersionUID = 1L; + + /** + * @see org.apache.wicket.ajax.markup.html.AjaxLink#onClick(org.apache.wicket.ajax.AjaxRequestTarget) + */ + public void onClick(AjaxRequestTarget target) + { + callback.onClick(target); + } + }; + } + else + { + return new AjaxFallbackLink(id) + { + private static final long serialVersionUID = 1L; + + /** + * @see org.apache.wicket.ajax.markup.html.AjaxFallbackLink#onClick(org.apache.wicket.ajax.AjaxRequestTarget) + */ + public void onClick(AjaxRequestTarget target) + { + callback.onClick(target); + } + }; + } + } + + /** + * Returns the current type of links on tree items. + * + * @return The link type + */ + public LinkType getLinkType() + { + return linkType; + } + + /** + * Sets the type of links on tree items. After the link type is changed, the + * whole tree is rebuild and re-rendered. + * + * @param linkType + * type of links + */ + public void setLinkType(LinkType linkType) + { + if (this.linkType != linkType) + { + this.linkType = linkType; + invalidateAll(); + } + } + + /** + * @see org.apache.wicket.markup.html.tree.AbstractTree#isForceRebuildOnSelectionChange() + */ + protected boolean isForceRebuildOnSelectionChange() + { + return false; + } + + private LinkType linkType = LinkType.AJAX; +} Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.html URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.html?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.html (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.html Sun Jun 10 16:58:22 2007 @@ -0,0 +1,19 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<wicket:panel> +<table class="icon-panel"><tr><td><img wicket:id="icon"></td><td wicket:id="content" class="content"></td></tr></table> +</wicket:panel> \ No newline at end of file Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.java?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.java (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelIconPanel.java Sun Jun 10 16:58:22 2007 @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.wicket.markup.html.tree; + +import javax.swing.tree.TreeNode; + +import org.apache.wicket.Component; +import org.apache.wicket.ResourceReference; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.image.Image; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.IModel; + +/** + * Simple panel that contains an icon next to a label. + * + * @author Matej Knopp + */ +public class LabelIconPanel extends Panel +{ + private static final long serialVersionUID = 1L; + + /** + * Constructs the panel. + * + * @param id + * component id + * @param model + * model that is used to access the TreeNode + * @param tree + */ + public LabelIconPanel(String id, IModel model, BaseTree tree) + { + super(id, model); + + addComponents(model, tree); + } + + /** + * Adds the icon and content components to the panel. You can override this + * method if you want custom components to be added + * + * @param model + * model that can be used to retrieve the TreeNode + * + * @param tree + */ + protected void addComponents(IModel model, BaseTree tree) + { + add(newImageComponent("icon", tree, model)); + add(newContentComponent("content", tree, model)); + } + + /** + * Creates the icon component for the node + * + * @param componentId + * @param tree + * @param model + * @return icon image component + */ + protected Component newImageComponent(String componentId, final BaseTree tree, + final IModel model) + { + return new Image(componentId) + { + private static final long serialVersionUID = 1L; + + protected ResourceReference getImageResourceReference() + { + return LabelIconPanel.this.getImageResourceReference(tree, (TreeNode)model + .getObject()); + } + }; + } + + /** + * Creates the content component (label in this case) for the node + * + * @param componentId + * @param tree + * @param model + * @return content component + */ + protected Component newContentComponent(String componentId, BaseTree tree, IModel model) + { + return new Label(componentId, model); + } + + /** + * Returns the image resource reference based on the give tree node type. + * + * @param tree + * @param node + * @return image resource reference + */ + protected ResourceReference getImageResourceReference(BaseTree tree, TreeNode node) + { + if (node.isLeaf()) + { + return getResourceItemLeaf(node); + } + else + { + if (tree.getTreeState().isNodeExpanded(node)) + { + return getResourceFolderOpen(node); + } + else + { + return getResourceFolderClosed(node); + } + } + } + + /** + * Optional method for wrapping (creating an intermediate model) for the + * tree node model + * + * @param nodeModel + * @return wrapped model + */ + protected IModel wrapNodeModel(IModel nodeModel) + { + return nodeModel; + } + + /** + * Returns resource reference for closed folder icon. + * @param node + * @return resource reference + */ + protected ResourceReference getResourceFolderClosed(TreeNode node) + { + return RESOURCE_FOLDER_CLOSED; + } + + /** + * Returns resource reference for open folder icon. + * @param node + * @return resource reference + */ + protected ResourceReference getResourceFolderOpen(TreeNode node) + { + return RESOURCE_FOLDER_OPEN; + } + + /** + * Returns resource reference for a leaf icon. + * @param node + * @return resource reference + */ + protected ResourceReference getResourceItemLeaf(TreeNode node) + { + return RESOURCE_ITEM; + } + + private static final ResourceReference RESOURCE_FOLDER_OPEN = new ResourceReference( + LabelIconPanel.class, "res/folder-open.gif"); + private static final ResourceReference RESOURCE_FOLDER_CLOSED = new ResourceReference( + LabelIconPanel.class, "res/folder-closed.gif"); + private static final ResourceReference RESOURCE_ITEM = new ResourceReference( + LabelIconPanel.class, "res/item.gif"); +} Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelTree.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelTree.java?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelTree.java (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LabelTree.java Sun Jun 10 16:58:22 2007 @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.wicket.markup.html.tree; + +import java.io.Serializable; + +import javax.swing.tree.TreeModel; + +import org.apache.wicket.Component; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; + +/** + * Simple tree component that uses label to render tree node. + * + * @author Matej Knopp + */ +public class LabelTree extends BaseTree +{ + private static final long serialVersionUID = 1L; + + /** + * Construct. + * + * @param id + */ + public LabelTree(String id) + { + super(id); + } + + /** + * Construct. + * + * @param id + * @param model + * model that provides the [EMAIL PROTECTED] TreeModel} + */ + public LabelTree(String id, IModel model) + { + super(id, model); + } + + /** + * Construct. + * + * @param id + * @param model + * Tree model + */ + public LabelTree(String id, TreeModel model) + { + super(id, new Model((Serializable)model)); + } + + /** + * @see org.apache.wicket.markup.html.tree.BaseTree#newNodeComponent(java.lang.String, + * org.apache.wicket.model.IModel) + */ + protected Component newNodeComponent(String id, IModel model) + { + return new LabelIconPanel(id, model, this); + } + +} Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.html URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.html?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.html (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.html Sun Jun 10 16:58:22 2007 @@ -0,0 +1,19 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<wicket:panel> +<table class="icon-panel"><tr><td wicket:id="iconLink"><img wicket:id="icon" class="icon"/></td><td class="content"><a wicket:id="contentLink"><span wicket:id="content" class="content"></span></a></td></tr></table> +</wicket:panel> \ No newline at end of file Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.java?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.java (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkIconPanel.java Sun Jun 10 16:58:22 2007 @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.wicket.markup.html.tree; + +import javax.swing.tree.TreeNode; + +import org.apache.wicket.MarkupContainer; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.model.IModel; + +/** + * Simple panel that contains a link with icon and a link with a label. + * + * @author Matej Knopp + */ +public class LinkIconPanel extends LabelIconPanel +{ + private static final long serialVersionUID = 1L; + + /** + * Constructs the panel. + * + * @param id + * component id + * @param model + * model that is used to access the TreeNode + * @param tree + */ + public LinkIconPanel(String id, IModel model, BaseTree tree) + { + super(id, model, tree); + } + + /** + * @see org.apache.wicket.markup.html.tree.LabelIconPanel#addComponents(org.apache.wicket.model.IModel, org.apache.wicket.markup.html.tree.BaseTree) + */ + protected void addComponents(final IModel model, final BaseTree tree) + { + BaseTree.ILinkCallback callback = new BaseTree.ILinkCallback() + { + private static final long serialVersionUID = 1L; + + public void onClick(AjaxRequestTarget target) + { + onNodeLinkClicked((TreeNode)model.getObject(), tree, target); + } + }; + + MarkupContainer link = tree.newLink("iconLink", callback); + add(link); + link.add(newImageComponent("icon", tree, model)); + + link = tree.newLink("contentLink", callback); + add(link); + link.add(newContentComponent("content", tree, model)); + } + + /** + * Handler invoked when the link is clicked. By default makes the node selected + * @param node + * @param tree + * @param target + */ + protected void onNodeLinkClicked(TreeNode node, BaseTree tree, AjaxRequestTarget target) + { + tree.getTreeState().selectNode(node, !tree.getTreeState().isNodeSelected(node)); + tree.updateTree(target); + } +} Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkTree.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkTree.java?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkTree.java (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/LinkTree.java Sun Jun 10 16:58:22 2007 @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.wicket.markup.html.tree; + +import java.io.Serializable; + +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreeNode; + +import org.apache.wicket.Component; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; + +/** + * Simple tree component that provides node panel with link allowing user to + * select individual nodes. + * + * @author Matej Knopp + */ +public class LinkTree extends BaseTree +{ + private static final long serialVersionUID = 1L; + + /** + * Construct. + * + * @param id + */ + public LinkTree(String id) + { + super(id); + } + + /** + * + * Construct. + * + * @param id + * @param model + * model that provides the [EMAIL PROTECTED] TreeModel} + */ + public LinkTree(String id, IModel model) + { + super(id, model); + } + + /** + * + * Construct. + * + * @param id + * @param model + * Tree model + */ + public LinkTree(String id, TreeModel model) + { + super(id, new Model((Serializable)model)); + } + + /** + * @see org.apache.wicket.markup.html.tree.BaseTree#newNodeComponent(java.lang.String, org.apache.wicket.model.IModel) + */ + protected Component newNodeComponent(String id, IModel model) + { + return new LinkIconPanel(id, model, LinkTree.this) + { + private static final long serialVersionUID = 1L; + + protected void onNodeLinkClicked(TreeNode node, BaseTree tree, AjaxRequestTarget target) + { + super.onNodeLinkClicked(node, tree, target); + LinkTree.this.onNodeLinkClicked(node, tree, target); + } + }; + } + + /** + * Method invoked after the node has been selected / unselected. + * @param node + * @param tree + * @param target + */ + protected void onNodeLinkClicked(TreeNode node, BaseTree tree, AjaxRequestTarget target) + { + + } +} Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/package.html URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/package.html?view=diff&rev=545982&r1=545981&r2=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/package.html (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/package.html Sun Jun 10 16:58:22 2007 @@ -23,8 +23,5 @@ <p> Package for Tree components. </p> -This tree will be moved to the core project (wicket.markup.html.tree) for -Wicket 2.0 and will serve as Wicket's default tree component, -and the tree that is now in that package will be moved here. </body> </html> Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree-images.png URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree-images.png?view=auto&rev=545982 ============================================================================== Binary file - no diff available. Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree-images.png ------------------------------------------------------------------------------ svn:executable = * Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree-images.png ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree.css URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree.css?view=auto&rev=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree.css (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/base-tree.css Sun Jun 10 16:58:22 2007 @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +table.wicket-tree-content { + border-collapse: collapse; + empty-cells: show; +} + +table.wicket-tree-content, +table.wicket-tree-content td, +table.wicket-tree-content tr, +table.wicket-tree-content th { + padding: 0px; + margin: 0px; +} + +table.wicket-tree-content td.spacer { + width: 18px; + height: 100%; +} + +table.wicket-tree-content td.spacer span, +table.wicket-tree-content td.line span { + display: block; + width: 18px; + height: 18px; +} + +table.wicket-tree-content td.line { + width: 18px; + height: 100%; + background-image: url("base-tree-images.png"); + background-position: -36px center; + background-repeat: repeat-y; +} + +table.wicket-tree-content td.half-line { + width: 18px; + height: 100%; + background-image: url("base-tree-images.png"); + background-position: -72px center; + background-repeat: no-repeat; +} + +table.wicket-tree-content a.junction-open, +table.wicket-tree-content a.junction-closed, +table.wicket-tree-content span.junction-corner { + width: 18px; + height: 18px; + display: block; + background-image: url("base-tree-images.png"); + background-repeat: no-repeat; + margin: 0px; padding: 0px; border-width: 0px; +} + +table.wicket-tree-content a.junction-open { + background-position: -18px center; +} + +table.wicket-tree-content a.junction-closed { + background-position: 0px center; +} + +table.wicket-tree-content span.junction-corner { + background-position: -54px center; +} + +table.wicket-tree-content table.icon-panel { + border-collapse: collapse; + empty-cells: show; +} + +table.wicket-tree-content table.icon-panel, +table.wicket-tree-content table.icon-panel tr, +table.wicket-tree-content table.icon-panel td { + margin: 0px; + padding: 0px; +} + +table.wicket-tree-content table.icon-panel img { + padding: 0px; + margin: 0px; + display: block; + border-width: 0px; + margin-left: 2px; + margin-top: -1px; +} + +table.wicket-tree-content.selected { + background-color: #E0E8FF; + font-weight: bold; +} + +table.wicket-tree-content.selected .content { + font-weight: bold; +} + +table.wicket-tree-content table.icon-panel a { + text-decoration: none; + color: #3311aa; +} + +table.wicket-tree-content table.icon-panel a:hover { + text-decoration: underline; + color: #3311aa; +} + +table.wicket-tree-content table.icon-panel img.icon { + cursor: pointer; +} + +table.icon-panel { + width: 100%; +} + +table.icon-panel td.content { + width: 100%; +} + +table.icon-panel td.content a { + padding-right: 0.4em; +} Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/folder-closed.gif URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/folder-closed.gif?view=auto&rev=545982 ============================================================================== Binary file - no diff available. Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/folder-closed.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/folder-open.gif URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/folder-open.gif?view=auto&rev=545982 ============================================================================== Binary file - no diff available. Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/folder-open.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/item.gif URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/item.gif?view=auto&rev=545982 ============================================================================== Binary file - no diff available. Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/tree/res/item.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/ModelBean.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/ModelBean.java?view=diff&rev=545982&r1=545981&r2=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/ModelBean.java (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/ModelBean.java Sun Jun 10 16:58:22 2007 @@ -187,6 +187,6 @@ @Override public String toString() { - return getProperty1(); + return getProperty1() + ", " + getProperty2() + ", " + getProperty3(); } } Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.html URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.html?view=diff&rev=545982&r1=545981&r2=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.html (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.html Sun Jun 10 16:58:22 2007 @@ -1,11 +1,16 @@ <wicket:head> <style> - div.my-tree div.wicket-tree { - height: 28em; + table.wicket-tree-content { + width: 100%; + } + td { + font-size: 82%; } </style> </wicket:head> <wicket:extend> - <div wicket:id="tree" class="my-tree"> - </div> + <table style="border: 1px solid #eee"><tr><td> + <div wicket:id="tree" class="my-tree"> + </div> + </td></tr></table> </wicket:extend> Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.java?view=diff&rev=545982&r1=545981&r2=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.java (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/tree/SimpleTreePage.java Sun Jun 10 16:58:22 2007 @@ -16,11 +16,9 @@ */ package org.apache.wicket.examples.ajax.builtin.tree; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeNode; - -import org.apache.wicket.extensions.markup.html.tree.Tree; import org.apache.wicket.markup.html.tree.AbstractTree; +import org.apache.wicket.markup.html.tree.BaseTree; +import org.apache.wicket.markup.html.tree.LinkTree; /** @@ -31,7 +29,7 @@ */ public class SimpleTreePage extends BaseTreePage { - private Tree tree; + private BaseTree tree; protected AbstractTree getTree() { @@ -44,14 +42,7 @@ */ public SimpleTreePage() { - tree = new Tree("tree", createTreeModel()) - { - protected String renderNode(TreeNode node) - { - ModelBean bean = (ModelBean)((DefaultMutableTreeNode)node).getUserObject(); - return bean.getProperty1(); - } - }; + tree = new LinkTree("tree", createTreeModel()); add(tree); tree.getTreeState().collapseAll(); } Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml?view=diff&rev=545982&r1=545981&r2=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml Sun Jun 10 16:58:22 2007 @@ -43,7 +43,7 @@ --> <context-param> <param-name>configuration</param-name> - <param-value>deployment</param-value> + <param-value>development</param-value> </context-param> <context-param> Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/style.css URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/style.css?view=diff&rev=545982&r1=545981&r2=545982 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/style.css (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/style.css Sun Jun 10 16:58:22 2007 @@ -172,7 +172,7 @@ table.dataview tr.even { background-color: #ffebcd; } table.dataview tr.odd { background-color: #fff; } table.dataview tr td { padding-left: 8px; padding-right: 30px; } -table.dataview tr th { color: black; padding-top: 3px; padding-bottom: 3px; padding-left: 8px; padding-right: 24px; background-color: #c1e4ff; border-bottom: 1px solid #0079d6; border-top: 1px solid #0079d6; text-align: left; white-space: nowrap; vertical-align: middle;} +table.dataview tr th { color: black; padding-top: 3px; padding-bottom: 3px; padding-left: 8px; padding-right: 30px; background-color: #c1e4ff; border-bottom: 1px solid #0079d6; border-top: 1px solid #0079d6; text-align: left; white-space: nowrap; vertical-align: middle;} table.dataview tr th { background-position: right; background-repeat:no-repeat; } table.dataview tr th.wicket_orderDown {