001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.sql.framework.ui.editor.property.impl;
043:
044: import java.beans.PropertyChangeListener;
045: import java.beans.PropertyChangeSupport;
046: import java.beans.PropertyVetoException;
047: import java.beans.VetoableChangeListener;
048: import java.beans.VetoableChangeSupport;
049: import java.util.ArrayList;
050: import java.util.Iterator;
051: import java.util.List;
052:
053: import org.netbeans.modules.sql.framework.ui.editor.property.IElement;
054: import org.netbeans.modules.sql.framework.ui.editor.property.INode;
055: import org.netbeans.modules.sql.framework.ui.editor.property.IProperty;
056: import org.netbeans.modules.sql.framework.ui.editor.property.IPropertyGroup;
057:
058: /**
059: * @author Ritesh Adval
060: * @version $Revision$
061: */
062: public class PropertyGroup implements IPropertyGroup, Comparable {
063:
064: private String displayName;
065: private String name;
066: private INode parent;
067: private int position;
068: private List<IProperty> propertyList = new ArrayList<IProperty>();
069:
070: private PropertyChangeSupport pSupport = new PropertyChangeSupport(
071: this );
072:
073: private String toolTip;
074:
075: private VetoableChangeSupport vSupport = new VetoableChangeSupport(
076: this );
077:
078: /** Creates a new instance of PropertyGroup */
079: public PropertyGroup() {
080: }
081:
082: /**
083: * add a element in the node
084: *
085: * @param element element to add
086: */
087: public void add(IElement element) {
088: element.setParent(this );
089: addProperty((IProperty) element);
090: }
091:
092: /**
093: * add a property in this gropu
094: *
095: * @param property
096: */
097: public void addProperty(IProperty property) {
098: propertyList.add(property);
099: }
100:
101: /**
102: * add a property change listener
103: *
104: * @param listener property change listener
105: */
106: public void addPropertyChangeListener(
107: PropertyChangeListener listener) {
108: pSupport.addPropertyChangeListener(listener);
109: }
110:
111: /**
112: * add a vetoable change listener
113: *
114: * @param listener vetoable change listener
115: */
116: public void addVetoableChangeListener(
117: VetoableChangeListener listener) {
118: vSupport.addVetoableChangeListener(listener);
119: }
120:
121: /**
122: * Compares this object with the specified object for order. Returns a negative
123: * integer, zero, or a positive integer as this object is less than, equal to, or
124: * greater than the specified object.
125: * <p>
126: * In the foregoing description, the notation <tt>sgn(</tt> <i>expression </i>
127: * <tt>)</tt> designates the mathematical <i>signum </i> function, which is defined
128: * to return one of <tt>-1</tt>,<tt>0</tt>, or <tt>1</tt> according to
129: * whether the value of <i>expression </i> is negative, zero or positive. The
130: * implementor must ensure <tt>sgn(x.compareTo(y)) ==
131: * -sgn(y.compareTo(x))</tt> for
132: * all <tt>x</tt> and <tt>y</tt>. (This implies that <tt>x.compareTo(y)</tt>
133: * must throw an exception iff <tt>y.compareTo(x)</tt> throws an exception.)
134: * <p>
135: * The implementor must also ensure that the relation is transitive:
136: * <tt>(x.compareTo(y)>0 && y.compareTo(z)>0)</tt> implies
137: * <tt>x.compareTo(z)>0</tt>.
138: * <p>
139: * Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt> implies that
140: * <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for all <tt>z</tt>.
141: * <p>
142: * It is strongly recommended, but <i>not </i> strictly required that
143: * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any class
144: * that implements the <tt>Comparable</tt> interface and violates this condition
145: * should clearly indicate this fact. The recommended language is "Note: this class
146: * has a natural ordering that is inconsistent with equals."
147: *
148: * @param o the Object to be compared.
149: * @return a negative integer, zero, or a positive integer as this object is less
150: * than, equal to, or greater than the specified object.
151: * @throws ClassCastException if the specified object's type prevents it from being
152: * compared to this Object.
153: */
154: public int compareTo(Object o) {
155: if (!(o instanceof IPropertyGroup)) {
156: throw new ClassCastException("Object " + o
157: + " being compared is not same as this object");
158: }
159:
160: IPropertyGroup propertyG = (IPropertyGroup) o;
161:
162: if (this .getPosition() < propertyG.getPosition()) {
163: return -1;
164: } else if (this .getPosition() > propertyG.getPosition()) {
165: return 1;
166: }
167:
168: return 0;
169: }
170:
171: public void firePropertyChangeEvent() {
172: pSupport.firePropertyChange(IPropertyGroup.VALID_ALL, this
173: .isValid(), this .isValid());
174: }
175:
176: public void firePropertyChangeEvent(String propertyName,
177: Object oldVal, Object newVal) {
178: pSupport.firePropertyChange(propertyName, oldVal, newVal);
179: }
180:
181: public void fireVetoableChangeEvent(String propertyName,
182: Object oldVal, Object newVal) throws PropertyVetoException {
183: vSupport.fireVetoableChange(propertyName, oldVal, newVal);
184: }
185:
186: /**
187: * get the display name of of element
188: *
189: * @return display name
190: */
191: public String getDisplayName() {
192: return displayName;
193: }
194:
195: /**
196: * get the name of of element
197: *
198: * @return name
199: */
200: public String getName() {
201: return this .name;
202: }
203:
204: /**
205: * get the parent element
206: *
207: * @return parent
208: */
209: public INode getParent() {
210: return parent;
211: }
212:
213: /**
214: * get the position where this property should appear in the property sheet gui
215: *
216: * @return position
217: */
218: public int getPosition() {
219: return this .position;
220: }
221:
222: /**
223: * get all the properties in this group
224: *
225: * @return all the properties in this group
226: */
227: public List<IProperty> getProperties() {
228: return propertyList;
229: }
230:
231: /**
232: * get the tooltip of of element
233: *
234: * @return tooltip
235: */
236: public String getToolTip() {
237: return this .toolTip;
238: }
239:
240: /**
241: * is valid value
242: *
243: * @return valid value
244: */
245: public boolean isValid() {
246: Iterator it = propertyList.iterator();
247: while (it.hasNext()) {
248: IProperty property = (IProperty) it.next();
249: if (property.isRequired() && !property.isValid()) {
250: return false;
251: }
252: }
253: return true;
254: }
255:
256: /**
257: * remove a property change listener
258: *
259: * @param listener property change listener
260: */
261: public void removePropertyChangeListener(
262: PropertyChangeListener listener) {
263: pSupport.removePropertyChangeListener(listener);
264: }
265:
266: /**
267: * remove a vetoable change listener
268: *
269: * @param listener vetoable change listener
270: */
271: public void removeVetoableChangeListener(
272: VetoableChangeListener listener) {
273: vSupport.removeVetoableChangeListener(listener);
274: }
275:
276: /**
277: * set the display name of the element
278: *
279: * @param dName display name
280: */
281: public void setDisplayName(String dName) {
282: this .displayName = dName;
283: }
284:
285: /**
286: * set the name of the element
287: *
288: * @param name name
289: */
290: public void setName(String name) {
291: this .name = name;
292: }
293:
294: /**
295: * set parent parent element
296: */
297: public void setParent(INode parent) {
298: this .parent = parent;
299: }
300:
301: /**
302: * set the position where this property should appear in the property sheet gui
303: *
304: * @return position
305: */
306: public void setPosition(String position) {
307: this .position = Integer.parseInt(position);
308: }
309:
310: /**
311: * set the tooltip of the element
312: *
313: * @param tTip tool tip
314: */
315: public void setToolTip(String tTip) {
316: this.toolTip = tTip;
317: }
318: }
|