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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.ruby.railsprojects.ui.wizards;
041:
042: import org.netbeans.api.db.explorer.ConnectionManager;
043: import org.netbeans.api.db.explorer.DatabaseConnection;
044: import org.netbeans.api.db.explorer.support.DatabaseExplorerUIs;
045: import org.netbeans.api.ruby.platform.RubyPlatform;
046: import org.netbeans.modules.ruby.railsprojects.database.RailsDatabaseConfiguration;
047: import org.netbeans.modules.ruby.railsprojects.database.RailsJdbcAsAdapterConnection;
048: import org.netbeans.modules.ruby.railsprojects.database.RailsJdbcConnection;
049: import org.openide.WizardDescriptor;
050: import org.openide.WizardValidationException;
051:
052: /**
053: * A panel for JDBC connections.
054: *
055: * @author Erno Mononen
056: */
057: public class JdbcConnectionsPanel extends SettingsPanel {
058:
059: /** Creates new form JdbcConnectionsPanel */
060: public JdbcConnectionsPanel() {
061: initComponents();
062: ConnectionManager connectionManager = ConnectionManager
063: .getDefault();
064: DatabaseExplorerUIs.connect(developmentComboBox,
065: connectionManager);
066: DatabaseExplorerUIs.connect(productionComboBox,
067: connectionManager);
068: DatabaseExplorerUIs.connect(testComboBox, connectionManager);
069: }
070:
071: /** This method is called from within the constructor to
072: * initialize the form.
073: * WARNING: Do NOT modify this code. The content of this method is
074: * always regenerated by the Form Editor.
075: */
076: @SuppressWarnings("unchecked")
077: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
078: private void initComponents() {
079:
080: developmentLabel = new javax.swing.JLabel();
081: productionLabel = new javax.swing.JLabel();
082: testLabel = new javax.swing.JLabel();
083: developmentComboBox = new javax.swing.JComboBox();
084: productionComboBox = new javax.swing.JComboBox();
085: testComboBox = new javax.swing.JComboBox();
086:
087: developmentLabel.setLabelFor(developmentComboBox);
088: org.openide.awt.Mnemonics.setLocalizedText(developmentLabel,
089: org.openide.util.NbBundle.getMessage(
090: JdbcConnectionsPanel.class,
091: "LBL_DevelopmentConnection")); // NOI18N
092:
093: productionLabel.setLabelFor(productionComboBox);
094: org.openide.awt.Mnemonics.setLocalizedText(productionLabel,
095: org.openide.util.NbBundle.getMessage(
096: JdbcConnectionsPanel.class,
097: "LBL_ProductionConnection")); // NOI18N
098:
099: testLabel.setLabelFor(testComboBox);
100: org.openide.awt.Mnemonics.setLocalizedText(testLabel,
101: org.openide.util.NbBundle.getMessage(
102: JdbcConnectionsPanel.class,
103: "LBL_TestConnection")); // NOI18N
104:
105: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
106: this );
107: this .setLayout(layout);
108: layout
109: .setHorizontalGroup(layout
110: .createParallelGroup(
111: org.jdesktop.layout.GroupLayout.LEADING)
112: .add(
113: layout
114: .createSequentialGroup()
115: .addContainerGap()
116: .add(
117: layout
118: .createParallelGroup(
119: org.jdesktop.layout.GroupLayout.LEADING)
120: .add(testLabel)
121: .add(
122: productionLabel)
123: .add(
124: developmentLabel))
125: .addPreferredGap(
126: org.jdesktop.layout.LayoutStyle.RELATED)
127: .add(
128: layout
129: .createParallelGroup(
130: org.jdesktop.layout.GroupLayout.LEADING)
131: .add(
132: productionComboBox,
133: 0,
134: 384,
135: Short.MAX_VALUE)
136: .add(
137: testComboBox,
138: 0,
139: 384,
140: Short.MAX_VALUE)
141: .add(
142: developmentComboBox,
143: 0,
144: 384,
145: Short.MAX_VALUE))
146: .addContainerGap()));
147: layout
148: .setVerticalGroup(layout
149: .createParallelGroup(
150: org.jdesktop.layout.GroupLayout.LEADING)
151: .add(
152: layout
153: .createSequentialGroup()
154: .addContainerGap()
155: .add(
156: layout
157: .createParallelGroup(
158: org.jdesktop.layout.GroupLayout.BASELINE)
159: .add(
160: developmentComboBox,
161: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
162: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
163: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
164: .add(
165: developmentLabel))
166: .addPreferredGap(
167: org.jdesktop.layout.LayoutStyle.RELATED)
168: .add(
169: layout
170: .createParallelGroup(
171: org.jdesktop.layout.GroupLayout.BASELINE)
172: .add(testLabel)
173: .add(
174: testComboBox,
175: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
176: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
177: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
178: .addPreferredGap(
179: org.jdesktop.layout.LayoutStyle.RELATED)
180: .add(
181: layout
182: .createParallelGroup(
183: org.jdesktop.layout.GroupLayout.BASELINE)
184: .add(
185: productionLabel)
186: .add(
187: productionComboBox,
188: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
189: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
190: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
191: .addContainerGap(
192: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
193: Short.MAX_VALUE)));
194:
195: developmentLabel.getAccessibleContext()
196: .setAccessibleDescription(
197: org.openide.util.NbBundle.getMessage(
198: JdbcConnectionsPanel.class,
199: "ACSD_DevelopmentConnection")); // NOI18N
200: productionLabel.getAccessibleContext()
201: .setAccessibleDescription(
202: org.openide.util.NbBundle.getMessage(
203: JdbcConnectionsPanel.class,
204: "ACSD_ProductionConnection")); // NOI18N
205: testLabel.getAccessibleContext().setAccessibleDescription(
206: org.openide.util.NbBundle.getMessage(
207: JdbcConnectionsPanel.class,
208: "ACSD_TestConnection")); // NOI18N
209:
210: getAccessibleContext().setAccessibleName(
211: org.openide.util.NbBundle.getMessage(
212: JdbcConnectionsPanel.class, "ASCN_JdbcPanel")); // NOI18N
213: getAccessibleContext().setAccessibleDescription(
214: org.openide.util.NbBundle.getMessage(
215: JdbcConnectionsPanel.class, "ASCD_JdbcPanel")); // NOI18N
216: getAccessibleContext().setAccessibleParent(this );
217: }// </editor-fold>//GEN-END:initComponents
218:
219: // Variables declaration - do not modify//GEN-BEGIN:variables
220: private javax.swing.JComboBox developmentComboBox;
221: private javax.swing.JLabel developmentLabel;
222: private javax.swing.JComboBox productionComboBox;
223: private javax.swing.JLabel productionLabel;
224: private javax.swing.JComboBox testComboBox;
225: private javax.swing.JLabel testLabel;
226:
227: // End of variables declaration//GEN-END:variables
228:
229: @Override
230: void store(WizardDescriptor settings) {
231: DatabaseConnection devel = (DatabaseConnection) developmentComboBox
232: .getSelectedItem();
233: DatabaseConnection production = (DatabaseConnection) productionComboBox
234: .getSelectedItem();
235: DatabaseConnection test = (DatabaseConnection) testComboBox
236: .getSelectedItem();
237: RailsDatabaseConfiguration databaseConfiguration = null;
238: Boolean jdbc = (Boolean) settings
239: .getProperty(NewRailsProjectWizardIterator.JDBC_WN);
240: if (jdbc != null && jdbc.booleanValue()) {
241: databaseConfiguration = new RailsJdbcConnection(devel,
242: test, production);
243: } else {
244: databaseConfiguration = new RailsJdbcAsAdapterConnection(
245: devel, test, production);
246: }
247: settings.putProperty(
248: NewRailsProjectWizardIterator.RAILS_DEVELOPMENT_DB,
249: databaseConfiguration);
250: }
251:
252: @Override
253: void read(WizardDescriptor settings) {
254: }
255:
256: @Override
257: boolean valid(WizardDescriptor settings) {
258: return true;
259: }
260:
261: @Override
262: void validate(WizardDescriptor settings)
263: throws WizardValidationException {
264: }
265:
266: }
|