KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > model > core > Layout


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.model.core;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20
21 /**
22  * <p>Layout based on Tiles definition. </p>
23  * <p>Layout is a {@link Localizable} that is to be used as a template for pages.
24  * Layout has may have tiles definition for content pages, that describes actual 'layout'
25  * of information on pages that will be based on this layout. Also, Layout has
26  * {@link ContentField}s and menu (built from {@link MenuItem}s); they will be
27  * inherited by derived pages.
28  * </p>
29  * <p><a HREF="Layout.java.htm"><i>View Source</i></a>
30  * </p>
31  * <p/>
32  *
33  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
34  * @version $Revision: 1.29 $ $Date: 2005/12/18 16:43:43 $
35  * @see ContentPage
36  * @see ContentField
37  * @see Localizable
38  * @struts.form include-all="false" extends="BaseForm"
39  * @hibernate.joined-subclass table="`al_core_layout`" lazy="false"
40  * @hibernate.joined-subclass-key column="`localizable_id`"
41  */

42 public class Layout extends Localizable {
43
44     //~ Instance variables
45

46     /**
47      * Name of tiles definition that correspond to this layout
48      */

49     protected String JavaDoc definition;
50     /**
51      * Name of this layout
52      */

53     protected String JavaDoc name;
54     /**
55      * Name of additional tiles definition for content page
56      */

57     protected String JavaDoc cpDefinition;
58     /**
59      * List of content pages which are based on this layout
60      */

61     protected List JavaDoc contentPages = new ArrayList JavaDoc();
62
63     //~ Methods
64

65     /**
66      * Returns the Tiles definition name
67      *
68      * @return definition name
69      * @struts.form-field
70      * @struts.validator type="required"
71      * @struts.validator-args arg0resource="core.layout.form.definition"
72      * @hibernate.property
73      * @hibernate.column name="`definition`" not-null="true" unique="true" length="252"
74      */

75     public String JavaDoc getDefinition() {
76         return definition;
77     }
78
79     /**
80      * Sets the Tiles definition name
81      *
82      * @param definition definition name to set
83      */

84     public void setDefinition(String JavaDoc definition) {
85         this.definition = definition;
86     }
87
88
89     /**
90      * Gets the content page definition name
91      *
92      * @return content page definition name
93      * @struts.form-field
94      * @hibernate.property
95      * @hibernate.column name="`cpDefinition`" not-null="false" unique="false" length="252"
96      */

97     public String JavaDoc getCpDefinition() {
98         return cpDefinition;
99     }
100
101     /**
102      * Sets the content page definition name
103      *
104      * @param cpDefinition content page definition name
105      */

106     public void setCpDefinition(String JavaDoc cpDefinition) {
107         this.cpDefinition = cpDefinition;
108     }
109
110
111     /**
112      * Returns the name of the layout.
113      *
114      * @return name
115      * @struts.form-field
116      * @struts.validator type="required"
117      * @struts.validator-args arg0resource="core.layout.form.name"
118      * @struts.validator type="mask" msgkey="core.commons.errors.layoutName"
119      * @struts.validator-var name="mask" value="^[^&lt;&gt;&amp;\042]+$"
120      * @hibernate.property
121      * @hibernate.column name="`name`" not-null="true" unique="true" length="252"
122      */

123     public String JavaDoc getName() {
124         return name;
125     }
126
127     /**
128      * Sets name of the layout
129      *
130      * @param name name of the layout
131      */

132     public void setName(String JavaDoc name) {
133         this.name = name;
134     }
135
136     /**
137      * Returns list of content pages which are based on this layout
138      *
139      * @return list of content pages
140      * @hibernate.bag name="contentPages" inverse="true" lazy="true" cascade="delete" outer-join="false"
141      * @hibernate.collection-key column="`layout_id`"
142      * @hibernate.collection-one-to-many class="com.blandware.atleap.model.core.ContentPage"
143      * @hibernate.cache usage="read-write"
144      */

145     public List JavaDoc getContentPages() {
146         return contentPages;
147     }
148
149     /**
150      * Sets list of content pages which are based on this layout
151      *
152      * @param contentPages list of content pages
153      */

154     public void setContentPages(List JavaDoc contentPages) {
155         this.contentPages = contentPages;
156     }
157
158     /**
159      * Adds a content page to the list of pages which are based on this layout
160      *
161      * @param contentPage the content page to be added
162      */

163     public void addContentPage(ContentPage contentPage) {
164         contentPage.setLayout(this);
165         contentPages.add(contentPage);
166     }
167
168     /**
169      * Updates content page for this layout
170      *
171      * @param contentPage the page to be updated
172      * @return old ContentPage object
173      */

174     public ContentPage updateContentPage(ContentPage contentPage) {
175         ContentPage oldContentPage = null;
176         if ( !contentPage.getLayout().equals(this) ) {
177             int index = contentPage.getLayout().contentPages.indexOf(contentPage);
178             if (index != -1)
179                 oldContentPage = (ContentPage)contentPage.getLayout().contentPages.remove(index);
180             contentPages.add(contentPage);
181             contentPage.setLayout(this);
182         }
183         return oldContentPage;
184     }
185
186     /**
187      * Removes a content page from the list of pages which are based on this layout
188      *
189      * @param contentPage the content page to be removed
190      */

191     public void removeContentPage(ContentPage contentPage) {
192         contentPages.remove(contentPage);
193     }
194
195     public boolean equals(Object JavaDoc o) {
196         if ( this == o ) {
197             return true;
198         }
199         if ( !(o instanceof Layout) ) {
200             return false;
201         }
202
203         final Layout layout = (Layout) o;
204
205         if ( definition != null ? !definition.equals(layout.definition) : layout.definition != null ) {
206             return false;
207         }
208
209         return true;
210     }
211
212     public int hashCode() {
213         return (definition != null ? definition.hashCode() : 0);
214     }
215
216 }
217
Popular Tags