KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > nodes > ColumnElementNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.dbschema.nodes;
21
22 import java.beans.*;
23
24 import org.openide.nodes.*;
25
26 import org.netbeans.modules.dbschema.*;
27 import org.netbeans.modules.dbschema.util.SQLTypeUtil;
28
29 /** Node representing a column.
30  * @see ColumnElement
31  */

32 public class ColumnElementNode extends DBMemberElementNode {
33     /** Create a new column node.
34      * @param element column element to represent
35      * @param writeable <code>true</code> to be writable
36      */

37     public ColumnElementNode (ColumnElement element, boolean writeable) {
38         super(element, Children.LEAF, writeable);
39     }
40
41     /* Resolve the current icon base.
42      * @return icon base string.
43      */

44     protected String JavaDoc resolveIconBase () {
45         return COLUMN;
46     }
47
48     /* Creates property set for this node */
49     protected Sheet createSheet () {
50         Sheet sheet = Sheet.createDefault();
51         Sheet.Set ps = sheet.get(Sheet.PROPERTIES);
52
53         ps.put(createNameProperty(writeable));
54         ps.put(createTypeProperty(writeable));
55         ps.put(createNullableProperty(writeable));
56         ps.put(createLengthProperty(writeable));
57         ps.put(createPrecisionProperty(writeable));
58         ps.put(createScaleProperty(writeable));
59
60         return sheet;
61     }
62
63     /** Create a property for the column type.
64      * @param canW <code>false</code> to force property to be read-only
65      * @return the property
66      */

67     protected Node.Property createTypeProperty (boolean canW) {
68         return new ElementProp(PROP_TYPE, /*Integer.TYPE*/String JavaDoc.class, canW) {
69             /** Gets the value */
70             public Object JavaDoc getValue () {
71                 return SQLTypeUtil.getSqlTypeString(((ColumnElement) element).getType());
72             }
73         };
74     }
75     
76     /** Create a property for the column nullable.
77      * @param canW <code>false</code> to force property to be read-only
78      * @return the property
79      */

80     protected Node.Property createNullableProperty (boolean canW) {
81         return new ElementProp(PROP_NULLABLE, Boolean.TYPE, canW) {
82             /** Gets the value */
83             public Object JavaDoc getValue () {
84                 return Boolean.valueOf(((ColumnElement)element).isNullable());
85             }
86         };
87     }
88     
89     /** Create a property for the column length.
90      * @param canW <code>false</code> to force property to be read-only
91      * @return the property
92      */

93     protected Node.Property createLengthProperty (boolean canW) {
94         return new ElementProp(PROP_LENGTH, Integer.TYPE, canW) {
95             /** Gets the value */
96             public Object JavaDoc getValue () {
97                 return ((ColumnElement)element).getLength();
98             }
99         };
100     }
101     
102     /** Create a property for the column precision.
103      * @param canW <code>false</code> to force property to be read-only
104      * @return the property
105      */

106     protected Node.Property createPrecisionProperty (boolean canW) {
107         return new ElementProp(PROP_PRECISION, Integer.TYPE, canW) {
108             /** Gets the value */
109             public Object JavaDoc getValue () {
110                 return ((ColumnElement)element).getPrecision();
111             }
112         };
113     }
114     
115     /** Create a property for the column scale.
116      * @param canW <code>false</code> to force property to be read-only
117      * @return the property
118      */

119     protected Node.Property createScaleProperty (boolean canW) {
120         return new ElementProp(PROP_SCALE, Integer.TYPE, canW) {
121             /** Gets the value */
122             public Object JavaDoc getValue () {
123                 return ((ColumnElement)element).getScale();
124             }
125         };
126     }
127 }
128
Popular Tags