📄 defaultabstracttree.java
字号:
} else { urls[i] = "indent-line"; } parent = parent.getParent(); } for (int i = level - 1; i >= 0; --i) { response.write("<span class=\"" + urls[i] + "\"></span>"); } } }; result.setRenderBodyOnly(true); return result; } /** * Creates an image placed on junction link. This image actually consists of two spans with * different css classes. These classes are specified according to the stylesheet to make the * junction image look well together with lines connecting nodes. * * @param parent * The component parent * @param id * The component id * @param node * The tree node * @return The component that represents a junction */ protected MarkupContainer newJunctionImage(MarkupContainer parent, final String id, final TreeNode node) { return (MarkupContainer)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); final String cssClassInner; if (node.isLeaf() == false) { cssClassInner = isNodeExpanded(node) ? "minus" : "plus"; } else { cssClassInner = "corner"; } final String cssClassOuter = isNodeLast(node) ? "junction-last" : "junction"; Response response = RequestCycle.get().getResponse(); response.write("<span class=\"" + cssClassOuter + "\"><span class=\"" + cssClassInner + "\"></span></span>"); } }.setRenderBodyOnly(true); } /** * 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 String imageId, final TreeNode node) { final MarkupContainer junctionLink; if (node.isLeaf() == false) { junctionLink = newLink(parent, 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); } }); } 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.put("onclick", "return false"); } }; } if (imageId != null) { junctionLink.add(newJunctionImage(junctionLink, imageId, node)); } return junctionLink; } /** * Creates a link of type specified by current linkType. When the links is clicked it calls the * specified callback. * * @param parent * The parent component * @param id * The component id * @param callback * The link call back * @return The link component */ protected MarkupContainer newLink(MarkupContainer parent, 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); } }; } } /** * Creates the icon for current node. By default uses image reference specified by * {@link DefaultAbstractTree#getNodeIcon(TreeNode)}. * * @param parent * The parent component * @param id * The component id * @param node * The tree node * @return The web component that represents the icon of the current node */ protected Component newNodeIcon(MarkupContainer parent, String id, final TreeNode node) { return new WebMarkupContainer(id) { private static final long serialVersionUID = 1L; protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("style", "background-image: url('" + RequestCycle.get().urlFor(getNodeIcon(node)) + "')"); } }; } /** * Creates a link that can be used to select / deselect the specified node. * * @param parent * The parent component * @param id * The component id * @param node * The parent node * @return The component that represents the link */ protected MarkupContainer newNodeLink(MarkupContainer parent, String id, final TreeNode node) { return newLink(parent, id, new ILinkCallback() { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { getTreeState().selectNode(node, !getTreeState().isNodeSelected(node)); onNodeLinkClicked(target, node); updateTree(target); } }); } /** * 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) { } /** * This callback method is called after user has selected / deselected the given node. * * @param target * Request target - may be null on non-ajax call * * @param node * Node for which this this callback is fired. */ protected void onNodeLinkClicked(AjaxRequestTarget target, TreeNode node) { } /** * Performs the tree initialization. Adds header contribution for the stylesheet. */ private void init() { ResourceReference css = getCSS(); if (css != null) { add(HeaderContributor.forCss(css.getScope(), css.getName())); } } /** * 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 boolean isNodeLast(TreeNode node) { TreeNode parent = node.getParent(); if (parent == null) { return true; } else { return parent.getChildAt(parent.getChildCount() - 1).equals(node); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -