|
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.ant.freeform.ui; import java.io.File; import java.util.ArrayList; import java.util.List; import javax.swing.JFileChooser; import org.openide.filesystems.FileUtil; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.netbeans.modules.ant.freeform.FreeformProject; import org.netbeans.modules.ant.freeform.FreeformProjectGenerator; import org.netbeans.modules.web.api.webmodule.WebProjectConstants; /** * * @author Radko Najman */ public class WebLocationsPanel extends javax.swing.JPanel implements ProjectCustomizer.Panel, HelpCtx.Provider { private boolean initialized; /** Original project base folder */ private File baseFolder; /** Freeform Project base folder */ private File nbProjectFolder; /** Creates new form WebLocations */ public WebLocationsPanel() { initComponents(); jComboBoxJ2eeLevel.addItem(NbBundle.getMessage(WebLocationsPanel.class, "TXT_J2EESpecLevel_0")); jComboBoxJ2eeLevel.addItem(NbBundle.getMessage(WebLocationsPanel.class, "TXT_J2EESpecLevel_1")); jComboBoxJ2eeLevel.setSelectedIndex(0); } public HelpCtx getHelpCtx() { return new HelpCtx( WebLocationsPanel.class ); } /** 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(); jTextFieldWeb = new javax.swing.JTextField(); jButtonWeb = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); jTextFieldSrc = new javax.swing.JTextField(); jButtonSrc = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); jTextFieldContextPath = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jComboBoxJ2eeLevel = new javax.swing.JComboBox(); FormListener formListener = new FormListener(); setLayout(new java.awt.GridBagLayout()); setPreferredSize(new java.awt.Dimension(375, 135)); jLabel1.setText(org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "LBL_WebPagesPanel_Description")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); add(jLabel1, gridBagConstraints); jLabel2.setLabelFor(jTextFieldWeb); org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "LBL_WebPagesPanel_WebPagesLocation_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 11); add(jLabel2, gridBagConstraints); 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, 6, 11); add(jTextFieldWeb, gridBagConstraints); jTextFieldWeb.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "ACS_LBL_WebPagesPanel_WebPagesLocation_A11YDesc")); org.openide.awt.Mnemonics.setLocalizedText(jButtonWeb, org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "BTN_BasicProjectInfoPanel_browseAntScript")); jButtonWeb.addActionListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0); add(jButtonWeb, gridBagConstraints); jButtonWeb.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "ACS_LBL_WebPagesPanel_WebPagesLocationBrowse_A11YDesc")); jLabel3.setLabelFor(jTextFieldSrc); org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "LBL_WebPagesPanel_JavaSourcesLocation_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); add(jLabel3, gridBagConstraints); 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(jTextFieldSrc, gridBagConstraints); jTextFieldSrc.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "ACS_LBL_WebPagesPanel_JavaSourcesLocation_A11YDesc")); org.openide.awt.Mnemonics.setLocalizedText(jButtonSrc, org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "BTN_BasicProjectInfoPanel_browseProjectFolder")); jButtonSrc.addActionListener(formListener); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); add(jButtonSrc, gridBagConstraints); jButtonSrc.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "ACS_LBL_WebPagesPanel_JavaSourcesLocationBrowse_A11YDesc")); jLabel4.setLabelFor(jTextFieldContextPath); org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "LBL_WebPagesPanel_ContextPath_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 11); add(jLabel4, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0); add(jTextFieldContextPath, gridBagConstraints); jTextFieldContextPath.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "ACS_LBL_WebPagesPanel_ContextPath_A11YDesc")); jLabel5.setLabelFor(jComboBoxJ2eeLevel); org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "LBL_WebPagesPanel_J2EESpecLevel_Label")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(3, 0, 0, 11); add(jLabel5, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weighty = 1.0; add(jComboBoxJ2eeLevel, gridBagConstraints); jComboBoxJ2eeLevel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(WebLocationsPanel.class, "ACS_LBL_WebPagesPanel_J2EESpecLevel_A11YDesc")); } // Code for dispatching events from components to event handlers. private class FormListener implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent evt) { if (evt.getSource() == jButtonWeb) { WebLocationsPanel.this.jButtonWebActionPerformed(evt); } else if (evt.getSource() == jButtonSrc) { WebLocationsPanel.this.jButtonSrcActionPerformed(evt); } } }//GEN-END:initComponents private void jButtonSrcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSrcActionPerformed JFileChooser chooser = createChooser(getSrcPackagesLocation().getAbsolutePath()); if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { setSrcPackages(chooser.getSelectedFile()); } }//GEN-LAST:event_jButtonSrcActionPerformed private void jButtonWebActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWebActionPerformed JFileChooser chooser = createChooser(getWebPagesLocation().getAbsolutePath()); if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { setWebPages(chooser.getSelectedFile()); } }//GEN-LAST:event_jButtonWebActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonSrc; private javax.swing.JButton jButtonWeb; 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.JTextField jTextFieldContextPath; private javax.swing.JTextField jTextFieldSrc; private javax.swing.JTextField jTextFieldWeb; // End of variables declaration//GEN-END:variables private static JFileChooser createChooser(String path) { JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, new File(path)); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); return chooser; } protected List getWebModules() { ArrayList l = new ArrayList(); FreeformProjectGenerator.WebModule wm = new FreeformProjectGenerator.WebModule (); wm.docRoot = getRelativeLocation(getWebPagesLocation()); wm.contextPath = jTextFieldContextPath.getText().trim(); wm.j2eeSpecLevel = (String) jComboBoxJ2eeLevel.getSelectedItem(); wm.classpath = getRelativeLocation(getSrcPackagesLocation()); l.add (wm); return l; } protected List getJavaSrcFolder() { ArrayList l = new ArrayList(); File sourceLoc = getSrcPackagesLocation(); FreeformProjectGenerator.SourceFolder sf = new FreeformProjectGenerator.SourceFolder(); sf.location = getRelativeLocation(sourceLoc); sf.type = JavaProjectConstants.SOURCES_TYPE_JAVA; sf.label = sourceLoc.getName(); sf.style = "packages"; // NOI18N l.add(sf); return l; } protected List getWebSrcFolder() { ArrayList l = new ArrayList(); final File webLocation = getWebPagesLocation(); FreeformProjectGenerator.SourceFolder sf = new FreeformProjectGenerator.SourceFolder(); sf.location = getRelativeLocation(webLocation); sf.type = WebProjectConstants.TYPE_DOC_ROOT; sf.label = webLocation.getName(); sf.style = "tree"; // NOI18N l.add(sf); return l; } private File getAsFile(String filename) { final String s = filename.trim(); final File f = new File(s); return f.isAbsolute() ? f : new File(baseFolder, s).getAbsoluteFile(); } /** Called from WizardDescriptor.Panel and ProjectCustomizer.Panel * to set base folder. Panel will use this for default position of JFileChooser. * @param baseFolder original project base folder * @param nbProjectFolder Freeform Project base folder */ public void setFolders(File baseFolder, File nbProjectFolder) { this.baseFolder = baseFolder; this.nbProjectFolder = nbProjectFolder; } protected void setWebPages(String path) { setWebPages(getAsFile(path)); } protected void setSrcPackages(String path) { setSrcPackages(getAsFile(path)); } private void setWebPages(final File file) { jTextFieldWeb.setText(relativizeFile(file)); } protected File getWebPagesLocation() { return getAsFile(jTextFieldWeb.getText()).getAbsoluteFile(); } private void setSrcPackages(final File file) { jTextFieldSrc.setText(relativizeFile(file)); } protected File getSrcPackagesLocation() { return getAsFile(jTextFieldSrc.getText()); } private String relativizeFile(final File file) { String filePath = FileUtil.normalizeFile(file).getAbsolutePath(); String parentPath = FileUtil.normalizeFile(baseFolder).getAbsolutePath() + File.pathSeparator; return PropertyUtils.relativizeFile(baseFolder, FileUtil.normalizeFile(file)); } private String getRelativeLocation(final File location) { final File normalizedLocation = FileUtil.normalizeFile(location); return FreeformProjectGenerator.relativizeLocation(baseFolder, nbProjectFolder, normalizedLocation); } // The implementation of ProjectCustomizer.Panel interface methods public void show(FreeformProject project, AntProjectHelper helper, ProjectModel model) { if (!initialized) { AuxiliaryConfiguration aux = FreeformProjectGenerator.getAuxiliaryConfiguration(helper); List l = FreeformProjectGenerator.getWebmodules(helper, aux); if (l != null) { setFolders(FreeformProjectGenerator.getProjectLocation(project), FileUtil.toFile(project.getProjectDirectory())); FreeformProjectGenerator.WebModule wm = (FreeformProjectGenerator.WebModule) l.get(0); String docroot = SourceFoldersPanel.getLocationDisplayName(project.evaluator(), baseFolder, wm.docRoot); String classpath = SourceFoldersPanel.getLocationDisplayName(project.evaluator(), baseFolder, wm.classpath); jTextFieldWeb.setText(docroot); jTextFieldSrc.setText(classpath); jTextFieldContextPath.setText(wm.contextPath); jComboBoxJ2eeLevel.setSelectedItem(wm.j2eeSpecLevel); } initialized = true; } } /* ProjectCustomizer.Panel hide */ public void hide(FreeformProject project, AntProjectHelper helper, ProjectModel model) { } public void storeValues(FreeformProject project, AntProjectHelper helper, ProjectModel model) { if (!initialized) { return; } AuxiliaryConfiguration aux = FreeformProjectGenerator.getAuxiliaryConfiguration(helper); FreeformProjectGenerator.putWebModules(helper, aux, getWebModules()); } // End of the implementation of ProjectCustomizer.Panel interface methods } |
... 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.