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.jellytools.modules.db.nodes;
043:
044: import javax.swing.tree.TreePath;
045: import org.netbeans.jellytools.Bundle;
046: import org.netbeans.jellytools.RuntimeTabOperator;
047: import org.netbeans.jellytools.actions.Action;
048: import org.netbeans.jellytools.actions.DeleteAction;
049: import org.netbeans.jellytools.actions.PropertiesAction;
050: import org.netbeans.jellytools.modules.db.actions.ConnectAction;
051: import org.netbeans.jellytools.modules.db.actions.DisconnectAction;
052: import org.netbeans.jellytools.modules.db.actions.ExecuteCommandAction;
053: import org.netbeans.jellytools.nodes.Node;
054: import org.netbeans.jemmy.operators.JTreeOperator;
055:
056: /** Node representing "Databases > ${connection}" node in Runtime tab.
057: * <p>
058: * Usage:<br>
059: * <pre>
060: * ConnectionNode conn = DriversNode.invoke("jdbc:derby:/mydb", "tester", "APP");
061: * conn.connect();
062: * conn.executeCommand();
063: * ....
064: * conn.disconnect();
065: * </pre>
066: *
067: * @author Martin.Schovanek@sun.com
068: */
069: public class ConnectionNode extends Node {
070: private static final Action connectAction = new ConnectAction();
071: private static final Action disconnectAction = new DisconnectAction();
072: private static final Action executeCommandAction = new ExecuteCommandAction();
073: private static final Action deleteAction = new DeleteAction();
074: private static final Action propertiesAction = new PropertiesAction();
075:
076: /** creates new ConnectionNode
077: * @param url database URL
078: * @param user user name
079: * @param schema schema name */
080: public ConnectionNode(String url, String user, String schema) {
081: super (new RuntimeTabOperator().getRootNode(),
082: DatabasesNode.TREE_PATH + "|"
083: + connectionName(url, user, schema));
084: }
085:
086: /** Finds "Databases > ${connection}" node
087: * @param url database URL
088: * @param user user name
089: * @param schema schema name */
090: public static ConnectionNode invoke(String url, String user,
091: String schema) {
092: RuntimeTabOperator.invoke();
093: return new ConnectionNode(url, user, schema);
094: }
095:
096: /** performs ConnectAction with this node */
097: public void connect() {
098: connectAction.perform(this );
099: }
100:
101: /** performs DisconnectAction with this node */
102: public void disconnect() {
103: disconnectAction.perform(this );
104: }
105:
106: /** performs ExecuteCommandAction with this node */
107: public void executeCommand() {
108: executeCommandAction.perform(this );
109: }
110:
111: /** performs DeleteAction with this node */
112: public void delete() {
113: deleteAction.perform(this );
114: }
115:
116: /** performs PropertiesAction with this node */
117: public void properties() {
118: propertiesAction.perform(this );
119: }
120:
121: /** tests popup menu items for presence */
122: void verifyPopup() {
123: verifyPopup(new Action[] { connectAction, disconnectAction,
124: executeCommandAction, deleteAction, propertiesAction });
125: }
126:
127: private static String connectionName(String url, String user,
128: String schema) {
129: if (schema == null) {
130: schema = Bundle.getStringTrimmed(
131: "org.netbeans.modules.db.resources.Bundle",
132: "SchemaIsNotSet");
133: }
134: return Bundle.getStringTrimmed(
135: "org.netbeans.modules.db.resources.Bundle",
136: "ConnectionNodeUniqueName", new Object[] { url, user,
137: schema });
138: }
139:
140: }
|