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.etl.project.anttasks;
042:
043: import java.io.File;
044: import javax.swing.filechooser.FileFilter;
045: import javax.swing.JFileChooser;
046:
047: public class ChooseLocationDialog extends javax.swing.JDialog {
048:
049: private String objDefn = null;
050: private String dbLocn = null;
051: private String dbName = null;
052:
053: /** Creates new form NewJDialog */
054: public ChooseLocationDialog(java.awt.Frame parent, boolean modal) {
055: super (parent, modal);
056: setLocation(300, 300);
057: initComponents();
058: }
059:
060: /** This method is called from within the constructor to
061: * initialize the form.
062: * WARNING: Do NOT modify this code. The content of this method is
063: * always regenerated by the Form Editor.
064: */
065: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
066: private void initComponents() {
067: java.awt.GridBagConstraints gridBagConstraints;
068:
069: panel = new javax.swing.JPanel();
070: objDefnLabel = new javax.swing.JLabel();
071: dbLocationTextField = new javax.swing.JTextField();
072: dbLocationLabel = new javax.swing.JLabel();
073: dbLocationBtn = new javax.swing.JButton();
074: objDefnTextField = new javax.swing.JTextField();
075: objDefnBtn = new javax.swing.JButton();
076: dbNameTextField = new javax.swing.JTextField();
077: dbLabel = new javax.swing.JLabel();
078: btnPanel = new javax.swing.JPanel();
079: okButton = new javax.swing.JButton();
080: cancelButton = new javax.swing.JButton();
081:
082: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
083: setTitle("Choose DB Location");
084: setModal(true);
085: setResizable(false);
086:
087: panel.setBorder(javax.swing.BorderFactory
088: .createLineBorder(new java.awt.Color(0, 0, 0)));
089: panel.setMaximumSize(new java.awt.Dimension(500, 150));
090: panel.setMinimumSize(new java.awt.Dimension(500, 150));
091: panel.setPreferredSize(new java.awt.Dimension(500, 150));
092: panel.setLayout(new java.awt.GridBagLayout());
093:
094: objDefnLabel.setText("Master Index Object Definition");
095: objDefnLabel
096: .setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
097: objDefnLabel.setMaximumSize(new java.awt.Dimension(150, 25));
098: objDefnLabel.setMinimumSize(new java.awt.Dimension(150, 25));
099: objDefnLabel.setPreferredSize(new java.awt.Dimension(150, 25));
100: gridBagConstraints = new java.awt.GridBagConstraints();
101: gridBagConstraints.gridx = 0;
102: gridBagConstraints.gridy = 0;
103: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
104: panel.add(objDefnLabel, gridBagConstraints);
105:
106: dbLocationTextField.setMaximumSize(new java.awt.Dimension(200,
107: 25));
108: dbLocationTextField.setMinimumSize(new java.awt.Dimension(200,
109: 25));
110: dbLocationTextField.setPreferredSize(new java.awt.Dimension(
111: 200, 25));
112: gridBagConstraints = new java.awt.GridBagConstraints();
113: gridBagConstraints.gridx = 2;
114: gridBagConstraints.gridy = 1;
115: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
116: panel.add(dbLocationTextField, gridBagConstraints);
117:
118: dbLocationLabel.setText("Staging Database Location");
119: dbLocationLabel.setMaximumSize(new java.awt.Dimension(150, 25));
120: dbLocationLabel.setMinimumSize(new java.awt.Dimension(150, 25));
121: dbLocationLabel
122: .setPreferredSize(new java.awt.Dimension(150, 25));
123: gridBagConstraints = new java.awt.GridBagConstraints();
124: gridBagConstraints.gridx = 0;
125: gridBagConstraints.gridy = 1;
126: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
127: panel.add(dbLocationLabel, gridBagConstraints);
128:
129: dbLocationBtn.setText("Browse");
130: dbLocationBtn
131: .addActionListener(new java.awt.event.ActionListener() {
132: public void actionPerformed(
133: java.awt.event.ActionEvent evt) {
134: dbLocationActionPerformed(evt);
135: }
136: });
137: gridBagConstraints = new java.awt.GridBagConstraints();
138: gridBagConstraints.gridx = 4;
139: gridBagConstraints.gridy = 1;
140: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
141: panel.add(dbLocationBtn, gridBagConstraints);
142:
143: objDefnTextField
144: .setMaximumSize(new java.awt.Dimension(200, 25));
145: objDefnTextField
146: .setMinimumSize(new java.awt.Dimension(200, 25));
147: objDefnTextField.setPreferredSize(new java.awt.Dimension(200,
148: 25));
149: gridBagConstraints = new java.awt.GridBagConstraints();
150: gridBagConstraints.gridx = 2;
151: gridBagConstraints.gridy = 0;
152: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
153: panel.add(objDefnTextField, gridBagConstraints);
154:
155: objDefnBtn.setText("Browse");
156: objDefnBtn
157: .addActionListener(new java.awt.event.ActionListener() {
158: public void actionPerformed(
159: java.awt.event.ActionEvent evt) {
160: objDefnActionPerformed(evt);
161: }
162: });
163: gridBagConstraints = new java.awt.GridBagConstraints();
164: gridBagConstraints.gridx = 4;
165: gridBagConstraints.gridy = 0;
166: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
167: panel.add(objDefnBtn, gridBagConstraints);
168:
169: dbNameTextField
170: .setPreferredSize(new java.awt.Dimension(200, 25));
171: gridBagConstraints = new java.awt.GridBagConstraints();
172: gridBagConstraints.gridx = 2;
173: gridBagConstraints.gridy = 2;
174: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
175: panel.add(dbNameTextField, gridBagConstraints);
176:
177: dbLabel.setText("Database Name");
178: dbLabel.setMaximumSize(new java.awt.Dimension(150, 25));
179: dbLabel.setMinimumSize(new java.awt.Dimension(150, 25));
180: dbLabel.setPreferredSize(new java.awt.Dimension(150, 25));
181: gridBagConstraints = new java.awt.GridBagConstraints();
182: gridBagConstraints.gridx = 0;
183: gridBagConstraints.gridy = 2;
184: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
185: panel.add(dbLabel, gridBagConstraints);
186:
187: getContentPane().add(panel, java.awt.BorderLayout.CENTER);
188:
189: okButton.setText("Ok");
190: okButton.setPreferredSize(new java.awt.Dimension(75, 25));
191: okButton.addActionListener(new java.awt.event.ActionListener() {
192: public void actionPerformed(java.awt.event.ActionEvent evt) {
193: okButtonActionPerformed(evt);
194: }
195: });
196: btnPanel.add(okButton);
197:
198: cancelButton.setText("Cancel");
199: cancelButton.setPreferredSize(new java.awt.Dimension(75, 25));
200: cancelButton
201: .addActionListener(new java.awt.event.ActionListener() {
202: public void actionPerformed(
203: java.awt.event.ActionEvent evt) {
204: cancelButtonActionPerformed(evt);
205: }
206: });
207: btnPanel.add(cancelButton);
208:
209: getContentPane().add(btnPanel, java.awt.BorderLayout.SOUTH);
210:
211: pack();
212: }// </editor-fold>//GEN-END:initComponents
213:
214: private void objDefnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_objDefnActionPerformed
215: JFileChooser chooser = new JFileChooser();
216: //chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
217: FileFilter currentFilter = chooser.getFileFilter();
218: chooser.addChoosableFileFilter(new Filter(
219: new String[] { ".xml" }));
220: chooser.setFileFilter(currentFilter);
221: int value = chooser.showOpenDialog(this );
222: if (value == JFileChooser.APPROVE_OPTION) {
223: objDefnTextField.setText(chooser.getSelectedFile()
224: .toString());//getCurrentDirectory().toString());
225: } else {
226: objDefnTextField.setText("");
227: }
228: //setObjectDefinition(chooser.getCurrentDirectory().getAbsolutePath());
229: }//GEN-LAST:event_objDefnActionPerformed
230:
231: private void setObjectDefinition(String str) {
232: this .objDefn = str;
233: }
234:
235: public String getObjectDefinition() {
236: return objDefn;
237: }
238:
239: private void dbLocationActionPerformed(
240: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dbLocationActionPerformed
241: JFileChooser chooser = new JFileChooser();
242: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
243: int value = chooser.showOpenDialog(this );
244: if (value == JFileChooser.APPROVE_OPTION) {
245: dbLocationTextField.setText(chooser.getSelectedFile()
246: .toString());
247: } else {
248: dbLocationTextField.setText("");
249: }
250: //setDBLocation(dbLocationTextField.getText());
251: }//GEN-LAST:event_dbLocationActionPerformed
252:
253: private void setDBLocation(String str) {
254: this .dbLocn = str;
255: }
256:
257: public String getDBLocation() {
258: return dbLocn;
259: }
260:
261: private void setDBName(String str) {
262: this .dbName = str;
263: }
264:
265: public String getDBName() {
266: return dbName;
267: }
268:
269: private void cancelButtonActionPerformed(
270: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
271: this .dispose();
272: System.exit(0);
273: }//GEN-LAST:event_cancelButtonActionPerformed
274:
275: private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
276: setDBLocation(dbLocationTextField.getText());
277: String str = objDefnTextField.getText();
278: if (str.endsWith("object.xml")) {
279: str = str.replace("object.xml", "");
280: } else {
281: System.out.println("Choose object.xml");
282: }
283: setObjectDefinition(str);
284: setDBName(dbNameTextField.getText());
285: this .dispose();
286: }//GEN-LAST:event_okButtonActionPerformed
287:
288: /**
289: * @param args the command line arguments
290: */
291: /*public static void main(String[] args) {
292: java.awt.EventQueue.invokeLater(new Runnable() {
293:
294: public void run() {
295: ChooseLocationDialog dialog = new ChooseLocationDialog(new javax.swing.JFrame(), true);
296: dialog.addWindowListener(new java.awt.event.WindowAdapter() {
297:
298: @Override
299: public void windowClosing(java.awt.event.WindowEvent e) {
300: System.exit(0);
301: }
302: });
303: dialog.setVisible(true);
304: }
305: });
306: }*/
307: class Filter extends javax.swing.filechooser.FileFilter {
308: private String[] extensions;
309:
310: public Filter(String[] extensions) {
311: this .extensions = new String[extensions.length];
312: for (int i = 0; i < extensions.length; i++) {
313: this .extensions[i] = extensions[i].toUpperCase();
314: }
315: }
316:
317: @Override
318: public boolean accept(File file) {
319: //String filename = file.getName();
320: //return filename.endsWith(".xml");
321: if (file.isDirectory()) {
322: return true;
323: }
324: for (int i = 0; i < extensions.length; i++) {
325: if (file.getName().toUpperCase()
326: .endsWith(extensions[i])) {
327: return true;
328: }
329: }
330:
331: return false;
332: }
333:
334: public String getDescription() {
335: return "*.xml";
336: }
337:
338: }
339:
340: // Variables declaration - do not modify//GEN-BEGIN:variables
341: private javax.swing.JPanel btnPanel;
342: private javax.swing.JButton cancelButton;
343: private javax.swing.JLabel dbLabel;
344: private javax.swing.JButton dbLocationBtn;
345: private javax.swing.JLabel dbLocationLabel;
346: private javax.swing.JTextField dbLocationTextField;
347: private javax.swing.JTextField dbNameTextField;
348: private javax.swing.JButton objDefnBtn;
349: private javax.swing.JLabel objDefnLabel;
350: private javax.swing.JTextField objDefnTextField;
351: private javax.swing.JButton okButton;
352: private javax.swing.JPanel panel;
353: // End of variables declaration//GEN-END:variables
354: }
|