KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > nodes > RootNode


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.db.explorer.nodes;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24
25 import org.openide.options.SystemOption;
26 import org.openide.util.NbBundle;
27
28 import org.netbeans.lib.ddl.impl.SpecificationFactory;
29 import org.netbeans.modules.db.explorer.DatabaseOption;
30
31 //commented out for 3.6 release, need to solve for next Studio release
32
//import org.netbeans.modules.db.explorer.PointbasePlus;
33

34 import org.netbeans.modules.db.explorer.infos.DatabaseNodeInfo;
35 import org.netbeans.modules.db.explorer.infos.RootNodeInfo;
36
37 /** Abstract class that can be used as super class of all data objects that
38 * should contain some nodes. It provides methods for adding/removing
39 * sub nodes.
40 */

41 public class RootNode extends DatabaseNode {
42     /** Stores DBNode's connections info */
43     private static DatabaseOption option = null;
44     private static RootNode rootNode = null;
45
46     /** DDLFactory */
47     SpecificationFactory sfactory;
48
49     public static DatabaseOption getOption() {
50         if (option == null)
51             option = (DatabaseOption)SystemOption.findObject(DatabaseOption.class, true);
52
53         return option;
54     }
55
56     public static RootNode getInstance() {
57         if (rootNode == null) {
58             rootNode = new RootNode();
59         }
60         return rootNode;
61     }
62     
63     private RootNode() {
64         setDisplayName(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("NDN_Databases")); //NOI18N
65
try {
66             sfactory = new SpecificationFactory();
67             //initialization listener for debug mode
68
initDebugListening();
69             
70 //commented out for 3.6 release, need to solve for next Studio release
71
//initialization listener for SAMPLE database option
72
// initSampleDatabaseListening();
73

74             DatabaseNodeInfo nfo = RootNodeInfo.getInstance();
75             if (sfactory != null) nfo.setSpecificationFactory(sfactory);
76             else throw new Exception JavaDoc(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_NoSpecificationFactory"));
77
78             setInfo(nfo);
79             getInfo().setNode(this);
80         } catch (Exception JavaDoc e) {
81             e.printStackTrace();
82         }
83     }
84
85     public boolean canRename() {
86         return false;
87     }
88
89     /**
90      * Connects the debug property in sfactory and debugMode property in DBExplorer module's option.
91      */

92     void initDebugListening() {
93         if ( (getOption() == null) || (sfactory == null) ) {
94             initDebugListening();
95         }
96         option.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
97             public void propertyChange(PropertyChangeEvent JavaDoc e) {
98                 if (e.getPropertyName() == null) {
99                     sfactory.setDebugMode(option.getDebugMode());
100                     return;
101                 }
102                 if (e.getPropertyName().equals(DatabaseOption.PROP_DEBUG_MODE))
103                     sfactory.setDebugMode(((Boolean JavaDoc) e.getNewValue()).booleanValue());
104             }
105         });
106         sfactory.setDebugMode(option.getDebugMode());
107     }
108
109 //commented out for 3.6 release, need to solve for next Studio release
110
// void initSampleDatabaseListening() {
111
// if ( (getOption() == null) || (sfactory == null) ) {
112
// initSampleDatabaseListening();
113
// }
114
// option.addPropertyChangeListener(new PropertyChangeListener() {
115
// public void propertyChange(PropertyChangeEvent e) {
116
// if (e.getPropertyName() != null && e.getPropertyName().equals(DatabaseOption.PROP_AUTO_CONNECTION))
117
// if(((Boolean)e.getNewValue()).booleanValue())
118
// try {
119
// PointbasePlus.addOrConnectAccordingToOption();
120
// } catch (Exception exp) {
121
// exp.printStackTrace();
122
// }
123
// }
124
// });
125
// }
126

127     public String JavaDoc getShortDescription() {
128         return NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ND_Root"); //NOI18N
129
}
130 }
131
Popular Tags