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.db.explorer.nodes;
043:
044: import java.beans.PropertyChangeEvent;
045: import java.beans.PropertyChangeListener;
046:
047: import org.openide.options.SystemOption;
048: import org.openide.util.NbBundle;
049:
050: import org.netbeans.lib.ddl.impl.SpecificationFactory;
051: import org.netbeans.modules.db.explorer.DatabaseOption;
052:
053: //commented out for 3.6 release, need to solve for next Studio release
054: //import org.netbeans.modules.db.explorer.PointbasePlus;
055:
056: import org.netbeans.modules.db.explorer.infos.DatabaseNodeInfo;
057: import org.netbeans.modules.db.explorer.infos.RootNodeInfo;
058:
059: /** Abstract class that can be used as super class of all data objects that
060: * should contain some nodes. It provides methods for adding/removing
061: * sub nodes.
062: */
063: public class RootNode extends DatabaseNode {
064: /** Stores DBNode's connections info */
065: private static DatabaseOption option = null;
066: private static RootNode rootNode = null;
067:
068: /** DDLFactory */
069: SpecificationFactory sfactory;
070:
071: public static DatabaseOption getOption() {
072: if (option == null)
073: option = (DatabaseOption) SystemOption.findObject(
074: DatabaseOption.class, true);
075:
076: return option;
077: }
078:
079: public static RootNode getInstance() {
080: if (rootNode == null) {
081: rootNode = new RootNode();
082: }
083: return rootNode;
084: }
085:
086: private RootNode() {
087: setDisplayName(NbBundle.getBundle(
088: "org.netbeans.modules.db.resources.Bundle").getString(
089: "NDN_Databases")); //NOI18N
090: try {
091: sfactory = new SpecificationFactory();
092: //initialization listener for debug mode
093: initDebugListening();
094:
095: //commented out for 3.6 release, need to solve for next Studio release
096: //initialization listener for SAMPLE database option
097: // initSampleDatabaseListening();
098:
099: DatabaseNodeInfo nfo = RootNodeInfo.getInstance();
100: if (sfactory != null)
101: nfo.setSpecificationFactory(sfactory);
102: else
103: throw new Exception(NbBundle.getBundle(
104: "org.netbeans.modules.db.resources.Bundle")
105: .getString("EXC_NoSpecificationFactory"));
106:
107: setInfo(nfo);
108: getInfo().setNode(this );
109: } catch (Exception e) {
110: e.printStackTrace();
111: }
112: }
113:
114: public boolean canRename() {
115: return false;
116: }
117:
118: /**
119: * Connects the debug property in sfactory and debugMode property in DBExplorer module's option.
120: */
121: void initDebugListening() {
122: if ((getOption() == null) || (sfactory == null)) {
123: initDebugListening();
124: }
125: option.addPropertyChangeListener(new PropertyChangeListener() {
126: public void propertyChange(PropertyChangeEvent e) {
127: if (e.getPropertyName() == null) {
128: sfactory.setDebugMode(option.getDebugMode());
129: return;
130: }
131: if (e.getPropertyName().equals(
132: DatabaseOption.PROP_DEBUG_MODE))
133: sfactory.setDebugMode(((Boolean) e.getNewValue())
134: .booleanValue());
135: }
136: });
137: sfactory.setDebugMode(option.getDebugMode());
138: }
139:
140: //commented out for 3.6 release, need to solve for next Studio release
141: // void initSampleDatabaseListening() {
142: // if ( (getOption() == null) || (sfactory == null) ) {
143: // initSampleDatabaseListening();
144: // }
145: // option.addPropertyChangeListener(new PropertyChangeListener() {
146: // public void propertyChange(PropertyChangeEvent e) {
147: // if (e.getPropertyName() != null && e.getPropertyName().equals(DatabaseOption.PROP_AUTO_CONNECTION))
148: // if(((Boolean)e.getNewValue()).booleanValue())
149: // try {
150: // PointbasePlus.addOrConnectAccordingToOption();
151: // } catch (Exception exp) {
152: // exp.printStackTrace();
153: // }
154: // }
155: // });
156: // }
157:
158: public String getShortDescription() {
159: return NbBundle.getBundle(
160: "org.netbeans.modules.db.resources.Bundle").getString(
161: "ND_Root"); //NOI18N
162: }
163: }
|