alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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.dd.wizards;

import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentListener;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.netbeans.spi.project.support.GenericSources;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.NbBundle;
import org.netbeans.modules.web.api.webmodule.WebModule;

// XXX I18N

/**
 *
 * @author  phrebejk, mkuchtiak
 */
public class TargetChooserPanelGUI extends javax.swing.JPanel implements ActionListener, DocumentListener  {
    private static final String TAG_FILE_FOLDER="WEB-INF/tags"; //NOI18N
    private static final String TAG_FILE_IN_JAVALIB_FOLDER="META-INF/tags"; //NOI18N
    private static final String TLD_FOLDER="WEB-INF/tlds"; //NOI18N
    private static final String TLD_IN_JAVALIB_FOLDER="META-INF"; //NOI18N
    
    private TargetChooserPanel wizardPanel;
    private Project project;
    private String expectedExtension;
    private final List/**/ listeners = new ArrayList();
    private SourceGroup[] folders;
    private FileType fileType;
    private WebModule wm;
    // GUI components for JSP/TAG
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextArea descriptionArea;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton jspSyntaxButton, xmlSyntaxButton;
    private javax.swing.JCheckBox segmentBox;
    private javax.swing.JLabel descriptionLabel, optionLabel;

    // GUI components for TLD
    private javax.swing.JTextField uriTextField,prefixTextField;
    private javax.swing.JLabel uriLabel, prefixLabel;
    private boolean uriWasTyped,prefixWasTyped;
    boolean tagFileValid=true;
    
    /** Creates new form TargetChooserGUI */
    public TargetChooserPanelGUI(final TargetChooserPanel wizardPanel, Project project, SourceGroup[] folders, FileType fileType) {
        this.wizardPanel = wizardPanel;
        this.project = project;
        this.folders=folders;
        this.fileType=fileType;
        initComponents();
        getAccessibleContext().setAccessibleDescription(
            NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_TargetPanel",fileType.toString()));
        
        if (FileType.JSP.equals(fileType) || FileType.TAG.equals(fileType)) {
            buttonGroup1 = new javax.swing.ButtonGroup();
            jScrollPane1 = new javax.swing.JScrollPane();
            descriptionArea = new javax.swing.JTextArea();
            segmentBox = new javax.swing.JCheckBox();
            descriptionLabel = new javax.swing.JLabel();
            optionLabel = new javax.swing.JLabel();
            jspSyntaxButton = new javax.swing.JRadioButton();
            xmlSyntaxButton = new javax.swing.JRadioButton();
            
            java.awt.GridBagConstraints gridBagConstraints;
            
            segmentBox.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    checkBoxChanged(evt);
                }
            });

            optionLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Options"));
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.gridheight = 2;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
            gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
            namePanel.add(optionLabel, gridBagConstraints);

            jspSyntaxButton.setSelected(true);
            jspSyntaxButton.setMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_JspStandard_mnem").charAt(0));
            buttonGroup1.add(jspSyntaxButton);
            jspSyntaxButton.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    checkBoxChanged(evt);
                }
            });

            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0);
            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
            namePanel.add(jspSyntaxButton, gridBagConstraints);
            
            xmlSyntaxButton.setMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_JspXml_mnem").charAt(0));
            buttonGroup1.add(xmlSyntaxButton);
            xmlSyntaxButton.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    checkBoxChanged(evt);
                }
            });

            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0);
            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
            namePanel.add(xmlSyntaxButton, gridBagConstraints);
            
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
            gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
            segmentBox.setMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_JspSegment_mnem").charAt(0));
            namePanel.add(segmentBox, gridBagConstraints);
            
            descriptionLabel.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_description"));
            descriptionLabel.setDisplayedMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Description_mnem").charAt(0));
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
            gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
            descriptionLabel.setLabelFor(descriptionArea);
            customPanel.add(descriptionLabel, gridBagConstraints);

            descriptionArea.setEditable(false);
            descriptionArea.setLineWrap(true);
            descriptionArea.setRows(3);
            descriptionArea.setWrapStyleWord(true);
            descriptionArea.setOpaque(false);
            descriptionArea.getAccessibleContext().setAccessibleDescription(descriptionLabel.getText());
            jScrollPane1.setViewportView(descriptionArea);

            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.weighty = 2.0;
            customPanel.add(jScrollPane1, gridBagConstraints);

        } else if (FileType.TAGLIBRARY.equals(fileType)) {
            java.awt.GridBagConstraints gridBagConstraints;
            uriTextField = new javax.swing.JTextField();
            uriTextField.setColumns(20);
            prefixTextField = new javax.swing.JTextField();
            prefixTextField.setColumns(5);
            
            uriLabel = new javax.swing.JLabel(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_URI"));
            uriLabel.setLabelFor(uriTextField);
            uriLabel.setDisplayedMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_URI_mnem").charAt(0));
            uriTextField.getAccessibleContext().setAccessibleDescription(
                NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_URI"));
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
            customPanel.add(uriLabel, gridBagConstraints);

            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 0);
            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
            gridBagConstraints.weightx = 1.0;
            customPanel.add(uriTextField, gridBagConstraints);

            prefixLabel = new javax.swing.JLabel(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Prefix"));
            prefixLabel.setLabelFor(prefixTextField);
            prefixLabel.setDisplayedMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Prefix_mnem").charAt(0));
            prefixTextField.getAccessibleContext().setAccessibleDescription(
                NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_Prefix"));
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
            customPanel.add(prefixLabel, gridBagConstraints);
            
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
            customPanel.add(prefixTextField, gridBagConstraints);
            
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 3;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            gridBagConstraints.gridheight = 2;
            gridBagConstraints.weightx = 2.0;
            customPanel.add(new javax.swing.JPanel(), gridBagConstraints);
            
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 2;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            gridBagConstraints.weightx = 1.0;
            customPanel.add(new javax.swing.JPanel(), gridBagConstraints);

            uriTextField.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    uriWasTyped=true;
                    wizardPanel.fireChange();
                }
            });

            prefixTextField.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    prefixWasTyped=true;
                    wizardPanel.fireChange();
                }
            });
        }
          
        
        //initValues( project, null, null );
        browseButton.addActionListener( this );
        documentNameTextField.getDocument().addDocumentListener( this );
        folderTextField.getDocument().addDocumentListener( this );
        
        setName( NbBundle.getMessage(TargetChooserPanelGUI.class,"TITLE_name_location"));
        
        if (fileType.equals(FileType.JSP)) {
            jLabel3.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_JspName"));
            jspSyntaxButton.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_JspSyntax"));
            jspSyntaxButton.getAccessibleContext().setAccessibleDescription(
                NbBundle.getMessage(TargetChooserPanelGUI.class, "DESC_JSP"));
            xmlSyntaxButton.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_XmlSyntax"));
            xmlSyntaxButton.getAccessibleContext().setAccessibleDescription(
                NbBundle.getMessage(TargetChooserPanelGUI.class, "DESC_JSP_XML"));
            segmentBox.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_JspSegment"));
            segmentBox.getAccessibleContext().setAccessibleDescription(
                NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_JSP_segment"));
            descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_JSP"));
        } else if (fileType.equals(FileType.TAG)) {
            jLabel3.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_TagFileName"));
            jspSyntaxButton.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_TagFileJsp"));
            jspSyntaxButton.getAccessibleContext().setAccessibleDescription(
                NbBundle.getMessage(TargetChooserPanelGUI.class, "DESC_TagFile"));
            xmlSyntaxButton.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_TagFileXml"));
            xmlSyntaxButton.getAccessibleContext().setAccessibleDescription(
                NbBundle.getMessage(TargetChooserPanelGUI.class, "DESC_TagFileXml"));
            segmentBox.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_TagFileSegment"));
            segmentBox.getAccessibleContext().setAccessibleDescription(
                NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_TagFile_segment"));
            descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFile"));
        } else if (fileType.equals(FileType.TAGLIBRARY)) {
            jLabel3.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_TldName"));
        } else if (fileType.equals(FileType.HTML)) {
            jLabel3.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_HtmlName"));
        }
    }
    
    public java.awt.Dimension getPreferredSize() {
        return PageIterator.PREF_SIZE;
    }
    
    WebModule getWebModule() {
        return wm;
    }
    
    public void initValues( Project p, FileObject template, FileObject preselectedFolder ) {
        projectTextField.setText(ProjectUtils.getInformation(p).getDisplayName());
        // set the location field and find web module
        if (folders!=null && folders.length>0) {
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(getLocations(folders)));
            wm = WebModule.getWebModule(folders[0].getRootFolder());
        } else
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(
                new Object[]{new LocationItem(p.getProjectDirectory())}));
        
        // filling the folder field
        String target=null;
        FileObject docBase = getLocationRoot();
        if ( preselectedFolder != null && FileUtil.isParentOf( docBase, preselectedFolder ) ) {
            target = FileUtil.getRelativePath( docBase, preselectedFolder );
        }
        
        // leave target null for tag files and TLDs outside the web project
        if (wm==null) {
            if (FileType.TAG.equals(fileType) && target!=null && !target.startsWith(TAG_FILE_IN_JAVALIB_FOLDER)) {
                target=null;
            }
            if (FileType.TAGLIBRARY.equals(fileType) && target!=null && !target.startsWith(TLD_IN_JAVALIB_FOLDER)) {
                target=null;
            }
        }
        
        // setting target folders for tag files and tlds 
        if (FileType.TAG.equals(fileType) && target==null) {
            if (wm!=null) folderTextField.setText(TAG_FILE_FOLDER+"/");
            else folderTextField.setText(TAG_FILE_IN_JAVALIB_FOLDER+"/");
        } else if (FileType.TAGLIBRARY.equals(fileType) && target==null) {
            if (wm==null) folderTextField.setText(TLD_IN_JAVALIB_FOLDER+"/"); // NOI18N
            else folderTextField.setText(TLD_FOLDER+"/"); // NOI18N
        } else 
            folderTextField.setText( target == null ? "" : target ); // NOI18N      
        String ext = template == null ? "" : template.getExt(); // NOI18N
        expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N
    }
    
    private Object[] getLocations(SourceGroup[] folders) {
        Object[] loc = new Object[folders.length];
        for (int i=0;i0) buf.append("/"+token);
        }     
        return buf.toString();
    }
    
    public String getTargetFolder() {
        return getTargetFile().getPath();
    }
    
    public File getTargetFile() {
        String text = getRelativeTargetFolder();
        
        if ( text.length() == 0 ) {
            if (wm==null)
                return FileUtil.toFile(getLocationRoot());
            else
                return FileUtil.toFile( wm.getDocumentBase());
        }
        else {
            // XXX have to account for FU.tF returning null
            if (wm==null) {
                return new File( FileUtil.toFile(getLocationRoot()), text );
            } else {
                return new File( FileUtil.toFile( wm.getDocumentBase() ), text );
            }
        }
    }
    public String getTargetName() {
        
        String text = documentNameTextField.getText().trim();
        
        if ( text.length() == 0 ) {
            return null;
        }
        else {
            return text;
        }
    }
    /*
    public void addChangeListener(ChangeListener l) {
        listeners.add(l);
    }
    
    public void removeChangeListener(ChangeListener l) {
        listeners.remove(l);
    }
    
    private void fireChange() {
        ChangeEvent e = new ChangeEvent(this);
        Iterator it = listeners.iterator();
        while (it.hasNext()) {
            ((ChangeListener)it.next()).stateChanged(e);
        }
    }
    */
        
    /** 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;

    namePanel = new javax.swing.JPanel();
    jLabel3 = new javax.swing.JLabel();
    documentNameTextField = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    projectTextField = new javax.swing.JTextField();
    jLabel7 = new javax.swing.JLabel();
    jComboBox1 = new javax.swing.JComboBox();
    jLabel2 = new javax.swing.JLabel();
    folderTextField = new javax.swing.JTextField();
    browseButton = new javax.swing.JButton();
    jLabel4 = new javax.swing.JLabel();
    fileTextField = new javax.swing.JTextField();
    targetSeparator = new javax.swing.JSeparator();
    customPanel = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();

    setLayout(new java.awt.GridBagLayout());

    namePanel.setLayout(new java.awt.GridBagLayout());

    jLabel3.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_FileName_mnem").charAt(0));
    jLabel3.setLabelFor(documentNameTextField);
    jLabel3.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_JspName"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    namePanel.add(jLabel3, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
    namePanel.add(documentNameTextField, gridBagConstraints);
    documentNameTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_FileName"));

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    add(namePanel, gridBagConstraints);

    jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Project_mnem").charAt(0));
    jLabel1.setLabelFor(projectTextField);
    jLabel1.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Project"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
    add(jLabel1, gridBagConstraints);

    projectTextField.setEditable(false);
    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(12, 6, 0, 0);
    add(projectTextField, gridBagConstraints);
    projectTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_Project"));

    jLabel7.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Location_mnem").charAt(0));
    jLabel7.setLabelFor(jComboBox1);
    jLabel7.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Location"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
    add(jLabel7, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
    add(jComboBox1, gridBagConstraints);
    jComboBox1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_Location"));

    jLabel2.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Folder_mnem").charAt(0));
    jLabel2.setLabelFor(folderTextField);
    jLabel2.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Folder"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
    add(jLabel2, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
    add(folderTextField, gridBagConstraints);
    folderTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_Folder"));

    browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Browse_Mnemonic").charAt(0));
    browseButton.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Browse"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
    add(browseButton, gridBagConstraints);
    browseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "ACSD_Browse"));

    jLabel4.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_CreatedFile_mnem").charAt(0));
    jLabel4.setLabelFor(fileTextField);
    jLabel4.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_CreatedFile"));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
    add(jLabel4, gridBagConstraints);

    fileTextField.setEditable(false);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0);
    add(fileTextField, gridBagConstraints);
    fileTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_CreatedFile"));

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
    add(targetSeparator, gridBagConstraints);

    customPanel.setLayout(new java.awt.GridBagLayout());

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
    add(customPanel, gridBagConstraints);

    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(jPanel3, gridBagConstraints);

  }//GEN-END:initComponents

    
    
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton browseButton;
  private javax.swing.JPanel customPanel;
  private javax.swing.JTextField documentNameTextField;
  private javax.swing.JTextField fileTextField;
  private javax.swing.JTextField folderTextField;
  private javax.swing.JComboBox jComboBox1;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JPanel jPanel3;
  private javax.swing.JPanel namePanel;
  private javax.swing.JTextField projectTextField;
  private javax.swing.JSeparator targetSeparator;
  // End of variables declaration//GEN-END:variables

    // ActionListener implementation -------------------------------------------
    
    public void actionPerformed(java.awt.event.ActionEvent e) {
        if ( browseButton == e.getSource() ) {
            FileObject fo=null;
            // Show the browse dialog 
            if (folders!=null) fo = BrowseFolders.showDialog(folders, org.openide.loaders.DataFolder.class);
            else {		           
                Sources sources = (Sources)project.getLookup().lookup( Sources.class );
                if (sources == null) {
                    sources = GenericSources.genericOnly(project);
                }
                fo = BrowseFolders.showDialog( sources.getSourceGroups( Sources.TYPE_GENERIC ),
                                               org.openide.loaders.DataFolder.class);
            }
            
            if ( fo != null && fo.isFolder() ) {
                FileObject root = ((LocationItem)jComboBox1.getSelectedItem()).getFileObject();
                folderTextField.setText( FileUtil.getRelativePath( root, fo ) );
            }
                        
        }
    }    
    
    // DocumentListener implementation -----------------------------------------
    
    public void changedUpdate(javax.swing.event.DocumentEvent e) {

        File rootDirFile = FileUtil.toFile(((LocationItem)jComboBox1.getSelectedItem()).getFileObject());
        if (rootDirFile != null) {
            String documentName = documentNameTextField.getText().trim();
            if (documentName.length() == 0) {
                fileTextField.setText(""); // NOI18N
            } else {
                File newFile = new File(new File(rootDirFile, folderTextField.getText().replace('/', File.separatorChar)),
                                        documentName + expectedExtension+(isSegment()?"f":(isXml()?"x":""))); //NOI18N
                fileTextField.setText(newFile.getAbsolutePath());
            }
        } else {
            // Not on disk.
            fileTextField.setText(""); // NOI18N
        }
        if (FileType.TAGLIBRARY.equals(fileType)) {
            if (!uriWasTyped) {
                String norm=getNormalizedFolder();
                //Default value for uri
                if (wm==null) {
                    String pack = getPackageNameInMetaInf();
                    uriTextField.setText((pack.length()>0?pack+".":"")+documentNameTextField.getText());
                }
                else uriTextField.setText((norm.length()==0?"":"/"+getNormalizedFolder())+ //NOI18N
                                          "/"+documentNameTextField.getText().trim()); //NOI18N
            }
            //Default value for prefix
            if (!prefixWasTyped)
                 prefixTextField.setText(documentNameTextField.getText().trim().toLowerCase());
        }
        wizardPanel.fireChange();
    }
    
    private String getPackageNameInMetaInf() {
        String pack = getRelativeTargetFolder();
        if (pack.startsWith("META-INF")) {//NOI18N
            pack = pack.substring(8);
            if (pack.length()==0) return "";
            if (pack.startsWith("/")) pack=pack.substring(1);//NOI18N
        }
        if (pack.length()==0) return "";//NOI18N
        pack = pack.replace('/', '.');
        return pack;
    }
    
    
    /** specific for JSP/TAG wizards
     */
    private void checkBoxChanged(java.awt.event.ItemEvent evt) {
        // TODO add your handling code here:
        if (fileType.equals(FileType.JSP)) {
            if (isSegment()) {
                if (isXml()) {
                    descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_segment_XML"));
                } else {
                    descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_segment"));
                }
                String createdFile = fileTextField.getText();
                if (createdFile.endsWith("jspx")) //NOI18N
                    fileTextField.setText(createdFile.substring(0,createdFile.length()-1)+"f"); //NOI18N
                else if (createdFile.endsWith("jsp")) //NOI18N
                    fileTextField.setText(createdFile+"f"); //NOI18N
            } else {
                String createdFile = fileTextField.getText();
                if (isXml()) {
                    descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_JSP_XML"));
                    if (createdFile.endsWith("jspf")) { //NOI18N
                        fileTextField.setText(createdFile.substring(0,createdFile.length()-1)+"x"); //NOI18N
                    } else if (createdFile.endsWith("jsp")) { //NOI18N
                        fileTextField.setText(createdFile+"x"); //NOI18N
                    }
                } else {
                    descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_JSP"));
                    if (createdFile.endsWith("jspf") || createdFile.endsWith("jspx")) { //NOI18N
                        fileTextField.setText(createdFile.substring(0,createdFile.length()-1)); //NOI18N
                    }
                }
            }
        } else if (fileType.equals(FileType.TAG)){
            if (isSegment()) {
                if (isXml()) {
                    descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFileSegmentXml"));
                } else {
                    descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFileSegment"));
                }
                String createdFile = fileTextField.getText();
                if (createdFile.endsWith("tagx")) //NOI18N
                    fileTextField.setText(createdFile.substring(0,createdFile.length()-1)+"f"); //NOI18N
                else if (createdFile.endsWith("tag")) //NOI18N 
                    fileTextField.setText(createdFile+"f"); //NOI18N
            } else {
                String createdFile = fileTextField.getText();
                if (isXml()) {
                    descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFileXml"));
                    if (createdFile.endsWith("tagf")) { //NOI18N
                        fileTextField.setText(createdFile.substring(0,createdFile.length()-1)+"x"); //NOI18N
                    } else if (createdFile.endsWith("tag")) { //NOI18N
                        fileTextField.setText(createdFile+"x"); //NOI18N
                    }
                } else {
                    descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFile"));
                    if (createdFile.endsWith("tagf") || createdFile.endsWith("tagx")) { //NOI18N
                        fileTextField.setText(createdFile.substring(0,createdFile.length()-1)); //NOI18N
                    }
                }
            }
        }
        wizardPanel.fireChange();
    }
    
    public void insertUpdate(javax.swing.event.DocumentEvent e) {
        changedUpdate( e );
    }
    
    public void removeUpdate(javax.swing.event.DocumentEvent e) {
        changedUpdate( e );
    }
    
    boolean isXml() {
        if (xmlSyntaxButton==null) return false;
        else return xmlSyntaxButton.isSelected();
    }
    
    boolean isSegment() {
        if (segmentBox==null) return false;
        else return segmentBox.isSelected();
    }

    String getUri() {
        if (uriTextField==null) return "";
        else return uriTextField.getText();
    }
    String getPrefix() {
        if (prefixTextField==null) return "";
        else return prefixTextField.getText();
    }
    
    String getErrorMessage() {
        if (FileType.JSP.equals(fileType)) {
            if (isSegment() && !getNormalizedFolder().startsWith("WEB-INF/jspf")) //NOI18N
                return NbBundle.getMessage(TargetChooserPanelGUI.class,"NOTE_segment");
        } else if (FileType.TAG.equals(fileType)) {
            tagFileValid=true;
            if (wm!=null) {
                if (!getNormalizedFolder().startsWith(TAG_FILE_FOLDER)) {
                    tagFileValid=false;
                    return NbBundle.getMessage(TargetChooserPanelGUI.class,"MSG_TagFile");
                }
            } else {
                if (!getNormalizedFolder().startsWith(TAG_FILE_IN_JAVALIB_FOLDER)) {
                    tagFileValid=false;
                    return NbBundle.getMessage(TargetChooserPanelGUI.class,"MSG_TagFileInJavalib");
                }
            }
        } else if (FileType.TAGLIBRARY.equals(fileType)) {
            if (wm==null) {
                if (!getNormalizedFolder().startsWith(TLD_IN_JAVALIB_FOLDER))
                    return NbBundle.getMessage(TargetChooserPanelGUI.class,"NOTE_TLDInJavalib");
            } else
                if (!getNormalizedFolder().startsWith("WEB-INF")) //NOI18N
                    return NbBundle.getMessage(TargetChooserPanelGUI.class,"NOTE_TLDInWeb");              
            if (getUri().length()==0) //NOI18N
                return NbBundle.getMessage(TargetChooserPanelGUI.class,"MSG_missingUri");
            if (getPrefix().length()==0) //NOI18N
                return NbBundle.getMessage(TargetChooserPanelGUI.class,"MSG_missingPrefix");
        }
        return null;
    }
    
    boolean isPanelValid() {
        if (FileType.TAGLIBRARY.equals(fileType) && 
            (getUri().length()==0 || getPrefix().length()==0))
            return false;
        if (FileType.TAG.equals(fileType) && !tagFileValid)
            return false;
        return true;
    }
    
    FileObject getLocationRoot() {
        return ((LocationItem)jComboBox1.getModel().getSelectedItem()).getFileObject();
    }
    
    public static class LocationItem {
        FileObject fo;
        SourceGroup group;
        public LocationItem(FileObject fo) {
            this.fo=fo;
        }
        public LocationItem(SourceGroup group) {
            this.fo=group.getRootFolder();
            this.group=group;
        }        
        public FileObject getFileObject() {
            return fo;
        }
        
        public String toString() {
            return (group==null?fo.getName():group.getDisplayName());
        }
    }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.