📄 enclosure.java
字号:
/* * 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.internal;import org.apache.wicket.Component;import org.apache.wicket.MarkupContainer;import org.apache.wicket.WicketRuntimeException;import org.apache.wicket.markup.ComponentTag;import org.apache.wicket.markup.MarkupException;import org.apache.wicket.markup.MarkupStream;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.border.Border;import org.apache.wicket.markup.html.border.Border.BorderBodyContainer;import org.apache.wicket.markup.parser.filter.EnclosureHandler;import org.apache.wicket.markup.resolver.EnclosureResolver;import org.slf4j.Logger;import org.slf4j.LoggerFactory;/** * An Enclosure are automatically created by Wicket. Do not create it yourself. An Enclosure * container is created if <wicket:enclosure> is found in the markup. It is meant to solve the * following situation. Instead of * * <pre> * <table wicket:id="label-container" class="notify"><tr><td><span wicket:id="label">[[notification]]</span></td></tr></table> * * WebMarkupContainer container=new WebMarkupContainer("label-container") * { * public boolean isVisible() * { * return hasNotification(); * } * }; * add(container); * container.add(new Label("label", notificationModel)); * </pre> * * with Enclosure you are able to do the following: * * <pre> * <wicket:enclosure> * <table class="notify"><tr><td><span wicket:id="label">[[notification]]</span></td></tr></table> * </wicket:enclosure> * * add(new Label("label", notificationModel)) * { * public boolean isVisible() * { * return hasNotification(); * } * } * </pre> * * @see EnclosureResolver * @see EnclosureHandler * * @author Juergen Donnerstag * @since 1.3 */public class Enclosure extends WebMarkupContainer{ private static final long serialVersionUID = 1L; private static final Logger log = LoggerFactory.getLogger(Enclosure.class); /** The child component to delegate the isVisible() call to */ private Component childComponent; /** Id of the child component that will control visibility of the enclosure */ private final CharSequence childId; /** * Construct. * * @param id * @param childId */ public Enclosure(final String id, final CharSequence childId) { super(id); this.childId = childId; } /** * * @see org.apache.wicket.MarkupContainer#isTransparentResolver() */ public boolean isTransparentResolver() { return true; } /** * * @param childId * @return Child Component */ private Component getChildComponent(final CharSequence childId) { MarkupContainer parent = getParent(); while (parent != null) { if (parent.isTransparentResolver()) { parent = parent.getParent(); } else if (parent instanceof BorderBodyContainer) { parent = ((BorderBodyContainer)parent).findParent(Border.class); } else { break; } } if (parent == null) { throw new WicketRuntimeException( "Unable to find parent component which is not a transparent resolver"); } if (childId == null) { throw new MarkupException( "You most likely forgot to register the EnclosureHandler with the MarkupParserFactory"); } final Component child = parent.get(childId.toString()); if (child == null) { throw new MarkupException( "Didn't find child component of <wicket:enclosure> with id='" + childId + "'. Component: " + this.toString()); } return child; } /** * * @see org.apache.wicket.MarkupContainer#onComponentTagBody(org.apache.wicket.markup.MarkupStream, * org.apache.wicket.markup.ComponentTag) */ protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { if (childComponent == null) { childComponent = getChildComponent(childId); } if (childComponent == this) { throw new WicketRuntimeException( "Programming error: childComponent == enclose component; endless loop"); } else if (childComponent != null) { // Delegate to child component setVisible(childComponent.isVisible() && childComponent.isRenderAllowed()); } if (isVisible() == true) { super.onComponentTagBody(markupStream, openTag); } else { markupStream.skipToMatchingCloseTag(openTag); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -