|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.web.project.ui.wizards; import java.io.File; import javax.swing.JFileChooser; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.filesystems.FileUtil; import org.openide.NotifyDescriptor; import org.openide.DialogDisplayer; import org.openide.WizardValidationException; import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.modules.web.project.ProjectWebModule; import org.netbeans.api.web.dd.DDProvider; import org.netbeans.api.web.dd.WebApp; public class ImportWebLocationsVisual extends javax.swing.JPanel implements DocumentListener, HelpCtx.Provider { private ImportWebProjectWizardIterator.SecondPanel panel; private String sourceRoot; protected String j2eeLevel; /** Creates new form ImportWebLocationsVisual */ public ImportWebLocationsVisual(ImportWebProjectWizardIterator.SecondPanel panel) { this.panel = panel; initComponents(); this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportWebLocationsVisual.class, "ACS_IW_SourcesPanel_A11YDesc")); // NOI18N setName(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_ImportLocationsTitle")); //NOI18N jTextFieldWebPages.getDocument().addDocumentListener(this); jTextFieldJavaSources.getDocument().addDocumentListener(this); jTextFieldLibraries.getDocument().addDocumentListener(this); jComboBoxJ2eeLevel.addItem(NbBundle.getMessage(ImportWebLocationsVisual.class, "J2EESpecLevel_0")); //NOI18N jComboBoxJ2eeLevel.addItem(NbBundle.getMessage(ImportWebLocationsVisual.class, "J2EESpecLevel_1")); //NOI18N jComboBoxJ2eeLevel.setSelectedIndex(0); } public void initValues(String sourceRoot, String webPages,String javaSources,String libraries) { this.sourceRoot = sourceRoot; //set the locations only if they weren't set before if (jTextFieldWebPages.getText().trim().equals("")) jTextFieldWebPages.setText(webPages); if (jTextFieldJavaSources.getText().trim().equals("")) jTextFieldJavaSources.setText(javaSources); if (jTextFieldLibraries.getText().trim().equals("")) jTextFieldLibraries.setText(libraries); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTextFieldWebPages = new javax.swing.JTextField(); jButtonWebPages = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); jTextFieldJavaSources = new javax.swing.JTextField(); jButtonJavaSources = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); jTextFieldLibraries = new javax.swing.JTextField(); jButtonLibraries = new javax.swing.JButton(); jLabel5 = new javax.swing.JLabel(); jComboBoxJ2eeLevel = new javax.swing.JComboBox(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jTextAreaDescription = new javax.swing.JTextArea(); FormListener formListener = new FormListener(); setLayout(new java.awt.GridBagLayout()); setPreferredSize(new java.awt.Dimension(231, 238)); jLabel1.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_LocationDesc_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); add(jLabel1, gridBagConstraints); jLabel2.setDisplayedMnemonic(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_WebPagesLocation_LabelMnemonic").charAt(0)); jLabel2.setLabelFor(jTextFieldWebPages); jLabel2.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_WebPagesLocation_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jLabel2, gridBagConstraints); jTextFieldWebPages.addFocusListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jTextFieldWebPages, gridBagConstraints); jTextFieldWebPages.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportWebLocationsVisual.class, "ACS_LBL_IW_WebPagesLocation_A11YDesc")); jButtonWebPages.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_NWP1_BrowseLocation_Button")); jButtonWebPages.addActionListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); add(jButtonWebPages, gridBagConstraints); jButtonWebPages.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportWebLocationsVisual.class, "ACS_LBL_IW_WebPagesLocationBrowse_A11YDesc")); jLabel3.setDisplayedMnemonic(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_JavaSourcesLocation_LabelMnemonic").charAt(0)); jLabel3.setLabelFor(jTextFieldJavaSources); jLabel3.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_JavaSourcesLocation_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jLabel3, gridBagConstraints); jTextFieldJavaSources.addFocusListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jTextFieldJavaSources, gridBagConstraints); jTextFieldJavaSources.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportWebLocationsVisual.class, "ACS_LBL_IW_JavaSourcesLocation_A11YDesc")); jButtonJavaSources.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_NWP1_BrowseLocation_Button")); jButtonJavaSources.addActionListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); add(jButtonJavaSources, gridBagConstraints); jButtonJavaSources.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportWebLocationsVisual.class, "ACS_LBL_IW_JavaSourcesLocationBrowse_A11YDesc")); jLabel4.setDisplayedMnemonic(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_LibrariesLocation_LabelMnemonic").charAt(0)); jLabel4.setLabelFor(jTextFieldLibraries); jLabel4.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_LibrariesLocation_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jLabel4, gridBagConstraints); jTextFieldLibraries.addFocusListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jTextFieldLibraries, gridBagConstraints); jTextFieldLibraries.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportWebLocationsVisual.class, "ACS_LBL_IW_LibrariesLocation_A11YDesc")); jButtonLibraries.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_NWP1_BrowseLocation_Button")); jButtonLibraries.addActionListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); add(jButtonLibraries, gridBagConstraints); jButtonLibraries.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportWebLocationsVisual.class, "ACS_LBL_IW_LibrariesLocationBrowse_A11YDesc")); jLabel5.setDisplayedMnemonic(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_WebPagesLocation_J2EESpecLevel_LabelMnemonic").charAt(0)); jLabel5.setLabelFor(jComboBoxJ2eeLevel); jLabel5.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_WebPagesLocation_J2EESpecLevel_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jLabel5, gridBagConstraints); jComboBoxJ2eeLevel.addActionListener(formListener); jComboBoxJ2eeLevel.addFocusListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jComboBoxJ2eeLevel, gridBagConstraints); jLabel6.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_Required_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); add(jLabel6, gridBagConstraints); jLabel7.setDisplayedMnemonic(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_Description_LabelMnemonic").charAt(0)); jLabel7.setLabelFor(jTextAreaDescription); jLabel7.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_NWP1_J2EESpecLevelDesc_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(12, 0, 11, 0); add(jLabel7, gridBagConstraints); jTextAreaDescription.setEditable(false); jTextAreaDescription.setLineWrap(true); jTextAreaDescription.setWrapStyleWord(true); jTextAreaDescription.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 7; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weighty = 1.0; add(jTextAreaDescription, gridBagConstraints); jTextAreaDescription.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportWebLocationsVisual.class, "ACS_LBL_IW_LocationDescription_A11YDesc")); } // Code for dispatching events from components to event handlers. private class FormListener implements java.awt.event.ActionListener, java.awt.event.FocusListener { public void actionPerformed(java.awt.event.ActionEvent evt) { if (evt.getSource() == jButtonWebPages) { ImportWebLocationsVisual.this.jButtonWebPagesActionPerformed(evt); } else if (evt.getSource() == jButtonJavaSources) { ImportWebLocationsVisual.this.jButtonJavaSourcesActionPerformed(evt); } else if (evt.getSource() == jButtonLibraries) { ImportWebLocationsVisual.this.jButtonLibrariesActionPerformed(evt); } else if (evt.getSource() == jComboBoxJ2eeLevel) { ImportWebLocationsVisual.this.jComboBoxJ2eeLevelActionPerformed(evt); } } public void focusGained(java.awt.event.FocusEvent evt) { if (evt.getSource() == jTextFieldWebPages) { ImportWebLocationsVisual.this.jTextFieldWebPagesFocusGained(evt); } else if (evt.getSource() == jTextFieldJavaSources) { ImportWebLocationsVisual.this.jTextFieldJavaSourcesFocusGained(evt); } else if (evt.getSource() == jTextFieldLibraries) { ImportWebLocationsVisual.this.jTextFieldLibrariesFocusGained(evt); } else if (evt.getSource() == jComboBoxJ2eeLevel) { ImportWebLocationsVisual.this.jComboBoxJ2eeLevelFocusGained(evt); } } public void focusLost(java.awt.event.FocusEvent evt) { } }//GEN-END:initComponents private void jComboBoxJ2eeLevelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxJ2eeLevelActionPerformed setJ2eeDescription(); }//GEN-LAST:event_jComboBoxJ2eeLevelActionPerformed private void jComboBoxJ2eeLevelFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jComboBoxJ2eeLevelFocusGained setJ2eeDescription(); switch (jComboBoxJ2eeLevel.getSelectedIndex()) { case 0: j2eeLevel = WebModule.J2EE_14_LEVEL; break; case 1: j2eeLevel = WebModule.J2EE_13_LEVEL; } }//GEN-LAST:event_jComboBoxJ2eeLevelFocusGained private void jTextFieldLibrariesFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldLibrariesFocusGained jTextAreaDescription.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_LibrariesLocationDesc")); //NOI18N }//GEN-LAST:event_jTextFieldLibrariesFocusGained private void jTextFieldJavaSourcesFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldJavaSourcesFocusGained jTextAreaDescription.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_JavaSourcesLocationDesc")); //NOI18N }//GEN-LAST:event_jTextFieldJavaSourcesFocusGained private void jTextFieldWebPagesFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldWebPagesFocusGained jTextAreaDescription.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_WebPagesLocationDesc")); //NOI18N }//GEN-LAST:event_jTextFieldWebPagesFocusGained private void jButtonLibrariesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLibrariesActionPerformed String location = jTextFieldLibraries.getText(); if (location.trim().length() == 0) location = sourceRoot; JFileChooser chooser = createChooser(location); if (JFileChooser.APPROVE_OPTION == chooser.showDialog(this, NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_SelectLibrariesLocation"))) { //NOI18N File libDir = chooser.getSelectedFile(); jTextFieldLibraries.setText(libDir.getAbsolutePath()); } }//GEN-LAST:event_jButtonLibrariesActionPerformed private void jButtonJavaSourcesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonJavaSourcesActionPerformed String location = jTextFieldJavaSources.getText(); if (location.trim().length() == 0) location = sourceRoot; JFileChooser chooser = createChooser(location); if (JFileChooser.APPROVE_OPTION == chooser.showDialog(this, NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_SelectJavaSourcesLocation"))) { //NOI18N File javaDir = chooser.getSelectedFile(); jTextFieldJavaSources.setText(javaDir.getAbsolutePath()); } }//GEN-LAST:event_jButtonJavaSourcesActionPerformed private void jButtonWebPagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWebPagesActionPerformed String location = jTextFieldWebPages.getText().trim(); if (location.length() == 0) location = sourceRoot; JFileChooser chooser = createChooser(location); if (JFileChooser.APPROVE_OPTION == chooser.showDialog(this, NbBundle.getMessage(ImportWebLocationsVisual.class, "LBL_IW_SelectWebPagesLocation"))) { //NOI18N File webDir = chooser.getSelectedFile(); jTextFieldWebPages.setText(webDir.getAbsolutePath()); } }//GEN-LAST:event_jButtonWebPagesActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonJavaSources; private javax.swing.JButton jButtonLibraries; private javax.swing.JButton jButtonWebPages; private javax.swing.JComboBox jComboBoxJ2eeLevel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JTextArea jTextAreaDescription; protected javax.swing.JTextField jTextFieldJavaSources; protected javax.swing.JTextField jTextFieldLibraries; protected javax.swing.JTextField jTextFieldWebPages; // End of variables declaration//GEN-END:variables private static JFileChooser createChooser(String path) { JFileChooser chooser = new JFileChooser(path); FileUtil.preventFileChooserSymlinkTraversal(chooser, new File(path)); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); return chooser; } // Implementation of DocumentListener -------------------------------------- public void changedUpdate(DocumentEvent e) { updateTexts(e); } public void insertUpdate(DocumentEvent e) { updateTexts(e); } public void removeUpdate(DocumentEvent e) { updateTexts(e); } // End if implementation of DocumentListener ------------------------------- /** Handles changes in the project name and project directory */ private void updateTexts(DocumentEvent e) { if(jTextFieldWebPages.getDocument().equals(e.getDocument())) { checkWebXmlJ2eeVersion(); } panel.fireChangeEvent (); } /** Help context where to find more about the paste type action. * @return the help context for this action */ public HelpCtx getHelpCtx() { return new HelpCtx(ImportWebLocationsVisual.class); } private void setJ2eeDescription() { jTextAreaDescription.setText(NbBundle.getMessage(ImportWebLocationsVisual.class, "J2EESpecLevel_Desc_" + jComboBoxJ2eeLevel.getSelectedIndex())); //NOI18N } public void validateLocations() throws WizardValidationException { File webInfLocation = new File(new File(jTextFieldWebPages.getText().trim()), ProjectWebModule.FOLDER_WEB_INF); File fileDD = new File(webInfLocation, ProjectWebModule.FILE_DD); if(!fileDD.exists()) { NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Confirmation( fileDD.getAbsolutePath() + "\n" + NbBundle.getMessage(ImportWebLocationsVisual.class, "MSG_FileNotFound"), NotifyDescriptor.PLAIN_MESSAGE); NotifyDescriptor.YES_OPTION.equals(DialogDisplayer.getDefault().notify(notifyDescriptor)); throw new WizardValidationException(jTextFieldWebPages, "", ""); } } private void checkWebXmlJ2eeVersion() { File webInfLocation = new File(new File(jTextFieldWebPages.getText().trim()), ProjectWebModule.FOLDER_WEB_INF); File fileDD = new File(webInfLocation, ProjectWebModule.FILE_DD); if(fileDD.exists()) { try { String version = DDProvider.getDefault().getDDRoot(fileDD).getVersion(); if(WebApp.VERSION_2_3.equals(version)) { jComboBoxJ2eeLevel.setSelectedIndex(1); } else if(WebApp.VERSION_2_4.equals(version)) { jComboBoxJ2eeLevel.setSelectedIndex(0); } } catch (Exception e) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(NbBundle.getMessage( ImportWebLocationsVisual.class, "MSG_WebXmlCorrupted" + ":" + e.getMessage()), NotifyDescriptor.ERROR_MESSAGE)); } } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.