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: /*
042: * ExportDataSourcesDialog.java
043: *
044: * Created on March 8, 2004, 12:09 PM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.ui;
048:
049: import java.awt.BorderLayout;
050: import java.io.File;
051: import javax.swing.*;
052: import javax.swing.event.DocumentEvent;
053: import javax.swing.event.DocumentListener;
054: import org.openide.DialogDisplayer;
055: import org.openide.NotifyDescriptor;
056: import org.openide.util.NbBundle;
057: import org.openide.util.RequestProcessor;
058:
059: /**
060: * A panle to allow the user to export EJB datasources to a jar file
061: *
062: * @author dongmei cao
063: */
064: public class ImportEjbDataSourcesPanel extends JPanel {
065:
066: private EjbDataSourcesSelectionPanel ejbDataSourceSelectionPanel;
067: private EjbDataSourcePropertiesPanel propsPanel;
068: private PortableEjbDataSource[] ejbDataSources;
069: private boolean textFieldChanged = false;
070:
071: public ImportEjbDataSourcesPanel() {
072: initComponents();
073:
074: propsPanel = new EjbDataSourcePropertiesPanel();
075: ejbDataSourceSelectionPanel = new EjbDataSourcesSelectionPanel(
076: propsPanel);
077:
078: selectionPanel.add(ejbDataSourceSelectionPanel,
079: BorderLayout.CENTER);
080: propertiesPanel.add(propsPanel, BorderLayout.CENTER);
081:
082: fileNameTextField.getDocument().addDocumentListener(
083: new DocumentListener() {
084:
085: public void insertUpdate(DocumentEvent e) {
086: textFieldChanged = true;
087: }
088:
089: public void removeUpdate(DocumentEvent e) {
090: textFieldChanged = true;
091: }
092:
093: public void changedUpdate(DocumentEvent e) {
094: textFieldChanged = true;
095: }
096: });
097:
098: }
099:
100: public ImportEjbDataSourcesPanel(
101: PortableEjbDataSource[] ejbDataSources) {
102: this ();
103: }
104:
105: public void setImportFilePath(String filePath) {
106: fileNameTextField.setText(filePath);
107: }
108:
109: public String getImportFilePath() {
110: return fileNameTextField.getText().trim();
111: }
112:
113: public void setEjbDataSources(PortableEjbDataSource[] ejbDataSources) {
114: this .ejbDataSources = ejbDataSources;
115: ejbDataSourceSelectionPanel.setEjbDataSources(ejbDataSources);
116: }
117:
118: public PortableEjbDataSource[] getEjbDataSources() {
119: return this .ejbDataSources;
120: }
121:
122: public boolean saveChange() {
123: return propsPanel.saveChange();
124: }
125:
126: /** This method is called from within the constructor to
127: * initialize the form.
128: * WARNING: Do NOT modify this code. The content of this method is
129: * always regenerated by the Form Editor.
130: */
131: private void initComponents() {//GEN-BEGIN:initComponents
132: java.awt.GridBagConstraints gridBagConstraints;
133:
134: title = new javax.swing.JLabel();
135: selectionPanel = new javax.swing.JPanel();
136: filePanel = new javax.swing.JPanel();
137: fileNameLabel = new javax.swing.JLabel();
138: fileNameTextField = new javax.swing.JTextField();
139: browseButton = new javax.swing.JButton();
140: propertiesPanel = new javax.swing.JPanel();
141:
142: setLayout(new java.awt.GridBagLayout());
143:
144: getAccessibleContext().setAccessibleName(
145: org.openide.util.NbBundle.getMessage(
146: ImportEjbDataSourcesPanel.class,
147: "IMPORT_EJB_DATASOURCES"));
148: getAccessibleContext().setAccessibleDescription(
149: org.openide.util.NbBundle.getMessage(
150: ImportEjbDataSourcesPanel.class,
151: "IMPORT_EJB_DATASOURCES"));
152: title.setLabelFor(selectionPanel);
153: title.setText(java.util.ResourceBundle.getBundle(
154: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
155: .getString("IMPORT_EJB_DATASOURCES_LABEL"));
156: gridBagConstraints = new java.awt.GridBagConstraints();
157: gridBagConstraints.gridx = 0;
158: gridBagConstraints.gridy = 2;
159: gridBagConstraints.gridwidth = 3;
160: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
161: gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
162: add(title, gridBagConstraints);
163: title.getAccessibleContext().setAccessibleName(
164: java.util.ResourceBundle.getBundle(
165: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
166: .getString("IMPORT_EJB_DATASOURCES_LABEL"));
167: title.getAccessibleContext().setAccessibleDescription(
168: java.util.ResourceBundle.getBundle(
169: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
170: .getString("IMPORT_EJB_DATASOURCES"));
171:
172: selectionPanel.setLayout(new java.awt.BorderLayout());
173:
174: selectionPanel.setBorder(new javax.swing.border.EmptyBorder(
175: new java.awt.Insets(5, 10, 10, 10)));
176: selectionPanel.setVerifyInputWhenFocusTarget(false);
177: gridBagConstraints = new java.awt.GridBagConstraints();
178: gridBagConstraints.gridx = 0;
179: gridBagConstraints.gridy = 4;
180: gridBagConstraints.gridwidth = 2;
181: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
182: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
183: gridBagConstraints.weightx = 0.5;
184: gridBagConstraints.weighty = 1.0;
185: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
186: add(selectionPanel, gridBagConstraints);
187:
188: filePanel.setLayout(new java.awt.BorderLayout(5, 1));
189:
190: filePanel.setBorder(new javax.swing.border.EmptyBorder(
191: new java.awt.Insets(5, 10, 10, 10)));
192: fileNameLabel.setDisplayedMnemonic(org.openide.util.NbBundle
193: .getMessage(ImportEjbDataSourcesPanel.class,
194: "FILE_NAME_MNEMONIC").charAt(0));
195: fileNameLabel.setLabelFor(fileNameTextField);
196: fileNameLabel.setText(java.util.ResourceBundle.getBundle(
197: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
198: .getString("FILE_NAME"));
199: filePanel.add(fileNameLabel, java.awt.BorderLayout.WEST);
200: fileNameLabel.getAccessibleContext().setAccessibleDescription(
201: java.util.ResourceBundle.getBundle(
202: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
203: .getString("IMPORT_FILE_NAME_DESC"));
204:
205: fileNameTextField
206: .addActionListener(new java.awt.event.ActionListener() {
207: public void actionPerformed(
208: java.awt.event.ActionEvent evt) {
209: fileNameTextFieldActionPerformed(evt);
210: }
211: });
212:
213: filePanel.add(fileNameTextField, java.awt.BorderLayout.CENTER);
214: fileNameTextField
215: .getAccessibleContext()
216: .setAccessibleDescription(
217: java.util.ResourceBundle
218: .getBundle(
219: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
220: .getString("IMPORT_FILE_NAME_DESC"));
221:
222: browseButton.setMnemonic(java.util.ResourceBundle.getBundle(
223: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
224: .getString("BROWSE_IMPORT_FILE_BUTTON_MNEMONIC")
225: .charAt(0));
226: browseButton.setText(java.util.ResourceBundle.getBundle(
227: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
228: .getString("BROWSE_IMPORT_FILE_BUTTON_LABEL"));
229: browseButton
230: .addActionListener(new java.awt.event.ActionListener() {
231: public void actionPerformed(
232: java.awt.event.ActionEvent evt) {
233: browseButtonActionPerformed(evt);
234: }
235: });
236:
237: filePanel.add(browseButton, java.awt.BorderLayout.EAST);
238: browseButton.getAccessibleContext().setAccessibleDescription(
239: java.util.ResourceBundle.getBundle(
240: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
241: .getString("BROWSE_IMPORT_FILE_BUTTON_DESC"));
242:
243: gridBagConstraints = new java.awt.GridBagConstraints();
244: gridBagConstraints.gridx = 0;
245: gridBagConstraints.gridy = 0;
246: gridBagConstraints.gridwidth = 3;
247: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
248: gridBagConstraints.insets = new java.awt.Insets(17, 0, 0, 0);
249: add(filePanel, gridBagConstraints);
250:
251: propertiesPanel.setLayout(new java.awt.BorderLayout());
252:
253: gridBagConstraints = new java.awt.GridBagConstraints();
254: gridBagConstraints.gridx = 2;
255: gridBagConstraints.gridy = 4;
256: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
257: gridBagConstraints.weightx = 1.0;
258: gridBagConstraints.weighty = 1.0;
259: gridBagConstraints.insets = new java.awt.Insets(12, 17, 0, 12);
260: add(propertiesPanel, gridBagConstraints);
261:
262: }//GEN-END:initComponents
263:
264: private void fileNameTextFieldActionPerformed(
265: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileNameTextFieldActionPerformed
266: if (!(new File(getImportFilePath())).exists()) {
267: String msg = NbBundle.getMessage(
268: ImportEjbDataSourcesPanel.class,
269: "IMPORT_FILE_NOT_FOUND", getImportFilePath());
270: NotifyDescriptor d = new NotifyDescriptor.Message(msg,
271: NotifyDescriptor.ERROR_MESSAGE);
272: DialogDisplayer.getDefault().notify(d);
273: return;
274: } else {
275: if (!textFieldChanged) {
276: return;
277: }
278:
279: textFieldChanged = false;
280: // This file will be the default file the file chooser
281: ImportExportFileChooser
282: .setCurrentFilePath(getImportFilePath());
283:
284: // start a new thread to read in the data
285: RequestProcessor.getDefault().post(new Runnable() {
286: public void run() {
287: PortableEjbDataSource[] ejbDataSources = ImportEjbDataSourcesHelper
288: .readDataSourceImports(getImportFilePath());
289: if (ejbDataSources != null)
290: setEjbDataSources(ejbDataSources);
291: else
292: return;
293: }
294: });
295: }
296: }//GEN-LAST:event_fileNameTextFieldActionPerformed
297:
298: private void browseButtonActionPerformed(
299: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
300:
301: // Chooser a file to import from
302:
303: ImportExportFileChooser fileChooser = new ImportExportFileChooser(
304: this );
305: String selectedFile = fileChooser.getImportFile();
306:
307: if (selectedFile != null) {
308: if (!(new File(selectedFile)).exists()) {
309: String msg = NbBundle.getMessage(
310: ImportEjbDataSourcesPanel.class,
311: "IMPORT_FILE_NOT_FOUND", selectedFile);
312: NotifyDescriptor d = new NotifyDescriptor.Message(msg,
313: NotifyDescriptor.ERROR_MESSAGE);
314: DialogDisplayer.getDefault().notify(d);
315: return;
316: }
317:
318: fileChooser.setCurrentFilePath(selectedFile);
319: fileNameTextField.setText(selectedFile);
320:
321: // No need to check file existence here because it is done in the file chooser
322:
323: // start a new thread to read in the data
324: RequestProcessor.getDefault().post(new Runnable() {
325: public void run() {
326: PortableEjbDataSource[] ejbDataSources = ImportEjbDataSourcesHelper
327: .readDataSourceImports(getImportFilePath());
328: if (ejbDataSources != null)
329: setEjbDataSources(ejbDataSources);
330: else
331: return;
332: }
333: });
334: }
335: }//GEN-LAST:event_browseButtonActionPerformed
336:
337: // Variables declaration - do not modify//GEN-BEGIN:variables
338: private javax.swing.JButton browseButton;
339: private javax.swing.JLabel fileNameLabel;
340: private javax.swing.JTextField fileNameTextField;
341: private javax.swing.JPanel filePanel;
342: private javax.swing.JPanel propertiesPanel;
343: private javax.swing.JPanel selectionPanel;
344: private javax.swing.JLabel title;
345: // End of variables declaration//GEN-END:variables
346:
347: }
|