KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > ui > SourceFoldersPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.freeform.ui;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.GridBagConstraints JavaDoc;
24 import java.awt.GridBagLayout JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.io.File JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Set JavaDoc;
31 import javax.swing.DefaultListCellRenderer JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JFileChooser JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36 import javax.swing.JList JavaDoc;
37 import javax.swing.JOptionPane JavaDoc;
38 import javax.swing.JPanel JavaDoc;
39 import javax.swing.JScrollPane JavaDoc;
40 import javax.swing.JTable JavaDoc;
41 import javax.swing.event.ChangeListener JavaDoc;
42 import javax.swing.event.ListSelectionEvent JavaDoc;
43 import javax.swing.event.ListSelectionListener JavaDoc;
44 import javax.swing.table.AbstractTableModel JavaDoc;
45 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
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 /**
68  * Wizard panel which lets user select source and test package roots and source level.
69  * Also shows some other info.
70  * @author David Konecny
71  */

72 public class SourceFoldersPanel extends JPanel JavaDoc implements HelpCtx.Provider, ListSelectionListener JavaDoc {
73     
74     private SourcesModel sourceFoldersModel;
75     private SourcesModel testFoldersModel;
76     private ChangeListener JavaDoc listener;
77     private boolean isWizard;
78     private ProjectModel model;
79
80     /** Creates new form SourceFoldersPanel */
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 JavaDoc.class, new ToolTipRenderer ());
96         testFolders.getTableHeader().setReorderingAllowed(false);
97         testFolders.setDefaultRenderer(String JavaDoc.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     /** WizardDescriptor.Panel can set one change listener
113      * to be notified about changes in the panel. */

114     public void setChangeListener(ChangeListener JavaDoc listener) {
115         this.listener = listener;
116     }
117     
118     private void initSourceLevel() {
119         sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK13")); // NOI18N
120
sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK14")); // NOI18N
121
sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK15")); // NOI18N
122
}
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 JavaDoc 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 JavaDoc sourceLevelValue) {
146         if (sourceLevelValue.equals("1.3")) { // NOI18N
147
sourceLevel.setSelectedIndex(0);
148         } else if (sourceLevelValue.equals("1.4")) { // NOI18N
149
sourceLevel.setSelectedIndex(1);
150         } else if (sourceLevelValue.equals("1.5")) { // NOI18N
151
sourceLevel.setSelectedIndex(2);
152         } else {
153             // user specified some other value in project.xml
154
sourceLevel.addItem(sourceLevelValue);
155             sourceLevel.setSelectedIndex(3);
156         }
157     }
158     
159     private String JavaDoc getSourceLevelValue(int index) {
160         switch (index) {
161             case 0: return "1.3"; // NOI18N
162
case 1: return "1.4"; // NOI18N
163
case 2: return "1.5"; // NOI18N
164
default: return null;
165         }
166     }
167     
168     /** This method is called from within the constructor to
169      * initialize the form.
170      * WARNING: Do NOT modify this code. The content of this method is
171      * always regenerated by the Form Editor.
172      */

173     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
174
private void initComponents() {
175         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
176
177         jLabel1 = new javax.swing.JLabel JavaDoc();
178         jLabel2 = new javax.swing.JLabel JavaDoc();
179         jLabel3 = new javax.swing.JLabel JavaDoc();
180         sourceLevel = new javax.swing.JComboBox JavaDoc();
181         addFolder = new javax.swing.JButton JavaDoc();
182         removeFolder = new javax.swing.JButton JavaDoc();
183         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
184         sourceFolders = new javax.swing.JTable JavaDoc();
185         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
186         testFolders = new javax.swing.JTable JavaDoc();
187         jLabel4 = new javax.swing.JLabel JavaDoc();
188         addTestFolder = new javax.swing.JButton JavaDoc();
189         removeTestFolder = new javax.swing.JButton JavaDoc();
190         upFolder = new javax.swing.JButton JavaDoc();
191         downFolder = new javax.swing.JButton JavaDoc();
192         downTestFolder = new javax.swing.JButton JavaDoc();
193         upTestFolder = new javax.swing.JButton JavaDoc();
194         projectFolderLabel = new javax.swing.JLabel JavaDoc();
195         projectContentLabel = new javax.swing.JLabel JavaDoc();
196         buildScriptLabel = new javax.swing.JLabel JavaDoc();
197         projectFolder = new javax.swing.JTextField JavaDoc();
198         contentFolder = new javax.swing.JTextField JavaDoc();
199         buildScript = new javax.swing.JTextField JavaDoc();
200         includesExcludesButton = new javax.swing.JButton JavaDoc();
201
202         setMinimumSize(new java.awt.Dimension JavaDoc(200, 100));
203         setPreferredSize(new java.awt.Dimension JavaDoc(247, 251));
204         setLayout(new java.awt.GridBagLayout JavaDoc());
205
206         jLabel1.setLabelFor(this);
207         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_jLabel1")); // NOI18N
208
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 12, 0);
216         add(jLabel1, gridBagConstraints);
217         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_jLabel1")); // NOI18N
218

219         jLabel2.setLabelFor(sourceFolders);
220         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_jLabel2")); // NOI18N
221
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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")); // NOI18N
229

230         jLabel3.setLabelFor(sourceLevel);
231         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_jLabel3")); // NOI18N
232
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
233         gridBagConstraints.gridx = 0;
234         gridBagConstraints.gridy = 14;
235         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
236         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 6);
237         add(jLabel3, gridBagConstraints);
238         jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_jLabel3")); // NOI18N
239

240         sourceLevel.addItemListener(new java.awt.event.ItemListener JavaDoc() {
241             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
242                 sourceLevelItemStateChanged(evt);
243             }
244         });
245         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 0, 12);
251         add(sourceLevel, gridBagConstraints);
252         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle"); // NOI18N
253
sourceLevel.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_sourceLevel")); // NOI18N
254

255         org.openide.awt.Mnemonics.setLocalizedText(addFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_addFolder")); // NOI18N
256
addFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
257             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
258                 addFolderActionPerformed(evt);
259             }
260         });
261         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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")); // NOI18N
268

269         org.openide.awt.Mnemonics.setLocalizedText(removeFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_removeFolder")); // NOI18N
270
removeFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
271             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
272                 removeFolderActionPerformed(evt);
273             }
274         });
275         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 0, 0, 0);
281         add(removeFolder, gridBagConstraints);
282         removeFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_removeFolder")); // NOI18N
283

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")); // NOI18N
287

288         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 12, 12);
297         add(jScrollPane1, gridBagConstraints);
298         jScrollPane1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "ACSD_SourceFoldersPanel_jScrollPanel1")); // NOI18N
299

300         jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
301         jScrollPane2.setViewportView(testFolders);
302         testFolders.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_SourceFoldersPanel_testFolders")); // NOI18N
303

304         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 12, 12);
313         add(jScrollPane2, gridBagConstraints);
314         jScrollPane2.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_jScrollPane2")); // NOI18N
315

316         jLabel4.setLabelFor(testFolders);
317         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_TestSourceFoldersPanel")); // NOI18N
318
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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")); // NOI18N
327
addTestFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
328             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
329                 addTestFolderActionPerformed(evt);
330             }
331         });
332         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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")); // NOI18N
339

340         org.openide.awt.Mnemonics.setLocalizedText(removeTestFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_removeTestFolder")); // NOI18N
341
removeTestFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
342             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
343                 removeTestFolderActionPerformed(evt);
344             }
345         });
346         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 0, 0, 0);
352         add(removeTestFolder, gridBagConstraints);
353         removeTestFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_removeTestFolder")); // NOI18N
354

355         org.openide.awt.Mnemonics.setLocalizedText(upFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_upFolder")); // NOI18N
356
upFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
357             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
358                 upFolderActionPerformed(evt);
359             }
360         });
361         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 0, 0, 0);
367         add(upFolder, gridBagConstraints);
368         upFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_upFolder")); // NOI18N
369

370         org.openide.awt.Mnemonics.setLocalizedText(downFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_downFolder")); // NOI18N
371
downFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
372             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
373                 downFolderActionPerformed(evt);
374             }
375         });
376         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 0, 0, 0);
382         add(downFolder, gridBagConstraints);
383         downFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_downFolder")); // NOI18N
384

385         org.openide.awt.Mnemonics.setLocalizedText(downTestFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_downTestFolder")); // NOI18N
386
downTestFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
387             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
388                 downTestFolderActionPerformed(evt);
389             }
390         });
391         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 0, 0, 0);
397         add(downTestFolder, gridBagConstraints);
398         downTestFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_downTestFolder")); // NOI18N
399

400         org.openide.awt.Mnemonics.setLocalizedText(upTestFolder, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "BTN_SourceFoldersPanel_upTestFolder")); // NOI18N
401
upTestFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
402             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
403                 upTestFolderActionPerformed(evt);
404             }
405         });
406         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 0, 0, 0);
412         add(upTestFolder, gridBagConstraints);
413         upTestFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceFoldersPanel_upTestFolder")); // NOI18N
414

415         projectFolderLabel.setLabelFor(projectFolder);
416         org.openide.awt.Mnemonics.setLocalizedText(projectFolderLabel, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_ProjFolderLabel")); // NOI18N
417
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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")); // NOI18N
427
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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")); // NOI18N
437
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 12, 6);
443         add(buildScriptLabel, gridBagConstraints);
444
445         projectFolder.setEditable(false);
446         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 6, 0);
452         add(projectFolder, gridBagConstraints);
453         projectFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_SourceFoldersPanel_projectFolder")); // NOI18N
454

455         contentFolder.setEditable(false);
456         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 6, 0);
462         add(contentFolder, gridBagConstraints);
463         contentFolder.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_SourceFoldersPanel_contentFolder")); // NOI18N
464

465         buildScript.setEditable(false);
466         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 0, 12, 0);
472         add(buildScript, gridBagConstraints);
473         buildScript.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_SourceFoldersPanel_buildScript")); // NOI18N
474

475         org.openide.awt.Mnemonics.setLocalizedText(includesExcludesButton, org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "SourceFoldersPanel.includesExcludesButton.text")); // NOI18N
476
includesExcludesButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
477             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
478                 includesExcludesButtonActionPerformed(evt);
479             }
480         });
481         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
482         gridBagConstraints.gridx = 2;
483         gridBagConstraints.gridy = 14;
484         add(includesExcludesButton, gridBagConstraints);
485     }// </editor-fold>//GEN-END:initComponents
486

487 private void includesExcludesButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_includesExcludesButtonActionPerformed
488
// Assumes they all use the same include/exclude patterns. Close enough.
489
IncludeExcludeVisualizer v = new IncludeExcludeVisualizer();
490         List JavaDoc<File JavaDoc> roots = new ArrayList JavaDoc<File JavaDoc>();
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 JavaDoc[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     }//GEN-LAST:event_includesExcludesButtonActionPerformed
507

508     private void downTestFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_downTestFolderActionPerformed
509
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     }//GEN-LAST:event_downTestFolderActionPerformed
523

524     private void upTestFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_upTestFolderActionPerformed
525
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     }//GEN-LAST:event_upTestFolderActionPerformed
539

540     private void downFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_downFolderActionPerformed
541
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     }//GEN-LAST:event_downFolderActionPerformed
555

556     private void upFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_upFolderActionPerformed
557
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     }//GEN-LAST:event_upFolderActionPerformed
571

572     private void removeTestFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeTestFolderActionPerformed
573
int[] indeces = testFolders.getSelectedRows();
574         if (indeces.length == 0) {
575             return;
576         }
577         for (int i = indeces.length-1; i>=0; i--) {
578             String JavaDoc 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     }//GEN-LAST:event_removeTestFolderActionPerformed
587

588     private void addTestFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addTestFolderActionPerformed
589
doAddFolderActionPerformed(evt, true);
590     }//GEN-LAST:event_addTestFolderActionPerformed
591

592     private void sourceLevelItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_sourceLevelItemStateChanged
593
if (sourceLevel.getSelectedIndex() != -1 && model != null) {
594             String JavaDoc sl = getSourceLevelValue(sourceLevel.getSelectedIndex());
595             if (sl == null) {
596                 sl = (String JavaDoc)sourceLevel.getSelectedItem();
597             }
598             model.setSourceLevel(sl);
599         }
600     }//GEN-LAST:event_sourceLevelItemStateChanged
601

602     private void removeFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeFolderActionPerformed
603
int[] indeces = sourceFolders.getSelectedRows();
604         if (indeces.length == 0) {
605             return;
606         }
607         for (int i = indeces.length - 1; i>=0; i--) {
608             String JavaDoc 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     }//GEN-LAST:event_removeFolderActionPerformed
617

618     private void addFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addFolderActionPerformed
619
doAddFolderActionPerformed(evt, false);
620     }//GEN-LAST:event_addFolderActionPerformed
621

622     private void doAddFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt, boolean isTests) {
623         JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
624         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
625         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
626         if (model.getBaseFolder() != null) {
627             File JavaDoc 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 JavaDoc files[] = chooser.getSelectedFiles();
642             Set JavaDoc<File JavaDoc> 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     /*package private for tests*/static Set JavaDoc<File JavaDoc> processRoots(ProjectModel model, File JavaDoc[] files, boolean isTests, boolean isWizard) {
659         Set JavaDoc<File JavaDoc> invalidRoots = new HashSet JavaDoc<File JavaDoc>();
660         
661         FILE: for (File JavaDoc file : files) {
662             File JavaDoc sourceLoc = FileUtil.normalizeFile(file);
663             String JavaDoc 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 JavaDoc<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 JavaDoc parent, File JavaDoc 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 JavaDoc<File JavaDoc> invalidRoots) {
704         JButton JavaDoc closeOption = new JButton JavaDoc (NbBundle.getMessage(SourceFoldersPanel.class,"CTL_SourceFolderPanel_Close"));
705         closeOption.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(SourceFoldersPanel.class,"AD_SourceFolderPanel_Close"));
706         JPanel JavaDoc warning = new WarningDlg (invalidRoots);
707         String JavaDoc message = NbBundle.getMessage(SourceFoldersPanel.class,"MSG_InvalidRoot");
708         JOptionPane JavaDoc optionPane = new JOptionPane JavaDoc (new Object JavaDoc[] {message, warning},
709             JOptionPane.WARNING_MESSAGE,
710             0,
711             null,
712             new Object JavaDoc[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 JavaDoc[] {
719                 closeOption,
720             },
721             closeOption,
722             DialogDescriptor.DEFAULT_ALIGN,
723             null,
724             null);
725         DialogDisplayer.getDefault().notify(dd);
726     }
727     
728     static String JavaDoc getDefaultLabel(String JavaDoc location, boolean isTests) {
729         if (location.equals(".") || ProjectConstants.PROJECT_LOCATION_PREFIX.equals(location + "/")) { // NOI18N
730
// #54428 - src dir *is* project dir, so use a more reasonable name.
731
return isTests ?
732                 NbBundle.getMessage(SourceFoldersPanel.class, "LBL_default_test_packages") :
733                 NbBundle.getMessage(SourceFoldersPanel.class, "LBL_default_source_packages");
734         }
735         // #47386 - remove "${project.dir}/" from label
736
String JavaDoc 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); // NOI18N // Fix for #45816 sourceLoc.getName();
741
}
742     
743     /**
744      * Convert given string value (e.g. "${project.dir}/src" to a file
745      * and try to relativize it.
746      */

747     public static String JavaDoc getLocationDisplayName(PropertyEvaluator evaluator, File JavaDoc base, String JavaDoc val) {
748         File JavaDoc f = Util.resolveFile(evaluator, base, val);
749         if (f == null) {
750             return val;
751         }
752         String JavaDoc location = f.getAbsolutePath();
753         if (CollocationQuery.areCollocated(base, f)) {
754             location = PropertyUtils.relativizeFile(base, f).replace('/', File.separatorChar); // NOI18N
755
}
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 JavaDoc("index="+index+" tests="+tests+" realIndex="+realIndex);
780     }
781
782     
783     public boolean hasSomeSourceFolder() {
784         return model.getSourceFoldersCount() > 0;
785     }
786     
787     // Variables declaration - do not modify//GEN-BEGIN:variables
788
private javax.swing.JButton JavaDoc addFolder;
789     private javax.swing.JButton JavaDoc addTestFolder;
790     private javax.swing.JTextField JavaDoc buildScript;
791     private javax.swing.JLabel JavaDoc buildScriptLabel;
792     private javax.swing.JTextField JavaDoc contentFolder;
793     private javax.swing.JButton JavaDoc downFolder;
794     private javax.swing.JButton JavaDoc downTestFolder;
795     private javax.swing.JButton JavaDoc includesExcludesButton;
796     private javax.swing.JLabel JavaDoc jLabel1;
797     private javax.swing.JLabel JavaDoc jLabel2;
798     private javax.swing.JLabel JavaDoc jLabel3;
799     private javax.swing.JLabel JavaDoc jLabel4;
800     private javax.swing.JScrollPane JavaDoc jScrollPane1;
801     private javax.swing.JScrollPane JavaDoc jScrollPane2;
802     private javax.swing.JLabel JavaDoc projectContentLabel;
803     private javax.swing.JTextField JavaDoc projectFolder;
804     private javax.swing.JLabel JavaDoc projectFolderLabel;
805     private javax.swing.JButton JavaDoc removeFolder;
806     private javax.swing.JButton JavaDoc removeTestFolder;
807     private javax.swing.JTable JavaDoc sourceFolders;
808     private javax.swing.JComboBox JavaDoc sourceLevel;
809     private javax.swing.JTable JavaDoc testFolders;
810     private javax.swing.JButton JavaDoc upFolder;
811     private javax.swing.JButton JavaDoc upTestFolder;
812     // End of variables declaration//GEN-END:variables
813

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     // XXX: this is copy of FreeformProjectGenerator.getAntScript
830
private static FileObject getAntScript(AntProjectHelper helper, PropertyEvaluator ev) {
831         //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
832
String JavaDoc antScript = ev.getProperty(ProjectConstants.PROP_ANT_SCRIPT);
833         if (antScript != null) {
834             File JavaDoc 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"); // NOI18N
842
return fo;
843         }
844     }
845
846     private class SourcesModel extends AbstractTableModel JavaDoc {
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 JavaDoc 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 JavaDoc getValueAt(int rowIndex, int columnIndex) {
883             if (columnIndex == 0) {
884                 String JavaDoc 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 JavaDoc getColumnClass(int column) {
901             return String JavaDoc.class;
902         }
903         
904         public void setValueAt(Object JavaDoc val, int rowIndex, int columnIndex) {
905             JavaProjectGenerator.SourceFolder sf = getItem(rowIndex, tests);
906             sf.label = (String JavaDoc)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 JavaDoc {
915         
916         public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value, boolean isSelected, boolean hasFocus,int row, int column) {
917             Component JavaDoc c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
918             if (c instanceof JComponent JavaDoc) {
919                 ((JComponent JavaDoc) c).setToolTipText ((String JavaDoc)value);
920             }
921             return c;
922         }
923         
924     }
925     
926     private static class WarningDlg extends JPanel JavaDoc {
927
928         public WarningDlg (Set JavaDoc invalidRoots) {
929             this.initGui (invalidRoots);
930         }
931
932         private void initGui (Set JavaDoc invalidRoots) {
933             setLayout( new GridBagLayout JavaDoc ());
934             JLabel JavaDoc label = new JLabel JavaDoc ();
935             org.openide.awt.Mnemonics.setLocalizedText(label, NbBundle.getMessage(SourceFoldersPanel.class,"LBL_InvalidRoot"));
936             GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
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 JavaDoc (12,0,6,0);
944             ((GridBagLayout JavaDoc)this.getLayout()).setConstraints(label,c);
945             this.add (label);
946             JList JavaDoc roots = new JList JavaDoc (invalidRoots.toArray());
947             roots.setCellRenderer (new InvalidRootRenderer(true));
948             JScrollPane JavaDoc p = new JScrollPane JavaDoc (roots);
949             c = new GridBagConstraints JavaDoc();
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 JavaDoc (0,0,12,0);
957             ((GridBagLayout JavaDoc)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 JavaDoc label2 = new JLabel JavaDoc ();
962             label2.setText (NbBundle.getMessage(SourceFoldersPanel.class,"MSG_InvalidRoot2"));
963             c = new GridBagConstraints JavaDoc();
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 JavaDoc (0,0,0,0);
971             ((GridBagLayout JavaDoc)this.getLayout()).setConstraints(label2,c);
972             this.add (label2);
973         }
974
975         private static class InvalidRootRenderer extends DefaultListCellRenderer JavaDoc {
976
977             private boolean projectConflict;
978
979             public InvalidRootRenderer (boolean projectConflict) {
980                 this.projectConflict = projectConflict;
981             }
982
983             public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
984                 File JavaDoc f = (File JavaDoc) value;
985                 String JavaDoc 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 JavaDoc 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