KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > editors > CmsDialogElement


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/CmsDialogElement.java,v $
3  * Date : $Date: 2005/06/23 11:11:54 $
4  * Version: $Revision: 1.9 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.editors;
33
34 import org.opencms.util.CmsStringUtil;
35
36 /**
37  * Contains the setup information about a single dialog element.<p>
38  *
39  * @author Alexander Kandzior
40  *
41  * @version $Revision: 1.9 $
42  *
43  * @since 6.0.0
44  */

45 public class CmsDialogElement implements Comparable JavaDoc {
46
47     /** Indicates if the element is existing on the page or not. */
48     private boolean m_existing;
49
50     /** Indicates if the element is mandantory or not. */
51     private boolean m_mandantory;
52
53     /** The (system) name of the element. */
54     private String JavaDoc m_name;
55
56     /** The nice "display" name of the element. */
57     private String JavaDoc m_niceName;
58
59     /** Indicates if the element is declared as template-element or not. */
60     private boolean m_templateElement;
61
62     /**
63      * Creates a new dialog element.<p>
64      *
65      * @param name the (system) name of the element
66      * @param niceName the nice "display" name of the element
67      * @param mandantory indicates if the element is mandantory
68      * @param templateElement indicates if the element is defined as template-element
69      * @param existing indicates if the element is existing on the xmlPage or not
70      */

71     public CmsDialogElement(String JavaDoc name, String JavaDoc niceName, boolean mandantory, boolean templateElement, boolean existing) {
72
73         m_name = name;
74         m_niceName = niceName;
75         m_mandantory = mandantory;
76         m_templateElement = templateElement;
77         m_existing = existing;
78     }
79
80     /**
81      * @see java.lang.Comparable#compareTo(java.lang.Object)
82      */

83     public int compareTo(Object JavaDoc obj) {
84
85         if (obj == this) {
86             return 0;
87         }
88         if (obj instanceof CmsDialogElement) {
89             CmsDialogElement element = (CmsDialogElement)obj;
90             if (m_name == null) {
91                 return (element.m_name == null) ? 0 : -1;
92             } else {
93                 return m_name.compareToIgnoreCase(element.m_name);
94             }
95         }
96         return 0;
97     }
98
99     /**
100      * @see java.lang.Object#equals(java.lang.Object)
101      */

102     public boolean equals(Object JavaDoc obj) {
103
104         if (obj == this) {
105             return true;
106         }
107         if (!(obj instanceof CmsDialogElement)) {
108             return false;
109         }
110         CmsDialogElement other = (CmsDialogElement)obj;
111         if (m_name == null) {
112             return other.m_name == null;
113         } else {
114             if (other.m_name == null) {
115                 return false;
116             }
117             String JavaDoc name1 = m_name;
118             String JavaDoc name2 = other.m_name;
119             if (name1.endsWith("[0]")) {
120                 name1 = name1.substring(0, name1.length() - 3);
121             }
122             if (name2.endsWith("[0]")) {
123                 name2 = name2.substring(0, name2.length() - 3);
124             }
125             return name1.equals(name2);
126         }
127     }
128
129     /**
130      * Returns the name.<p>
131      *
132      * @return the name
133      */

134     public String JavaDoc getName() {
135
136         return m_name;
137     }
138
139     /**
140      * Returns the niceName.<p>
141      *
142      * @return the niceName
143      */

144     public String JavaDoc getNiceName() {
145
146         if (CmsStringUtil.isEmpty(m_niceName)) {
147             // if the nice name is empty use the system name for display
148

149             if (isExisting() && !isTemplateElement()) {
150                 // this element was not defined with the "template-elements" property
151
return "* " + getName();
152             } else {
153                 return getName();
154             }
155         }
156
157         return m_niceName;
158     }
159
160     /**
161      * @see java.lang.Object#hashCode()
162      */

163     public int hashCode() {
164
165         if (m_name == null) {
166             return 0;
167         } else {
168             return m_name.hashCode();
169         }
170     }
171
172     /**
173      * Returns the existing.<p>
174      *
175      * @return the existing
176      */

177     public boolean isExisting() {
178
179         return m_existing;
180     }
181
182     /**
183      * Returns the mandantory.<p>
184      *
185      * @return the mandantory
186      */

187     public boolean isMandantory() {
188
189         return m_mandantory;
190     }
191
192     /**
193      * Returns true if the element is defined by the template,
194      * false if the element is just contained in the xml page code.<p>
195      *
196      * @return true if the element is defined by the template
197      */

198     public boolean isTemplateElement() {
199
200         return m_templateElement;
201     }
202
203     /**
204      * Sets the existing.<p>
205      *
206      * @param existing the existing to set
207      */

208     public void setExisting(boolean existing) {
209
210         m_existing = existing;
211     }
212 }
Popular Tags