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-2006 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.dbschema.nodes;
043:
044: import java.beans.*;
045:
046: import org.openide.nodes.*;
047:
048: import org.netbeans.modules.dbschema.*;
049: import org.netbeans.modules.dbschema.util.SQLTypeUtil;
050:
051: /** Node representing a column.
052: * @see ColumnElement
053: */
054: public class ColumnElementNode extends DBMemberElementNode {
055: /** Create a new column node.
056: * @param element column element to represent
057: * @param writeable <code>true</code> to be writable
058: */
059: public ColumnElementNode(ColumnElement element, boolean writeable) {
060: super (element, Children.LEAF, writeable);
061: }
062:
063: /* Resolve the current icon base.
064: * @return icon base string.
065: */
066: protected String resolveIconBase() {
067: return COLUMN;
068: }
069:
070: /* Creates property set for this node */
071: protected Sheet createSheet() {
072: Sheet sheet = Sheet.createDefault();
073: Sheet.Set ps = sheet.get(Sheet.PROPERTIES);
074:
075: ps.put(createNameProperty(writeable));
076: ps.put(createTypeProperty(writeable));
077: ps.put(createNullableProperty(writeable));
078: ps.put(createLengthProperty(writeable));
079: ps.put(createPrecisionProperty(writeable));
080: ps.put(createScaleProperty(writeable));
081:
082: return sheet;
083: }
084:
085: /** Create a property for the column type.
086: * @param canW <code>false</code> to force property to be read-only
087: * @return the property
088: */
089: protected Node.Property createTypeProperty(boolean canW) {
090: return new ElementProp(PROP_TYPE, /*Integer.TYPE*/
091: String.class, canW) {
092: /** Gets the value */
093: public Object getValue() {
094: return SQLTypeUtil
095: .getSqlTypeString(((ColumnElement) element)
096: .getType());
097: }
098: };
099: }
100:
101: /** Create a property for the column nullable.
102: * @param canW <code>false</code> to force property to be read-only
103: * @return the property
104: */
105: protected Node.Property createNullableProperty(boolean canW) {
106: return new ElementProp(PROP_NULLABLE, Boolean.TYPE, canW) {
107: /** Gets the value */
108: public Object getValue() {
109: return Boolean.valueOf(((ColumnElement) element)
110: .isNullable());
111: }
112: };
113: }
114:
115: /** Create a property for the column length.
116: * @param canW <code>false</code> to force property to be read-only
117: * @return the property
118: */
119: protected Node.Property createLengthProperty(boolean canW) {
120: return new ElementProp(PROP_LENGTH, Integer.TYPE, canW) {
121: /** Gets the value */
122: public Object getValue() {
123: return ((ColumnElement) element).getLength();
124: }
125: };
126: }
127:
128: /** Create a property for the column precision.
129: * @param canW <code>false</code> to force property to be read-only
130: * @return the property
131: */
132: protected Node.Property createPrecisionProperty(boolean canW) {
133: return new ElementProp(PROP_PRECISION, Integer.TYPE, canW) {
134: /** Gets the value */
135: public Object getValue() {
136: return ((ColumnElement) element).getPrecision();
137: }
138: };
139: }
140:
141: /** Create a property for the column scale.
142: * @param canW <code>false</code> to force property to be read-only
143: * @return the property
144: */
145: protected Node.Property createScaleProperty(boolean canW) {
146: return new ElementProp(PROP_SCALE, Integer.TYPE, canW) {
147: /** Gets the value */
148: public Object getValue() {
149: return ((ColumnElement) element).getScale();
150: }
151: };
152: }
153: }
|