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-2007 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: package org.netbeans.modules.mashup.db.ui.wizard;
042:
043: import java.awt.event.ActionEvent;
044: import java.awt.event.ActionListener;
045: import java.util.ArrayList;
046: import java.util.HashSet;
047: import java.util.List;
048: import java.util.Set;
049: import javax.swing.JComboBox;
050:
051: import net.java.hulp.i18n.Logger;
052: import org.netbeans.api.db.explorer.ConnectionManager;
053: import org.netbeans.api.db.explorer.DatabaseConnection;
054: import org.netbeans.modules.etl.logger.Localizer;
055: import org.netbeans.modules.etl.logger.LogUtil;
056: import org.netbeans.modules.etl.ui.ETLEditorSupport;
057: import org.netbeans.modules.mashup.tables.wizard.MashupTableWizardIterator;
058: import org.netbeans.modules.sql.framework.common.utils.DBExplorerUtil;
059: import org.netbeans.modules.sql.framework.common.utils.DBURL;
060:
061: /**
062: * Visual panel which displays the available mashup databases.
063: *
064: * @author Karthik S
065: * @author Ahimanikya Satapathy
066: */
067: public class SelectDatabaseVisualPanel extends javax.swing.JPanel {
068: private static transient final Logger mLogger = LogUtil
069: .getLogger(SelectDatabaseVisualPanel.class.getName());
070: private static transient final Localizer mLoc = Localizer.get();
071: private boolean populated;
072: private SelectDatabasePanel owner;
073: private String selectedDB;
074: Set<String> urls = new HashSet<String>();
075:
076: /** Creates new form SelectDatabaseVisualPanel */
077: public SelectDatabaseVisualPanel() {
078: initComponents();
079: databasesCombo.removeAllItems();
080: populateDBList();
081: }
082:
083: public SelectDatabaseVisualPanel(SelectDatabasePanel panel) {
084: this ();
085: this .owner = panel;
086: databasesCombo.addActionListener(new ActionListener() {
087:
088: public void actionPerformed(ActionEvent e) {
089: JComboBox combo = (JComboBox) e.getSource();
090: DBURL selectedUrl = (DBURL) combo.getSelectedItem();
091: selectedDB = selectedUrl.getURL();
092: dbPathTextField.setText(selectedUrl.getWorkDir());
093: if (selectedDB != null) {
094: SelectDatabaseVisualPanel.this .owner
095: .fireChangeEvent();
096: }
097: }
098: });
099: if (databasesCombo.getItemCount() != 0) {
100: databasesCombo.setSelectedIndex(0);
101: }
102: }
103:
104: String nbBundle1 = mLoc.t("PRSR001: Choose Mashup Database");
105:
106: @Override
107: public String getName() {
108: return Localizer.parse(nbBundle1);
109: }
110:
111: public String getSelectedDatabase() {
112: return selectedDB;
113: }
114:
115: private void populateDBList() {
116: List<DatabaseConnection> models = new ArrayList<DatabaseConnection>();
117: DBExplorerUtil.recreateMissingFlatfileConnectionInDBExplorer();
118: if (MashupTableWizardIterator.IS_PROJECT_CALL) {
119: models.addAll(DBExplorerUtil
120: .getDatabasesForCurrentProject());
121: }
122:
123: // Here we either display project level data base or top level
124: if (!MashupTableWizardIterator.IS_PROJECT_CALL) {
125: DatabaseConnection[] dbconns = ConnectionManager
126: .getDefault().getConnections();
127: for (int i = 0; i < dbconns.length; i++) {
128: if (dbconns[i].getDriverClass().equals(
129: DBExplorerUtil.AXION_DRIVER)) {
130: models.add(dbconns[i]);
131: }
132: }
133: }
134:
135: for (DatabaseConnection model : models) {
136: if (MashupTableWizardIterator.IS_PROJECT_CALL) {
137: String url = model.getDatabaseURL();
138: if (url.contains(ETLEditorSupport.PRJ_NAME.trim())) {
139: databasesCombo.addItem(new DBURL(url, true));
140: }
141: } else {
142: databasesCombo.addItem(new DBURL(
143: model.getDatabaseURL(), false));
144: }
145: }
146:
147: MashupTableWizardIterator.IS_PROJECT_CALL = false;
148: if (databasesCombo.getItemCount() != 0) {
149: this .populated = true;
150: } else {
151: String nbBundle2 = mLoc
152: .t("PRSR001: No Mashup Database found.");
153: error.setText(Localizer.parse(nbBundle2));
154: this .populated = false;
155: }
156: }
157:
158: public boolean isPopulated() {
159: return this .populated;
160: }
161:
162: /** This method is called from within the constructor to
163: * initialize the form.
164: * WARNING: Do NOT modify this code. The content of this method is
165: * always regenerated by the Form Editor.
166: */
167: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
168: private void initComponents() {
169:
170: buttonGroup1 = new javax.swing.ButtonGroup();
171: jPanel1 = new javax.swing.JPanel();
172: databasesCombo = new javax.swing.JComboBox();
173: dbPathTextField = new javax.swing.JTextField();
174: error = new javax.swing.JLabel();
175:
176: setMaximumSize(new java.awt.Dimension(500, 200));
177: setMinimumSize(new java.awt.Dimension(50, 50));
178: setPreferredSize(new java.awt.Dimension(390, 160));
179:
180: jPanel1.setBorder(javax.swing.BorderFactory
181: .createTitledBorder("Available Databases"));
182:
183: databasesCombo.setToolTipText("Available Databases");
184: databasesCombo.setAutoscrolls(true);
185: databasesCombo
186: .addActionListener(new java.awt.event.ActionListener() {
187: public void actionPerformed(
188: java.awt.event.ActionEvent evt) {
189: databasesComboActionPerformed(evt);
190: }
191: });
192:
193: dbPathTextField.setEnabled(false);
194:
195: error.setForeground(new java.awt.Color(255, 0, 0));
196:
197: org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
198: jPanel1);
199: jPanel1.setLayout(jPanel1Layout);
200: jPanel1Layout
201: .setHorizontalGroup(jPanel1Layout
202: .createParallelGroup(
203: org.jdesktop.layout.GroupLayout.LEADING)
204: .add(
205: jPanel1Layout
206: .createSequentialGroup()
207: .add(
208: jPanel1Layout
209: .createParallelGroup(
210: org.jdesktop.layout.GroupLayout.LEADING)
211: .add(
212: jPanel1Layout
213: .createParallelGroup(
214: org.jdesktop.layout.GroupLayout.TRAILING,
215: false)
216: .add(
217: org.jdesktop.layout.GroupLayout.LEADING,
218: databasesCombo,
219: 0,
220: 347,
221: Short.MAX_VALUE)
222: .add(
223: org.jdesktop.layout.GroupLayout.LEADING,
224: dbPathTextField))
225: .add(
226: jPanel1Layout
227: .createSequentialGroup()
228: .add(
229: 122,
230: 122,
231: 122)
232: .add(
233: error)))
234: .addContainerGap(
235: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
236: Short.MAX_VALUE)));
237: jPanel1Layout
238: .setVerticalGroup(jPanel1Layout
239: .createParallelGroup(
240: org.jdesktop.layout.GroupLayout.LEADING)
241: .add(
242: jPanel1Layout
243: .createSequentialGroup()
244: .addContainerGap()
245: .add(
246: databasesCombo,
247: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
248: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
249: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
250: .addPreferredGap(
251: org.jdesktop.layout.LayoutStyle.RELATED)
252: .add(
253: dbPathTextField,
254: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
255: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
256: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
257: .addPreferredGap(
258: org.jdesktop.layout.LayoutStyle.RELATED,
259: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
260: Short.MAX_VALUE)
261: .add(
262: error,
263: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
264: 12,
265: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
266: .addContainerGap()));
267:
268: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
269: this );
270: this .setLayout(layout);
271: layout.setHorizontalGroup(layout.createParallelGroup(
272: org.jdesktop.layout.GroupLayout.LEADING).add(
273: layout.createSequentialGroup().addContainerGap().add(
274: jPanel1,
275: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
276: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
277: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
278: .addContainerGap(101, Short.MAX_VALUE)));
279: layout.setVerticalGroup(layout.createParallelGroup(
280: org.jdesktop.layout.GroupLayout.LEADING).add(
281: layout.createSequentialGroup().addContainerGap().add(
282: jPanel1,
283: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
284: 109,
285: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
286: .addContainerGap(40, Short.MAX_VALUE)));
287: }// </editor-fold>//GEN-END:initComponents
288:
289: private void databasesComboActionPerformed(
290: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_databasesComboActionPerformed
291: // TODO add your handling code here:
292:
293: }//GEN-LAST:event_databasesComboActionPerformed
294:
295: // Variables declaration - do not modify//GEN-BEGIN:variables
296: private javax.swing.ButtonGroup buttonGroup1;
297: private javax.swing.JComboBox databasesCombo;
298: private javax.swing.JTextField dbPathTextField;
299: private javax.swing.JLabel error;
300: private javax.swing.JPanel jPanel1;
301: // End of variables declaration//GEN-END:variables
302: }
|