KickJava   Java API By Example, From Geeks To Geeks.

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


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.text.MessageFormat JavaDoc;
23
24 import org.openide.util.NbBundle;
25 import org.openide.nodes.*;
26
27 import org.netbeans.modules.dbschema.*;
28
29 /** Node representing a database table.
30  * @see TableElement
31  */

32 public class TableElementNode extends DBElementNode {
33     /** Return value of getIconAffectingProperties method. */
34     private static final String JavaDoc[] ICON_AFFECTING_PROPERTIES = new String JavaDoc[] {
35         PROP_TABLE_OR_VIEW
36     };
37
38     /** Create a new class node.
39     * @param element class element to represent
40     * @param children node children
41     * @param writeable <code>true</code> to be writable
42     */

43     public TableElementNode(TableElement element, Children children, boolean writeable) {
44         super(element, children, writeable);
45         setDisplayName(MessageFormat.format((element.isTable() ? NbBundle.getBundle("org.netbeans.modules.dbschema.nodes.Bundle_noi18n").getString("SHORT_tableElement") : NbBundle.getBundle("org.netbeans.modules.dbschema.nodes.Bundle_noi18n").getString("SHORT_viewElement")), new Object JavaDoc[]{super.getDisplayName()})); //NOI18N
46
}
47
48     /* Resolve the current icon base.
49     * @return icon base string.
50     */

51     protected String JavaDoc resolveIconBase() {
52         return ((TableElement)element).isView() ? VIEW : TABLE;
53     }
54
55     /* This method is used for resolving the names of the properties,
56     * which could affect the icon (such as "modifiers").
57     * @return the appropriate array.
58     */

59     protected String JavaDoc[] getIconAffectingProperties() {
60         return ICON_AFFECTING_PROPERTIES;
61     }
62   
63     /* Creates property set for this node */
64     protected Sheet createSheet () {
65         Sheet sheet = Sheet.createDefault();
66         Sheet.Set ps = sheet.get(Sheet.PROPERTIES);
67         ps.put(createNameProperty(writeable));
68         ps.put(createTableOrViewProperty(writeable));
69
70         return sheet;
71     }
72
73     /** Create a node property representing the element's name.
74      * @param canW if <code>false</code>, property will be read-only
75      * @return the property.
76      */

77     protected Node.Property createNameProperty (boolean canW) {
78         return new ElementProp(Node.PROP_NAME, String JavaDoc.class,canW) {
79             /** Gets the value */
80             public Object JavaDoc getValue () {
81                 String JavaDoc name = ((TableElement) element).getName().getFullName();
82                 int pos;
83                     
84                 pos = name.lastIndexOf("."); //NOI18N
85
if (pos != -1)
86                     name = name.substring(pos + 1);
87                 
88                 return name;
89             }
90         };
91     }
92
93     /** Create a property for the table or view flag.
94      * @param canW <code>false</code> to force property to be read-only
95      * @return the property
96      */

97     protected Node.Property createTableOrViewProperty (boolean canW) {
98         return new ElementProp(PROP_TABLE_OR_VIEW, String JavaDoc.class, canW) {
99             /** Gets the value */
100             public Object JavaDoc getValue () {
101                 if (((TableElement)element).isTableOrView())
102                     return NbBundle.getMessage(TableElementNode.class, "Table"); //NOI18N
103
else
104                     return NbBundle.getMessage(TableElementNode.class, "View"); //NOI18N
105
}
106         };
107     }
108 }
109
Popular Tags