001: /*
002: * $Id: Panel.java 460110 2006-04-02 07:32:18Z jdonnerstag $ $Revision:
003: * 1.10 $ $Date: 2006-04-02 09:32:18 +0200 (Sun, 02 Apr 2006) $
004: *
005: * ==============================================================================
006: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007: * use this file except in compliance with the License. You may obtain a copy of
008: * the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package wicket.markup.html.panel;
019:
020: import wicket.markup.ComponentTag;
021: import wicket.markup.MarkupStream;
022: import wicket.markup.html.WebMarkupContainerWithAssociatedMarkup;
023: import wicket.markup.html.internal.HtmlHeaderContainer;
024: import wicket.markup.parser.XmlTag;
025: import wicket.markup.parser.filter.WicketTagIdentifier;
026: import wicket.model.IModel;
027:
028: /**
029: * A panel is a reusable component that holds markup and other components.
030: * <p>
031: * Whereas WebMarkupContainer is an inline container like
032: * <pre>
033: * ...
034: * <span wicket:id="xxx">
035: * <span wicket:id="mylabel">My label</span>
036: * ....
037: * </span>
038: * ...
039: * </pre>
040: * a Panel has its own associated markup file and the container content is
041: * taken from that file, like:
042: * <pre>
043: * <span wicket:id="mypanel"/>
044: *
045: * TestPanel.html
046: * <wicket:panel>
047: * <span wicket:id="mylabel">My label</span>
048: * ....
049: * </wicket:panel>
050: * </pre>
051: *
052: * @author Jonathan Locke
053: * @author Juergen Donnerstag
054: */
055: public class Panel extends WebMarkupContainerWithAssociatedMarkup {
056: private static final long serialVersionUID = 1L;
057:
058: static {
059: // register "wicket:fragement"
060: WicketTagIdentifier.registerWellKnownTagName("panel");
061: }
062:
063: /** If if tag was an open-close tag */
064: private boolean wasOpenCloseTag = false;
065:
066: /**
067: * @see wicket.Component#Component(String)
068: */
069: public Panel(final String id) {
070: super (id);
071: }
072:
073: /**
074: * @see wicket.Component#Component(String, IModel)
075: */
076: public Panel(final String id, final IModel model) {
077: super (id, model);
078: }
079:
080: /**
081: *
082: * @see wicket.Component#onComponentTag(wicket.markup.ComponentTag)
083: */
084: protected void onComponentTag(final ComponentTag tag) {
085: if (tag.isOpenClose()) {
086: this .wasOpenCloseTag = true;
087:
088: // Convert <span wicket:id="myPanel" /> into
089: // <span wicket:id="myPanel">...</span>
090: tag.setType(XmlTag.OPEN);
091: }
092: super .onComponentTag(tag);
093: }
094:
095: /**
096: *
097: * @see wicket.Component#onComponentTagBody(wicket.markup.MarkupStream, wicket.markup.ComponentTag)
098: */
099: protected void onComponentTagBody(final MarkupStream markupStream,
100: final ComponentTag openTag) {
101: // Render the associated markup
102: renderAssociatedMarkup("panel",
103: "Markup for a panel component has to contain part '<wicket:panel>'");
104:
105: if (this .wasOpenCloseTag == false) {
106: // Skip any raw markup in the body
107: markupStream.skipRawMarkup();
108: }
109: }
110:
111: /**
112: * Check the associated markup file for a wicket header tag
113: *
114: * @see wicket.Component#renderHead(wicket.markup.html.internal.HtmlHeaderContainer)
115: */
116: public void renderHead(HtmlHeaderContainer container) {
117: this.renderHeadFromAssociatedMarkupFile(container);
118: super.renderHead(container);
119: }
120: }
|