1 19 20 package org.netbeans.modules.java.freeform.ui; 21 22 import java.awt.Component ; 23 import java.awt.GridBagConstraints ; 24 import java.awt.GridBagLayout ; 25 import java.awt.Insets ; 26 import java.io.File ; 27 import java.util.ArrayList ; 28 import java.util.HashSet ; 29 import java.util.List ; 30 import java.util.Set ; 31 import javax.swing.DefaultListCellRenderer ; 32 import javax.swing.JButton ; 33 import javax.swing.JComponent ; 34 import javax.swing.JFileChooser ; 35 import javax.swing.JLabel ; 36 import javax.swing.JList ; 37 import javax.swing.JOptionPane ; 38 import javax.swing.JPanel ; 39 import javax.swing.JScrollPane ; 40 import javax.swing.JTable ; 41 import javax.swing.event.ChangeListener ; 42 import javax.swing.event.ListSelectionEvent ; 43 import javax.swing.event.ListSelectionListener ; 44 import javax.swing.table.AbstractTableModel ; 45 import javax.swing.table.DefaultTableCellRenderer ; 46 import org.netbeans.api.project.FileOwnerQuery; 47 import org.netbeans.api.project.Project; 48 import org.netbeans.api.project.ProjectInformation; 49 import org.netbeans.api.project.ProjectUtils; 50 import org.netbeans.api.queries.CollocationQuery; 51 import org.netbeans.modules.ant.freeform.spi.ProjectConstants; 52 import org.netbeans.modules.ant.freeform.spi.support.Util; 53 import org.netbeans.modules.java.freeform.JavaProjectGenerator; 54 import org.netbeans.modules.java.freeform.JavaProjectNature; 55 import org.netbeans.spi.java.project.support.ui.IncludeExcludeVisualizer; 56 import org.netbeans.spi.project.support.ant.AntProjectHelper; 57 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 58 import org.netbeans.spi.project.support.ant.PropertyUtils; 59 import org.openide.DialogDescriptor; 60 import org.openide.DialogDisplayer; 61 import org.openide.NotifyDescriptor; 62 import org.openide.filesystems.FileObject; 63 import org.openide.filesystems.FileUtil; 64 import org.openide.util.HelpCtx; 65 import org.openide.util.NbBundle; 66 67 72 public class SourceFoldersPanel extends JPanel implements HelpCtx.Provider, ListSelectionListener { 73 74 private SourcesModel sourceFoldersModel; 75 private SourcesModel testFoldersModel; 76 private ChangeListener listener; 77 private boolean isWizard; 78 private ProjectModel model; 79 80 81 public SourceFoldersPanel() { 82 this(true); 83 } 84 85 public SourceFoldersPanel(boolean isWizard) { 86 this.isWizard = isWizard; 87 initComponents(); 88 sourceFoldersModel = new SourcesModel(false); 89 sourceFolders.setModel(sourceFoldersModel); 90 sourceFolders.getSelectionModel().addListSelectionListener(this); 91 testFoldersModel = new SourcesModel(true); 92 testFolders.setModel(testFoldersModel); 93 testFolders.getSelectionModel().addListSelectionListener(this); 94 sourceFolders.getTableHeader().setReorderingAllowed(false); 95 sourceFolders.setDefaultRenderer(String .class, new ToolTipRenderer ()); 96 testFolders.getTableHeader().setReorderingAllowed(false); 97 testFolders.setDefaultRenderer(String .class, new ToolTipRenderer ()); 98 initSourceLevel(); 99 jLabel1.setVisible(isWizard); 100 projectFolderLabel.setVisible(!isWizard); 101 projectContentLabel.setVisible(!isWizard); 102 buildScriptLabel.setVisible(!isWizard); 103 projectFolder.setVisible(!isWizard); 104 contentFolder.setVisible(!isWizard); 105 buildScript.setVisible(!isWizard); 106 } 107 108 public HelpCtx getHelpCtx() { 109 return new HelpCtx( SourceFoldersPanel.class ); 110 } 111 112 114 public void setChangeListener(ChangeListener listener) { 115 this.listener = listener; 116 } 117 118 private void initSourceLevel() { 119 sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK13")); sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK14")); sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK15")); } 123 124 private void updateButtons() { 125 removeFolder.setEnabled(sourceFolders.getSelectedRowCount()>0); 126 removeTestFolder.setEnabled(testFolders.getSelectedRowCount()>0); 127 updateUpDownButtons(); 128 } 129 130 public void valueChanged(ListSelectionEvent e) { 131 updateButtons(); 132 } 133 134 private void updateUpDownButtons() { 135 int first = sourceFolders.getSelectionModel().getMinSelectionIndex(); 136 int last = sourceFolders.getSelectionModel().getMaxSelectionIndex(); 137 upFolder.setEnabled(first > 0); 138 downFolder.setEnabled(last > -1 && last < sourceFoldersModel.getRowCount()-1); 139 first = testFolders.getSelectionModel().getMinSelectionIndex(); 140 last = testFolders.getSelectionModel().getMaxSelectionIndex(); 141 upTestFolder.setEnabled(first > 0); 142 downTestFolder.setEnabled(last > -1 && last < testFoldersModel.getRowCount()-1); 143 } 144 145 private void updateSourceLevelCombo(String sourceLevelValue) { 146 if (sourceLevelValue.equals("1.3")) { sourceLevel.setSelectedIndex(0); 148 } else if (sourceLevelValue.equals("1.4")) { sourceLevel.setSelectedIndex(1); 150 } else if (sourceLevelValue.equals("1.5")) { sourceLevel.setSelectedIndex(2); 152 } else { 153 sourceLevel.addItem(sourceLevelValue); 155 sourceLevel.setSelectedIndex(3); 156 } 157 } 158 159 private String getSourceLevelValue(int index) { 160 switch (index) { 161 case 0: return "1.3"; case 1: return "1.4"; case 2: return "1.5"; default: return null; 165 } 166 } 167 168 173 private void initComponents() { 175 java.awt.GridBagConstraints gridBagConstraints; 176 177 jLabel1 = new javax.swing.JLabel (); 178 jLabel2 = new javax.swing.JLabel (); 179 jLabel3 = new javax.swing.JLabel (); 180 sourceLevel = new javax.swing.JComboBox (); 181 addFolder = new javax.swing.JButton (); 182 removeFolder = new javax.swing.JButton (); 183 jScrollPane1 = new javax.swing.JScrollPane (); 184 sourceFolders = new javax.swing.JTable (); 185 jScrollPane2 = new javax.swing.JScrollPane (); 186 testFolders = new javax.swing.JTable (); 187 jLabel4 = new javax.swing.JLabel (); 188 addTestFolder = new javax.swing.JButton (); 189 removeTestFolder = new javax.swing.JButton (); 190 upFolder = new javax.swing.JButton (); 191 downFolder = new javax.swing.JButton (); 192 downTestFolder = new javax.swing.JButton (); 193 upTestFolder = new javax.swing.JButton (); 194 projectFolderLabel = new javax.swing.JLabel (); 195 projectContentLabel = new javax.swing.JLabel (); 196 buildScriptLabel = new javax.swing.JLabel (); 197 projectFolder = new javax.swing.JTextField (); 198 contentFolder = new javax.swing.JTextField (); 199 buildScript = new javax.swing.JTextField (); 200 includesExcludesButton = new javax.swing.JButton (); 201 202 setMinimumSize(new java.awt.Dimension (200, 100)); 203 setPreferredSize(new java.awt.Dimension (247, 251)); 204 setLayout(new java.awt.GridBagLayout ()); 205 206 jLabel1.setLabelFor(this); 207 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_jLabel1")); gridBagConstraints = new java.awt.GridBagConstraints (); 209 gridBagConstraints.gridx = 0; 210 gridBagConstraints.gridy = 3; 211 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 212 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 213 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 214 gridBagConstraints.weightx = 1.0; 215 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 216 add(jLabel1, gridBagConstraints); 217 jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_jLabel1")); 219 jLabel2.setLabelFor(sourceFolders); 220 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_jLabel2")); gridBagConstraints = new java.awt.GridBagConstraints (); 222 gridBagConstraints.gridx = 0; 223 gridBagConstraints.gridy = 4; 224 gridBagConstraints.gridwidth = 2; 225 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 226 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 227 add(jLabel2, gridBagConstraints); 228 jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_jLabel2")); 230 jLabel3.setLabelFor(sourceLevel); 231 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_jLabel3")); gridBagConstraints = new java.awt.GridBagConstraints (); 233 gridBagConstraints.gridx = 0; 234 gridBagConstraints.gridy = 14; 235 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 236 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 6); 237 add(jLabel3, gridBagConstraints); 238 jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_jLabel3")); 240 sourceLevel.addItemListener(new java.awt.event.ItemListener () { 241 public void itemStateChanged(java.awt.event.ItemEvent evt) { 242 sourceLevelItemStateChanged(evt); 243 } 244 }); 245 gridBagConstraints = new java.awt.GridBagConstraints (); 246 gridBagConstraints.gridx = 1; 247 gridBagConstraints.gridy = 14; 248 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 249 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 250 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 251 add(sourceLevel, gridBagConstraints); 252 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle"); sourceLevel.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_sourceLevel")); 255 org.openide.awt.Mnemonics.setLocalizedText(addFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_addFolder")); addFolder.addActionListener(new java.awt.event.ActionListener () { 257 public void actionPerformed(java.awt.event.ActionEvent evt) { 258 addFolderActionPerformed(evt); 259 } 260 }); 261 gridBagConstraints = new java.awt.GridBagConstraints (); 262 gridBagConstraints.gridx = 2; 263 gridBagConstraints.gridy = 5; 264 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 265 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 266 add(addFolder, gridBagConstraints); 267 addFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_addFolder")); 269 org.openide.awt.Mnemonics.setLocalizedText(removeFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_removeFolder")); removeFolder.addActionListener(new java.awt.event.ActionListener () { 271 public void actionPerformed(java.awt.event.ActionEvent evt) { 272 removeFolderActionPerformed(evt); 273 } 274 }); 275 gridBagConstraints = new java.awt.GridBagConstraints (); 276 gridBagConstraints.gridx = 2; 277 gridBagConstraints.gridy = 6; 278 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 279 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 280 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 281 add(removeFolder, gridBagConstraints); 282 removeFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_removeFolder")); 284 jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); 285 jScrollPane1.setViewportView(sourceFolders); 286 sourceFolders.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_sourceFolders")); 288 gridBagConstraints = new java.awt.GridBagConstraints (); 289 gridBagConstraints.gridx = 0; 290 gridBagConstraints.gridy = 5; 291 gridBagConstraints.gridwidth = 2; 292 gridBagConstraints.gridheight = 4; 293 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 294 gridBagConstraints.weightx = 1.0; 295 gridBagConstraints.weighty = 1.0; 296 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 297 add(jScrollPane1, gridBagConstraints); 298 jScrollPane1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_jScrollPanel1")); 300 jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); 301 jScrollPane2.setViewportView(testFolders); 302 testFolders.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_SourceFoldersPanel_testFolders")); 304 gridBagConstraints = new java.awt.GridBagConstraints (); 305 gridBagConstraints.gridx = 0; 306 gridBagConstraints.gridy = 10; 307 gridBagConstraints.gridwidth = 2; 308 gridBagConstraints.gridheight = 4; 309 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 310 gridBagConstraints.weightx = 1.0; 311 gridBagConstraints.weighty = 1.0; 312 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 313 add(jScrollPane2, gridBagConstraints); 314 jScrollPane2.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_jScrollPane2")); 316 jLabel4.setLabelFor(testFolders); 317 org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_TestSourceFoldersPanel")); gridBagConstraints = new java.awt.GridBagConstraints (); 319 gridBagConstraints.gridx = 0; 320 gridBagConstraints.gridy = 9; 321 gridBagConstraints.gridwidth = 2; 322 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 323 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 324 add(jLabel4, gridBagConstraints); 325 326 org.openide.awt.Mnemonics.setLocalizedText(addTestFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_addTestFolder")); addTestFolder.addActionListener(new java.awt.event.ActionListener () { 328 public void actionPerformed(java.awt.event.ActionEvent evt) { 329 addTestFolderActionPerformed(evt); 330 } 331 }); 332 gridBagConstraints = new java.awt.GridBagConstraints (); 333 gridBagConstraints.gridx = 2; 334 gridBagConstraints.gridy = 10; 335 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 336 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 337 add(addTestFolder, gridBagConstraints); 338 addTestFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_addTestFolder")); 340 org.openide.awt.Mnemonics.setLocalizedText(removeTestFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_removeTestFolder")); removeTestFolder.addActionListener(new java.awt.event.ActionListener () { 342 public void actionPerformed(java.awt.event.ActionEvent evt) { 343 removeTestFolderActionPerformed(evt); 344 } 345 }); 346 gridBagConstraints = new java.awt.GridBagConstraints (); 347 gridBagConstraints.gridx = 2; 348 gridBagConstraints.gridy = 11; 349 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 350 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 351 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 352 add(removeTestFolder, gridBagConstraints); 353 removeTestFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_removeTestFolder")); 355 org.openide.awt.Mnemonics.setLocalizedText(upFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_upFolder")); upFolder.addActionListener(new java.awt.event.ActionListener () { 357 public void actionPerformed(java.awt.event.ActionEvent evt) { 358 upFolderActionPerformed(evt); 359 } 360 }); 361 gridBagConstraints = new java.awt.GridBagConstraints (); 362 gridBagConstraints.gridx = 2; 363 gridBagConstraints.gridy = 7; 364 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 365 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 366 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 367 add(upFolder, gridBagConstraints); 368 upFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_upFolder")); 370 org.openide.awt.Mnemonics.setLocalizedText(downFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_downFolder")); downFolder.addActionListener(new java.awt.event.ActionListener () { 372 public void actionPerformed(java.awt.event.ActionEvent evt) { 373 downFolderActionPerformed(evt); 374 } 375 }); 376 gridBagConstraints = new java.awt.GridBagConstraints (); 377 gridBagConstraints.gridx = 2; 378 gridBagConstraints.gridy = 8; 379 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 380 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 381 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 382 add(downFolder, gridBagConstraints); 383 downFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_downFolder")); 385 org.openide.awt.Mnemonics.setLocalizedText(downTestFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_downTestFolder")); downTestFolder.addActionListener(new java.awt.event.ActionListener () { 387 public void actionPerformed(java.awt.event.ActionEvent evt) { 388 downTestFolderActionPerformed(evt); 389 } 390 }); 391 gridBagConstraints = new java.awt.GridBagConstraints (); 392 gridBagConstraints.gridx = 2; 393 gridBagConstraints.gridy = 13; 394 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 395 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 396 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 397 add(downTestFolder, gridBagConstraints); 398 downTestFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_downTestFolder")); 400 org.openide.awt.Mnemonics.setLocalizedText(upTestFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_upTestFolder")); upTestFolder.addActionListener(new java.awt.event.ActionListener () { 402 public void actionPerformed(java.awt.event.ActionEvent evt) { 403 upTestFolderActionPerformed(evt); 404 } 405 }); 406 gridBagConstraints = new java.awt.GridBagConstraints (); 407 gridBagConstraints.gridx = 2; 408 gridBagConstraints.gridy = 12; 409 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 410 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 411 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 412 add(upTestFolder, gridBagConstraints); 413 upTestFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_upTestFolder")); 415 projectFolderLabel.setLabelFor(projectFolder); 416 org.openide.awt.Mnemonics.setLocalizedText(projectFolderLabel, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_ProjFolderLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 418 gridBagConstraints.gridx = 0; 419 gridBagConstraints.gridy = 0; 420 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 421 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 422 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 423 add(projectFolderLabel, gridBagConstraints); 424 425 projectContentLabel.setLabelFor(contentFolder); 426 org.openide.awt.Mnemonics.setLocalizedText(projectContentLabel, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_ProjContentLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 428 gridBagConstraints.gridx = 0; 429 gridBagConstraints.gridy = 1; 430 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 431 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 432 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 433 add(projectContentLabel, gridBagConstraints); 434 435 buildScriptLabel.setLabelFor(buildScript); 436 org.openide.awt.Mnemonics.setLocalizedText(buildScriptLabel, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_BuildScriptLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 438 gridBagConstraints.gridx = 0; 439 gridBagConstraints.gridy = 2; 440 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 441 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 442 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 6); 443 add(buildScriptLabel, gridBagConstraints); 444 445 projectFolder.setEditable(false); 446 gridBagConstraints = new java.awt.GridBagConstraints (); 447 gridBagConstraints.gridx = 1; 448 gridBagConstraints.gridy = 0; 449 gridBagConstraints.gridwidth = 2; 450 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 451 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 452 add(projectFolder, gridBagConstraints); 453 projectFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_SourceFoldersPanel_projectFolder")); 455 contentFolder.setEditable(false); 456 gridBagConstraints = new java.awt.GridBagConstraints (); 457 gridBagConstraints.gridx = 1; 458 gridBagConstraints.gridy = 1; 459 gridBagConstraints.gridwidth = 2; 460 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 461 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 462 add(contentFolder, gridBagConstraints); 463 contentFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_SourceFoldersPanel_contentFolder")); 465 buildScript.setEditable(false); 466 gridBagConstraints = new java.awt.GridBagConstraints (); 467 gridBagConstraints.gridx = 1; 468 gridBagConstraints.gridy = 2; 469 gridBagConstraints.gridwidth = 2; 470 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 471 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 472 add(buildScript, gridBagConstraints); 473 buildScript.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_SourceFoldersPanel_buildScript")); 475 org.openide.awt.Mnemonics.setLocalizedText(includesExcludesButton, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "SourceFoldersPanel.includesExcludesButton.text")); includesExcludesButton.addActionListener(new java.awt.event.ActionListener () { 477 public void actionPerformed(java.awt.event.ActionEvent evt) { 478 includesExcludesButtonActionPerformed(evt); 479 } 480 }); 481 gridBagConstraints = new java.awt.GridBagConstraints (); 482 gridBagConstraints.gridx = 2; 483 gridBagConstraints.gridy = 14; 484 add(includesExcludesButton, gridBagConstraints); 485 } 487 private void includesExcludesButtonActionPerformed(java.awt.event.ActionEvent evt) { IncludeExcludeVisualizer v = new IncludeExcludeVisualizer(); 490 List <File > roots = new ArrayList <File >(); 491 for (JavaProjectGenerator.SourceFolder folder : model.getSourceFolders()) { 492 v.setIncludePattern(folder.includes != null ? folder.includes : "**"); 493 v.setExcludePattern(folder.excludes != null ? folder.excludes : ""); 494 roots.add(Util.resolveFile(model.getEvaluator(), model.getNBProjectFolder(), folder.location)); 495 } 496 v.setRoots(roots.toArray(new File [roots.size()])); 497 DialogDescriptor dd = new DialogDescriptor(v.getVisualizerPanel(), 498 NbBundle.getMessage(SourceFoldersPanel.class, "SourceFoldersPanel.title.includeExclude")); 499 dd.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); 500 if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dd))) { 501 for (JavaProjectGenerator.SourceFolder folder : model.getSourceFolders()) { 502 folder.includes = v.getIncludePattern().equals("**") ? null : v.getIncludePattern(); 503 folder.excludes = v.getExcludePattern().equals("") ? null : v.getExcludePattern(); 504 } 505 } 506 } 508 private void downTestFolderActionPerformed(java.awt.event.ActionEvent evt) { int[] indeces = testFolders.getSelectedRows(); 510 if (indeces.length == 0) { 511 return; 512 } 513 for (int i=indeces.length-1; i>=0; i--) { 514 int fromIndex = calcRealSourceIndex(indeces[i], true); 515 model.moveSourceFolder(fromIndex, fromIndex+1); 516 } 517 testFoldersModel.fireTableDataChanged(); 518 testFolders.getSelectionModel().clearSelection(); 519 for (int i=0; i<indeces.length; i++) { 520 testFolders.getSelectionModel().addSelectionInterval (indeces[i]+1, indeces[i]+1); 521 } 522 } 524 private void upTestFolderActionPerformed(java.awt.event.ActionEvent evt) { int[] indeces = testFolders.getSelectedRows(); 526 if (indeces.length == 0) { 527 return; 528 } 529 for (int i=0; i < indeces.length; i++) { 530 int fromIndex = calcRealSourceIndex(indeces[i], true); 531 model.moveSourceFolder(fromIndex, fromIndex-1); 532 } 533 testFoldersModel.fireTableDataChanged(); 534 testFolders.getSelectionModel().clearSelection(); 535 for (int i=0; i<indeces.length; i++) { 536 testFolders.getSelectionModel().addSelectionInterval (indeces[i]-1, indeces[i]-1); 537 } 538 } 540 private void downFolderActionPerformed(java.awt.event.ActionEvent evt) { int[] indeces = sourceFolders.getSelectedRows(); 542 if (indeces.length == 0) { 543 return; 544 } 545 for (int i=indeces.length-1; i>=0; i--) { 546 int fromIndex = calcRealSourceIndex(indeces[i], false); 547 model.moveSourceFolder(fromIndex, fromIndex+1); 548 } 549 sourceFoldersModel.fireTableDataChanged(); 550 sourceFolders.getSelectionModel().clearSelection(); 551 for (int i=0; i<indeces.length; i++) { 552 sourceFolders.getSelectionModel().addSelectionInterval (indeces[i]+1, indeces[i]+1); 553 } 554 } 556 private void upFolderActionPerformed(java.awt.event.ActionEvent evt) { int[] indeces = sourceFolders.getSelectedRows(); 558 if (indeces.length == 0) { 559 return; 560 } 561 for (int i=0; i < indeces.length; i++) { 562 int fromIndex = calcRealSourceIndex(indeces[i], false); 563 model.moveSourceFolder(fromIndex, fromIndex-1); 564 } 565 sourceFoldersModel.fireTableDataChanged(); 566 sourceFolders.getSelectionModel().clearSelection(); 567 for (int i=0; i<indeces.length; i++) { 568 sourceFolders.getSelectionModel().addSelectionInterval (indeces[i]-1, indeces[i]-1); 569 } 570 } 572 private void removeTestFolderActionPerformed(java.awt.event.ActionEvent evt) { int[] indeces = testFolders.getSelectedRows(); 574 if (indeces.length == 0) { 575 return; 576 } 577 for (int i = indeces.length-1; i>=0; i--) { 578 String location = getItem(indeces[i], true).location; 579 model.removeSourceFolder(calcRealSourceIndex(indeces[i], true)); 580 } 581 testFoldersModel.fireTableDataChanged(); 582 if (listener != null) { 583 listener.stateChanged(null); 584 } 585 updateButtons(); 586 } 588 private void addTestFolderActionPerformed(java.awt.event.ActionEvent evt) { doAddFolderActionPerformed(evt, true); 590 } 592 private void sourceLevelItemStateChanged(java.awt.event.ItemEvent evt) { if (sourceLevel.getSelectedIndex() != -1 && model != null) { 594 String sl = getSourceLevelValue(sourceLevel.getSelectedIndex()); 595 if (sl == null) { 596 sl = (String )sourceLevel.getSelectedItem(); 597 } 598 model.setSourceLevel(sl); 599 } 600 } 602 private void removeFolderActionPerformed(java.awt.event.ActionEvent evt) { int[] indeces = sourceFolders.getSelectedRows(); 604 if (indeces.length == 0) { 605 return; 606 } 607 for (int i = indeces.length - 1; i>=0; i--) { 608 String location = getItem(indeces[i], false).location; 609 model.removeSourceFolder(calcRealSourceIndex(indeces[i], false)); 610 } 611 sourceFoldersModel.fireTableDataChanged(); 612 if (listener != null) { 613 listener.stateChanged(null); 614 } 615 updateButtons(); 616 } 618 private void addFolderActionPerformed(java.awt.event.ActionEvent evt) { doAddFolderActionPerformed(evt, false); 620 } 622 private void doAddFolderActionPerformed(java.awt.event.ActionEvent evt, boolean isTests) { 623 JFileChooser chooser = new JFileChooser (); 624 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 625 chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); 626 if (model.getBaseFolder() != null) { 627 File files[] = model.getBaseFolder().listFiles(); 628 if (files != null && files.length > 0) { 629 chooser.setSelectedFile(files[0]); 630 } else { 631 chooser.setSelectedFile(model.getBaseFolder()); 632 } 633 } 634 if (isTests) { 635 chooser.setDialogTitle(NbBundle.getMessage(SourceFoldersPanel.class, "LBL_Browse_Test_Folder")); 636 } else { 637 chooser.setDialogTitle(NbBundle.getMessage(SourceFoldersPanel.class, "LBL_Browse_Source_Folder")); 638 } 639 chooser.setMultiSelectionEnabled(true); 640 if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { 641 File files[] = chooser.getSelectedFiles(); 642 Set <File > invalidRoots = processRoots(model, files, isTests, isWizard); 643 if (isTests) { 644 testFoldersModel.fireTableDataChanged(); 645 } else { 646 sourceFoldersModel.fireTableDataChanged(); 647 } 648 if (listener != null) { 649 listener.stateChanged(null); 650 } 651 updateButtons(); 652 if (invalidRoots.size()>0) { 653 showInvalidRootsWarning (invalidRoots); 654 } 655 } 656 } 657 658 static Set <File > processRoots(ProjectModel model, File [] files, boolean isTests, boolean isWizard) { 659 Set <File > invalidRoots = new HashSet <File >(); 660 661 FILE: for (File file : files) { 662 File sourceLoc = FileUtil.normalizeFile(file); 663 String location = Util.relativizeLocation(model.getBaseFolder(), model.getNBProjectFolder(), sourceLoc); 664 Project p, thisProject = isWizard ? null : FileOwnerQuery.getOwner(model.getNBProjectFolder().toURI()); 665 if ((p = FileOwnerQuery.getOwner(sourceLoc.toURI())) != null && (thisProject == null || !thisProject.equals(p)) && !isParentOf(model.getNBProjectFolder(), sourceLoc) && !isParentOf(model.getBaseFolder(), sourceLoc)) { 666 invalidRoots.add(sourceLoc); 667 } else { 668 List <JavaProjectGenerator.SourceFolder> sourceFolders = model.getSourceFolders(); 669 for (JavaProjectGenerator.SourceFolder sf : sourceFolders) { 670 if (location.equals(sf.location)) { 671 if ((isTests && !model.isTestSourceFolder(sf)) 672 || (!isTests && model.isTestSourceFolder(sf))) { 673 invalidRoots.add(sourceLoc); 674 } 675 continue FILE; 676 } 677 } 678 679 JavaProjectGenerator.SourceFolder sf = new JavaProjectGenerator.SourceFolder(); 680 sf.location = location; 681 sf.type = ProjectModel.TYPE_JAVA; 682 sf.style = JavaProjectNature.STYLE_PACKAGES; 683 sf.label = getDefaultLabel(sf.location, isTests); 684 if (!sourceFolders.isEmpty()) { 685 JavaProjectGenerator.SourceFolder prototype = sourceFolders.iterator().next(); 686 sf.includes = prototype.includes; 687 sf.excludes = prototype.excludes; 688 } 689 model.addSourceFolder(sf, isTests); 690 } 691 } 692 693 return invalidRoots; 694 } 695 696 private static boolean isParentOf(File parent, File child) { 697 while (child != null && !child.equals(parent)) 698 child = child.getParentFile(); 699 700 return child != null && child.equals(parent); 701 } 702 703 private void showInvalidRootsWarning (Set <File > invalidRoots) { 704 JButton closeOption = new JButton (NbBundle.getMessage(SourceFoldersPanel.class,"CTL_SourceFolderPanel_Close")); 705 closeOption.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(SourceFoldersPanel.class,"AD_SourceFolderPanel_Close")); 706 JPanel warning = new WarningDlg (invalidRoots); 707 String message = NbBundle.getMessage(SourceFoldersPanel.class,"MSG_InvalidRoot"); 708 JOptionPane optionPane = new JOptionPane (new Object [] {message, warning}, 709 JOptionPane.WARNING_MESSAGE, 710 0, 711 null, 712 new Object [0], 713 null); 714 optionPane.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(SourceFoldersPanel.class,"AD_InvalidRootDlg")); 715 DialogDescriptor dd = new DialogDescriptor (optionPane, 716 NbBundle.getMessage(SourceFoldersPanel.class,"TITLE_InvalidRoot"), 717 true, 718 new Object [] { 719 closeOption, 720 }, 721 closeOption, 722 DialogDescriptor.DEFAULT_ALIGN, 723 null, 724 null); 725 DialogDisplayer.getDefault().notify(dd); 726 } 727 728 static String getDefaultLabel(String location, boolean isTests) { 729 if (location.equals(".") || ProjectConstants.PROJECT_LOCATION_PREFIX.equals(location + "/")) { return isTests ? 732 NbBundle.getMessage(SourceFoldersPanel.class, "LBL_default_test_packages") : 733 NbBundle.getMessage(SourceFoldersPanel.class, "LBL_default_source_packages"); 734 } 735 String relloc = location; 737 if (relloc.startsWith(ProjectConstants.PROJECT_LOCATION_PREFIX)) { 738 relloc = relloc.substring(ProjectConstants.PROJECT_LOCATION_PREFIX.length()); 739 } 740 return relloc.replace('/', File.separatorChar); } 742 743 747 public static String getLocationDisplayName(PropertyEvaluator evaluator, File base, String val) { 748 File f = Util.resolveFile(evaluator, base, val); 749 if (f == null) { 750 return val; 751 } 752 String location = f.getAbsolutePath(); 753 if (CollocationQuery.areCollocated(base, f)) { 754 location = PropertyUtils.relativizeFile(base, f).replace('/', File.separatorChar); } 756 return location; 757 } 758 759 private JavaProjectGenerator.SourceFolder getItem(int index, boolean tests) { 760 return model.getSourceFolder(calcRealSourceIndex(index, tests)); 761 } 762 763 private int calcRealSourceIndex(int index, boolean tests) { 764 int realIndex = 0; 765 for (int i=0; i<model.getSourceFoldersCount(); i++) { 766 JavaProjectGenerator.SourceFolder sf = model.getSourceFolder(i); 767 boolean isTest = model.isTestSourceFolder(sf); 768 if (tests && !isTest) { 769 continue; 770 } 771 if (!tests && isTest) { 772 continue; 773 } 774 if (index == realIndex) { 775 return i; 776 } 777 realIndex++; 778 } 779 throw new ArrayIndexOutOfBoundsException ("index="+index+" tests="+tests+" realIndex="+realIndex); 780 } 781 782 783 public boolean hasSomeSourceFolder() { 784 return model.getSourceFoldersCount() > 0; 785 } 786 787 private javax.swing.JButton addFolder; 789 private javax.swing.JButton addTestFolder; 790 private javax.swing.JTextField buildScript; 791 private javax.swing.JLabel buildScriptLabel; 792 private javax.swing.JTextField contentFolder; 793 private javax.swing.JButton downFolder; 794 private javax.swing.JButton downTestFolder; 795 private javax.swing.JButton includesExcludesButton; 796 private javax.swing.JLabel jLabel1; 797 private javax.swing.JLabel jLabel2; 798 private javax.swing.JLabel jLabel3; 799 private javax.swing.JLabel jLabel4; 800 private javax.swing.JScrollPane jScrollPane1; 801 private javax.swing.JScrollPane jScrollPane2; 802 private javax.swing.JLabel projectContentLabel; 803 private javax.swing.JTextField projectFolder; 804 private javax.swing.JLabel projectFolderLabel; 805 private javax.swing.JButton removeFolder; 806 private javax.swing.JButton removeTestFolder; 807 private javax.swing.JTable sourceFolders; 808 private javax.swing.JComboBox sourceLevel; 809 private javax.swing.JTable testFolders; 810 private javax.swing.JButton upFolder; 811 private javax.swing.JButton upTestFolder; 812 814 public void setModel(ProjectModel model, AntProjectHelper projectHelper) { 815 this.model = model; 816 updateSourceLevelCombo(model.getSourceLevel()); 817 updateButtons(); 818 sourceFoldersModel.fireTableDataChanged(); 819 if (!isWizard) { 820 projectFolder.setText(FileUtil.getFileDisplayName(projectHelper.getProjectDirectory())); 821 contentFolder.setText(model.getBaseFolder().getAbsolutePath()); 822 FileObject fo = getAntScript(projectHelper, model.getEvaluator()); 823 if (fo != null) { 824 buildScript.setText(FileUtil.getFileDisplayName(fo)); 825 } 826 } 827 } 828 829 private static FileObject getAntScript(AntProjectHelper helper, PropertyEvaluator ev) { 831 String antScript = ev.getProperty(ProjectConstants.PROP_ANT_SCRIPT); 833 if (antScript != null) { 834 File f= helper.resolveFile(antScript); 835 if (!f.exists()) { 836 return null; 837 } 838 FileObject fo = FileUtil.toFileObject(f); 839 return fo; 840 } else { 841 FileObject fo = helper.getProjectDirectory().getFileObject("build.xml"); return fo; 843 } 844 } 845 846 private class SourcesModel extends AbstractTableModel { 847 848 private boolean tests; 849 850 public SourcesModel(boolean tests) { 851 this.tests = tests; 852 } 853 854 public int getColumnCount() { 855 return isWizard ? 1 : 2; 856 } 857 858 public String getColumnName(int column) { 859 switch (column) { 860 case 0: return org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_Package"); 861 default: return org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_Label"); 862 } 863 } 864 865 public int getRowCount() { 866 if (model == null) 867 return 0; 868 int count = 0; 869 for (int i=0; i<model.getSourceFoldersCount(); i++) { 870 JavaProjectGenerator.SourceFolder sf = model.getSourceFolder(i); 871 boolean isTest = model.isTestSourceFolder(sf); 872 if (tests && isTest) { 873 count++; 874 } 875 if (!tests && !isTest) { 876 count++; 877 } 878 } 879 return count; 880 } 881 882 public Object getValueAt(int rowIndex, int columnIndex) { 883 if (columnIndex == 0) { 884 String loc = getItem(rowIndex, tests).location; 885 loc = getLocationDisplayName(model.getEvaluator(), model.getNBProjectFolder(), loc); 886 return loc; 887 } else { 888 return getItem(rowIndex, tests).label; 889 } 890 } 891 892 public boolean isCellEditable(int row, int column) { 893 if (column == 1) { 894 return true; 895 } else { 896 return false; 897 } 898 } 899 900 public Class getColumnClass(int column) { 901 return String .class; 902 } 903 904 public void setValueAt(Object val, int rowIndex, int columnIndex) { 905 JavaProjectGenerator.SourceFolder sf = getItem(rowIndex, tests); 906 sf.label = (String )val; 907 if (sf.label.length() == 0) { 908 sf.label = getDefaultLabel(sf.location, tests); 909 } 910 } 911 912 } 913 914 private class ToolTipRenderer extends DefaultTableCellRenderer { 915 916 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row, int column) { 917 Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 918 if (c instanceof JComponent ) { 919 ((JComponent ) c).setToolTipText ((String )value); 920 } 921 return c; 922 } 923 924 } 925 926 private static class WarningDlg extends JPanel { 927 928 public WarningDlg (Set invalidRoots) { 929 this.initGui (invalidRoots); 930 } 931 932 private void initGui (Set invalidRoots) { 933 setLayout( new GridBagLayout ()); 934 JLabel label = new JLabel (); 935 org.openide.awt.Mnemonics.setLocalizedText(label, NbBundle.getMessage(SourceFoldersPanel.class,"LBL_InvalidRoot")); 936 GridBagConstraints c = new GridBagConstraints (); 937 c.gridx = GridBagConstraints.RELATIVE; 938 c.gridy = GridBagConstraints.RELATIVE; 939 c.gridwidth = GridBagConstraints.REMAINDER; 940 c.fill = GridBagConstraints.HORIZONTAL; 941 c.anchor = GridBagConstraints.NORTHWEST; 942 c.weightx = 1.0; 943 c.insets = new Insets (12,0,6,0); 944 ((GridBagLayout )this.getLayout()).setConstraints(label,c); 945 this.add (label); 946 JList roots = new JList (invalidRoots.toArray()); 947 roots.setCellRenderer (new InvalidRootRenderer(true)); 948 JScrollPane p = new JScrollPane (roots); 949 c = new GridBagConstraints (); 950 c.gridx = GridBagConstraints.RELATIVE; 951 c.gridy = GridBagConstraints.RELATIVE; 952 c.gridwidth = GridBagConstraints.REMAINDER; 953 c.fill = GridBagConstraints.BOTH; 954 c.anchor = GridBagConstraints.NORTHWEST; 955 c.weightx = c.weighty = 1.0; 956 c.insets = new Insets (0,0,12,0); 957 ((GridBagLayout )this.getLayout()).setConstraints(p,c); 958 this.add (p); 959 label.setLabelFor(roots); 960 roots.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(SourceFoldersPanel.class,"AD_InvalidRoot")); 961 JLabel label2 = new JLabel (); 962 label2.setText (NbBundle.getMessage(SourceFoldersPanel.class,"MSG_InvalidRoot2")); 963 c = new GridBagConstraints (); 964 c.gridx = GridBagConstraints.RELATIVE; 965 c.gridy = GridBagConstraints.RELATIVE; 966 c.gridwidth = GridBagConstraints.REMAINDER; 967 c.fill = GridBagConstraints.HORIZONTAL; 968 c.anchor = GridBagConstraints.NORTHWEST; 969 c.weightx = 1.0; 970 c.insets = new Insets (0,0,0,0); 971 ((GridBagLayout )this.getLayout()).setConstraints(label2,c); 972 this.add (label2); 973 } 974 975 private static class InvalidRootRenderer extends DefaultListCellRenderer { 976 977 private boolean projectConflict; 978 979 public InvalidRootRenderer (boolean projectConflict) { 980 this.projectConflict = projectConflict; 981 } 982 983 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 984 File f = (File ) value; 985 String message = f.getAbsolutePath(); 986 if (projectConflict) { 987 Project p = FileOwnerQuery.getOwner(f.toURI()); 988 if (p!=null) { 989 ProjectInformation pi = ProjectUtils.getInformation(p); 990 String projectName = pi.getDisplayName(); 991 message = NbBundle.getMessage(SourceFoldersPanel.class,"TXT_RootOwnedByProject", message, projectName); 992 } 993 } 994 return super.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus); 995 } 996 } 997 } 998 999 } 1000 | Popular Tags |