1 19 20 package org.netbeans.modules.web.jsf.wizards; 21 22 import java.io.IOException ; 23 import java.util.List ; 24 import javax.swing.ComboBoxModel ; 25 import javax.swing.JTextField ; 26 import javax.swing.event.ChangeListener ; 27 import javax.swing.event.DocumentEvent ; 28 import javax.swing.event.DocumentListener ; 29 import javax.swing.text.Document ; 30 import javax.swing.text.JTextComponent ; 31 import org.netbeans.api.project.Project; 32 import org.netbeans.api.project.ProjectUtils; 33 import org.netbeans.api.project.SourceGroup; 34 import org.netbeans.api.project.Sources; 35 import org.netbeans.modules.web.api.webmodule.WebModule; 43 import org.netbeans.modules.web.api.webmodule.WebProjectConstants; 44 import org.netbeans.modules.web.jsf.JSFConfigUtilities; 45 import org.netbeans.modules.web.jsf.dialogs.BrowseFolders; 46 import org.netbeans.spi.java.project.support.ui.PackageView; 47 import org.netbeans.spi.project.ui.templates.support.Templates; 48 import org.openide.ErrorManager; 49 import org.openide.WizardDescriptor; 50 import org.openide.filesystems.FileObject; 51 import org.openide.filesystems.FileUtil; 52 import org.openide.util.NbBundle; 53 54 58 public class PersistenceClientSetupPanelVisual extends javax.swing.JPanel implements DocumentListener { 59 60 private WizardDescriptor wizard; 61 private Project project; 62 private JTextComponent packageComboBoxEditor; 63 65 66 public PersistenceClientSetupPanelVisual(WizardDescriptor wizard) { 67 this.wizard = wizard; 68 initComponents(); 69 70 packageComboBoxEditor = ((JTextComponent )packageComboBox.getEditor().getEditorComponent()); 71 Document packageComboBoxDocument = packageComboBoxEditor.getDocument(); 72 packageComboBoxDocument.addDocumentListener(this); 73 } 74 75 80 private void initComponents() { 82 jLabel2 = new javax.swing.JLabel (); 83 jsfFolder = new javax.swing.JTextField (); 84 browseFolderButton = new javax.swing.JButton (); 85 jLabel3 = new javax.swing.JLabel (); 86 jLabel4 = new javax.swing.JLabel (); 87 jLabel5 = new javax.swing.JLabel (); 88 projectLabel = new javax.swing.JLabel (); 89 projectTextField = new javax.swing.JTextField (); 90 locationLabel = new javax.swing.JLabel (); 91 locationComboBox = new javax.swing.JComboBox (); 92 packageLabel = new javax.swing.JLabel (); 93 packageComboBox = new javax.swing.JComboBox (); 94 95 setName(org.openide.util.NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "LBL_JSFPagesAndClasses")); 96 jLabel2.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("ACS_JSF_Pages").charAt(0)); 97 jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("LBL_JSF_pages_folder")); 98 99 browseFolderButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("ACS_Browse2").charAt(0)); 100 browseFolderButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("LBL_Browse")); 101 browseFolderButton.addActionListener(new java.awt.event.ActionListener () { 102 public void actionPerformed(java.awt.event.ActionEvent evt) { 103 browseFolderButtonActionPerformed(evt); 104 } 105 }); 106 107 jLabel3.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("ACS_Controller").charAt(0)); 108 jLabel3.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("LBL_JSF_Managed_bean")); 109 110 jLabel4.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MSG_Jsf_Pages_Location")); 111 112 jLabel5.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MSG_Folders")); 113 114 projectLabel.setText(org.openide.util.NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "LBL_Project")); 115 116 projectTextField.setEditable(false); 117 118 org.openide.awt.Mnemonics.setLocalizedText(locationLabel, org.openide.util.NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "LBL_SrcLocation")); 119 120 locationComboBox.addActionListener(new java.awt.event.ActionListener () { 121 public void actionPerformed(java.awt.event.ActionEvent evt) { 122 locationComboBoxActionPerformed(evt); 123 } 124 }); 125 126 packageLabel.setText(org.openide.util.NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "LBL_Package")); 127 128 packageComboBox.setEditable(true); 129 130 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 131 this.setLayout(layout); 132 layout.setHorizontalGroup( 133 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 134 .add(layout.createSequentialGroup() 135 .add(jLabel4) 136 .addContainerGap(321, Short.MAX_VALUE)) 137 .add(layout.createSequentialGroup() 138 .add(jLabel2) 139 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 140 .add(jsfFolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE) 141 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 142 .add(browseFolderButton)) 143 .add(layout.createSequentialGroup() 144 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 145 .add(projectLabel) 146 .add(locationLabel) 147 .add(packageLabel)) 148 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 149 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 150 .add(org.jdesktop.layout.GroupLayout.TRAILING, locationComboBox, 0, 462, Short.MAX_VALUE) 151 .add(projectTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE) 152 .add(packageComboBox, 0, 462, Short.MAX_VALUE))) 153 .add(layout.createSequentialGroup() 154 .add(jLabel3) 155 .addContainerGap()) 156 .add(layout.createSequentialGroup() 157 .add(jLabel5) 158 .addContainerGap()) 159 ); 160 layout.setVerticalGroup( 161 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 162 .add(layout.createSequentialGroup() 163 .add(jLabel4) 164 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 165 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 166 .add(jLabel2) 167 .add(jsfFolder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 168 .add(browseFolderButton)) 169 .add(27, 27, 27) 170 .add(jLabel5) 171 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 172 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 173 .add(projectLabel) 174 .add(projectTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 175 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 176 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 177 .add(locationLabel) 178 .add(locationComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 179 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 180 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 181 .add(packageLabel) 182 .add(packageComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 183 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 184 .add(jLabel3) 185 .addContainerGap(70, Short.MAX_VALUE)) 186 ); 187 } 189 private void locationComboBoxActionPerformed(java.awt.event.ActionEvent evt) { locationChanged(); 191 } 193 private void browseFolderButtonActionPerformed(java.awt.event.ActionEvent evt) { Sources s = (Sources) Templates.getProject(wizard).getLookup().lookup(Sources.class); 195 org.netbeans.api.project.SourceGroup[] groups = s.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT); 196 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 197 if (fo!=null) { 198 String res = "/"+JSFConfigUtilities.getResourcePath(groups,fo,'/',true); 199 jsfFolder.setText(res); 200 } 201 } 203 204 private javax.swing.JButton browseFolderButton; 206 private javax.swing.JLabel jLabel2; 207 private javax.swing.JLabel jLabel3; 208 private javax.swing.JLabel jLabel4; 209 private javax.swing.JLabel jLabel5; 210 private javax.swing.JTextField jsfFolder; 211 private javax.swing.JComboBox locationComboBox; 212 private javax.swing.JLabel locationLabel; 213 private javax.swing.JComboBox packageComboBox; 214 private javax.swing.JLabel packageLabel; 215 private javax.swing.JLabel projectLabel; 216 private javax.swing.JTextField projectTextField; 217 219 public void addChangeListener(ChangeListener listener) { 220 } 222 223 boolean valid(WizardDescriptor wizard) { 224 return true; 255 } 256 257 public SourceGroup getLocationValue() { 258 return (SourceGroup)locationComboBox.getSelectedItem(); 259 } 260 261 public String getPackage() { 262 return packageComboBoxEditor.getText(); 263 } 264 265 private void locationChanged() { 266 updateSourceGroupPackages(); 267 } 269 270 void read(WizardDescriptor settings) { 271 jsfFolder.setText((String ) settings.getProperty(WizardProperties.JSF_FOLDER)); 272 273 project = Templates.getProject(settings); 274 FileObject targetFolder = Templates.getTargetFolder(settings); 275 276 projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName()); 277 278 281 packageComboBox.setRenderer(PackageView.listRenderer()); 282 283 updateSourceGroupPackages(); 284 285 if (targetFolder != null) { 287 if (FileUtil.isParentOf(WebModule.getWebModule( 296 targetFolder).getDocumentBase(), targetFolder)) { 297 Sources s = (Sources) Templates.getProject(wizard).getLookup().lookup(Sources.class); 298 SourceGroup[] groups = s.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT); 299 jsfFolder.setText("/"+JSFConfigUtilities.getResourcePath(groups,targetFolder,'/',true)); 300 } 301 } 302 } 303 304 void store(WizardDescriptor settings) { 305 settings.putProperty(WizardProperties.JSF_FOLDER, jsfFolder.getText()); 306 settings.putProperty(WizardProperties.JSF_CLASSES_PACKAGE, getPackage()); 307 } 313 314 private void updateSourceGroupPackages() { 315 SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem(); 316 ComboBoxModel model = PackageView.createListView(sourceGroup); 317 if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF") 318 && model.getSize() > 1) { model.setSelectedItem(model.getElementAt(1)); 320 } 321 packageComboBox.setModel(model); 322 } 323 324 public void insertUpdate(DocumentEvent e) { 325 } 327 328 public void removeUpdate(DocumentEvent e) { 329 } 331 332 public void changedUpdate(DocumentEvent e) { 333 } 335 336 } 337 | Popular Tags |