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 */
017package org.apache.wicket.markup.html.border;
018
019import org.apache.wicket.markup.html.panel.IMarkupSourcingStrategy;
020import org.apache.wicket.markup.html.panel.Panel;
021import org.apache.wicket.markup.html.panel.PanelMarkupSourcingStrategy;
022import org.apache.wicket.model.IModel;
023
024/**
025 * Whereas a Panel replaces the body markup with the associated markup file, a BorderPanel assumes a
026 * that Body component renders the body markup including any number of Wicket Components.
027 * <p>
028 * Example:
029 * 
030 * <pre>
031 * <u>MyPage.html</u>
032 * ...
033 * &lt;div wicket:id="myPanel"&gt;
034 *   ...
035 *   &lt;div wicket:id="componentInBody"/&gt;
036 *   ...
037 * &lt;/div&gt;
038 * 
039 * <u>MyPage.java</u>
040 * ...
041 * public MyPage extends WebPage {
042 *   ...
043 *   public MyPage() { 
044 *     ...
045 *     MyPanel border = new MyPanel("myPanel");
046 *     add(border);
047 *     border.getBodyContainer().add(new MyComponent("componentInBody"));
048 *     ...
049 *   }
050 *   ...
051 * }
052 * 
053 * <u>MyPanel.java</u>
054 * ...
055 * public MyPanel extends BorderPanel {
056 *   ...
057 *   public MyPanel(final String id) {
058 *     super(id);
059 *     ...
060 *     add(newBodyContainer("body"));
061 *     ...
062 *   }
063 * }
064 * </pre>
065 * 
066 * @see BorderBehavior A behavior which adds (raw) markup before and after the component
067 * 
068 * @author Juergen Donnerstag
069 */
070public abstract class BorderPanel extends Panel
071{
072        private static final long serialVersionUID = 1L;
073
074        private Body body;
075
076        /**
077         * @see org.apache.wicket.Component#Component(String)
078         */
079        public BorderPanel(final String id)
080        {
081                this(id, null);
082        }
083
084        /**
085         * @see org.apache.wicket.Component#Component(String, IModel)
086         */
087        public BorderPanel(final String id, final IModel<?> model)
088        {
089                super(id, model);
090        }
091
092        @Override
093        protected IMarkupSourcingStrategy newMarkupSourcingStrategy()
094        {
095                return PanelMarkupSourcingStrategy.get(true);
096        }
097
098        /**
099         * Sets the body container
100         * 
101         * @param body
102         * @return The body component
103         */
104        public final Body setBodyContainer(final Body body)
105        {
106                this.body = body;
107                return body;
108        }
109
110        /**
111         * Provide easy access to the Body component.
112         * 
113         * @return The body container
114         */
115        public final Body getBodyContainer()
116        {
117                return body;
118        }
119
120        /**
121         * Create a new body container identified by id in the panel's markup
122         * 
123         * @param id
124         * @return Body component
125         */
126        public final Body newBodyContainer(final String id)
127        {
128                body = new Body(id, this);
129                return body;
130        }
131}