Source Code Cross Referenced for SourceFoldersPanel.java in  » IDE-Netbeans » java » org » netbeans » modules » java » freeform » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » java » org.netbeans.modules.java.freeform.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.java.freeform.ui;
0043:
0044:        import java.awt.Component;
0045:        import java.awt.GridBagConstraints;
0046:        import java.awt.GridBagLayout;
0047:        import java.awt.Insets;
0048:        import java.io.File;
0049:        import java.nio.charset.Charset;
0050:        import java.util.ArrayList;
0051:        import java.util.HashSet;
0052:        import java.util.List;
0053:        import java.util.Set;
0054:        import javax.swing.DefaultComboBoxModel;
0055:        import javax.swing.DefaultListCellRenderer;
0056:        import javax.swing.JButton;
0057:        import javax.swing.JComponent;
0058:        import javax.swing.JFileChooser;
0059:        import javax.swing.JLabel;
0060:        import javax.swing.JList;
0061:        import javax.swing.JOptionPane;
0062:        import javax.swing.JPanel;
0063:        import javax.swing.JScrollPane;
0064:        import javax.swing.JTable;
0065:        import javax.swing.ListCellRenderer;
0066:        import javax.swing.event.ChangeListener;
0067:        import javax.swing.event.ListSelectionEvent;
0068:        import javax.swing.event.ListSelectionListener;
0069:        import javax.swing.plaf.UIResource;
0070:        import javax.swing.table.AbstractTableModel;
0071:        import javax.swing.table.DefaultTableCellRenderer;
0072:        import org.netbeans.api.project.FileOwnerQuery;
0073:        import org.netbeans.api.project.Project;
0074:        import org.netbeans.api.project.ProjectInformation;
0075:        import org.netbeans.api.project.ProjectUtils;
0076:        import org.netbeans.api.queries.CollocationQuery;
0077:        import org.netbeans.api.queries.FileEncodingQuery;
0078:        import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
0079:        import org.netbeans.modules.ant.freeform.spi.support.Util;
0080:        import org.netbeans.modules.java.freeform.JavaProjectGenerator;
0081:        import org.netbeans.modules.java.freeform.JavaProjectNature;
0082:        import org.netbeans.spi.java.project.support.ui.IncludeExcludeVisualizer;
0083:        import org.netbeans.spi.project.support.ant.AntProjectHelper;
0084:        import org.netbeans.spi.project.support.ant.PropertyEvaluator;
0085:        import org.netbeans.spi.project.support.ant.PropertyUtils;
0086:        import org.openide.DialogDescriptor;
0087:        import org.openide.DialogDisplayer;
0088:        import org.openide.NotifyDescriptor;
0089:        import org.openide.filesystems.FileObject;
0090:        import org.openide.filesystems.FileUtil;
0091:        import org.openide.util.HelpCtx;
0092:        import org.openide.util.NbBundle;
0093:
0094:        /**
0095:         * Wizard panel which lets user select source and test package roots and source level.
0096:         * Also shows some other info.
0097:         * @author  David Konecny
0098:         */
0099:        public class SourceFoldersPanel extends JPanel implements 
0100:                HelpCtx.Provider, ListSelectionListener {
0101:
0102:            private SourcesModel sourceFoldersModel;
0103:            private SourcesModel testFoldersModel;
0104:            private ChangeListener listener;
0105:            private boolean isWizard;
0106:            private ProjectModel model;
0107:
0108:            /** Creates new form SourceFoldersPanel */
0109:            public SourceFoldersPanel() {
0110:                this (true);
0111:            }
0112:
0113:            public SourceFoldersPanel(boolean isWizard) {
0114:                this .isWizard = isWizard;
0115:                initComponents();
0116:                sourceFoldersModel = new SourcesModel(false);
0117:                sourceFolders.setModel(sourceFoldersModel);
0118:                sourceFolders.getSelectionModel()
0119:                        .addListSelectionListener(this );
0120:                testFoldersModel = new SourcesModel(true);
0121:                testFolders.setModel(testFoldersModel);
0122:                testFolders.getSelectionModel().addListSelectionListener(this );
0123:                sourceFolders.getTableHeader().setReorderingAllowed(false);
0124:                sourceFolders.setDefaultRenderer(String.class,
0125:                        new ToolTipRenderer());
0126:                testFolders.getTableHeader().setReorderingAllowed(false);
0127:                testFolders.setDefaultRenderer(String.class,
0128:                        new ToolTipRenderer());
0129:                initSourceLevel();
0130:                jLabel1.setVisible(isWizard);
0131:            }
0132:
0133:            public HelpCtx getHelpCtx() {
0134:                return new HelpCtx(SourceFoldersPanel.class);
0135:            }
0136:
0137:            /** WizardDescriptor.Panel can set one change listener 
0138:             * to be notified about changes in the panel. */
0139:            public void setChangeListener(ChangeListener listener) {
0140:                this .listener = listener;
0141:            }
0142:
0143:            private void initSourceLevel() {
0144:                sourceLevel.addItem(org.openide.util.NbBundle.getMessage(
0145:                        SourceFoldersPanel.class,
0146:                        "LBL_SourceFoldersPanel_JDK13")); // NOI18N
0147:                sourceLevel.addItem(org.openide.util.NbBundle.getMessage(
0148:                        SourceFoldersPanel.class,
0149:                        "LBL_SourceFoldersPanel_JDK14")); // NOI18N
0150:                sourceLevel.addItem(org.openide.util.NbBundle.getMessage(
0151:                        SourceFoldersPanel.class,
0152:                        "LBL_SourceFoldersPanel_JDK15")); // NOI18N
0153:            }
0154:
0155:            private void updateButtons() {
0156:                removeFolder
0157:                        .setEnabled(sourceFolders.getSelectedRowCount() > 0);
0158:                removeTestFolder
0159:                        .setEnabled(testFolders.getSelectedRowCount() > 0);
0160:                updateUpDownButtons();
0161:            }
0162:
0163:            public void valueChanged(ListSelectionEvent e) {
0164:                updateButtons();
0165:            }
0166:
0167:            private void updateUpDownButtons() {
0168:                int first = sourceFolders.getSelectionModel()
0169:                        .getMinSelectionIndex();
0170:                int last = sourceFolders.getSelectionModel()
0171:                        .getMaxSelectionIndex();
0172:                upFolder.setEnabled(first > 0);
0173:                downFolder.setEnabled(last > -1
0174:                        && last < sourceFoldersModel.getRowCount() - 1);
0175:                first = testFolders.getSelectionModel().getMinSelectionIndex();
0176:                last = testFolders.getSelectionModel().getMaxSelectionIndex();
0177:                upTestFolder.setEnabled(first > 0);
0178:                downTestFolder.setEnabled(last > -1
0179:                        && last < testFoldersModel.getRowCount() - 1);
0180:            }
0181:
0182:            private void updateSourceLevelCombo(String sourceLevelValue) {
0183:                if (sourceLevelValue.equals("1.3")) { // NOI18N
0184:                    sourceLevel.setSelectedIndex(0);
0185:                } else if (sourceLevelValue.equals("1.4")) { // NOI18N
0186:                    sourceLevel.setSelectedIndex(1);
0187:                } else if (sourceLevelValue.equals("1.5")) { // NOI18N
0188:                    sourceLevel.setSelectedIndex(2);
0189:                } else {
0190:                    // user specified some other value in project.xml
0191:                    sourceLevel.addItem(sourceLevelValue);
0192:                    sourceLevel.setSelectedIndex(3);
0193:                }
0194:            }
0195:
0196:            private void updateEncodingCombo() {
0197:                encodingComboBox.setModel(new EncodingModel());
0198:            }
0199:
0200:            private String getSourceLevelValue(int index) {
0201:                switch (index) {
0202:                case 0:
0203:                    return "1.3"; // NOI18N
0204:                case 1:
0205:                    return "1.4"; // NOI18N
0206:                case 2:
0207:                    return "1.5"; // NOI18N
0208:                default:
0209:                    return null;
0210:                }
0211:            }
0212:
0213:            /** This method is called from within the constructor to
0214:             * initialize the form.
0215:             * WARNING: Do NOT modify this code. The content of this method is
0216:             * always regenerated by the Form Editor.
0217:             */
0218:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
0219:            private void initComponents() {
0220:                java.awt.GridBagConstraints gridBagConstraints;
0221:
0222:                jLabel1 = new javax.swing.JLabel();
0223:                jLabel2 = new javax.swing.JLabel();
0224:                jLabel3 = new javax.swing.JLabel();
0225:                sourceLevel = new javax.swing.JComboBox();
0226:                addFolder = new javax.swing.JButton();
0227:                removeFolder = new javax.swing.JButton();
0228:                jScrollPane1 = new javax.swing.JScrollPane();
0229:                sourceFolders = new javax.swing.JTable();
0230:                jScrollPane2 = new javax.swing.JScrollPane();
0231:                testFolders = new javax.swing.JTable();
0232:                jLabel4 = new javax.swing.JLabel();
0233:                addTestFolder = new javax.swing.JButton();
0234:                removeTestFolder = new javax.swing.JButton();
0235:                upFolder = new javax.swing.JButton();
0236:                downFolder = new javax.swing.JButton();
0237:                downTestFolder = new javax.swing.JButton();
0238:                upTestFolder = new javax.swing.JButton();
0239:                includesExcludesButton = new javax.swing.JButton();
0240:                encodingLabel = new javax.swing.JLabel();
0241:                encodingComboBox = new javax.swing.JComboBox();
0242:                jPanel1 = new javax.swing.JPanel();
0243:                jLabel5 = new javax.swing.JLabel();
0244:                jTextArea1 = new javax.swing.JTextArea();
0245:
0246:                setMinimumSize(new java.awt.Dimension(265, 375));
0247:                setPreferredSize(new java.awt.Dimension(800, 500));
0248:                setLayout(new java.awt.GridBagLayout());
0249:
0250:                jLabel1.setLabelFor(this );
0251:                org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
0252:                        org.openide.util.NbBundle.getMessage(
0253:                                SourceFoldersPanel.class,
0254:                                "LBL_SourceFoldersPanel_jLabel1")); // NOI18N
0255:                gridBagConstraints = new java.awt.GridBagConstraints();
0256:                gridBagConstraints.gridx = 0;
0257:                gridBagConstraints.gridy = 0;
0258:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0259:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0260:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0261:                gridBagConstraints.weightx = 1.0;
0262:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
0263:                add(jLabel1, gridBagConstraints);
0264:                jLabel1.getAccessibleContext().setAccessibleDescription(
0265:                        org.openide.util.NbBundle.getMessage(
0266:                                SourceFoldersPanel.class,
0267:                                "ACSD_SourceFoldersPanel_jLabel1")); // NOI18N
0268:
0269:                jLabel2.setLabelFor(sourceFolders);
0270:                org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
0271:                        org.openide.util.NbBundle.getMessage(
0272:                                SourceFoldersPanel.class,
0273:                                "LBL_SourceFoldersPanel_jLabel2")); // NOI18N
0274:                gridBagConstraints = new java.awt.GridBagConstraints();
0275:                gridBagConstraints.gridx = 0;
0276:                gridBagConstraints.gridy = 1;
0277:                gridBagConstraints.gridwidth = 3;
0278:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0279:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0280:                add(jLabel2, gridBagConstraints);
0281:                jLabel2.getAccessibleContext().setAccessibleDescription(
0282:                        org.openide.util.NbBundle.getMessage(
0283:                                SourceFoldersPanel.class,
0284:                                "ACSD_SourceFoldersPanel_jLabel2")); // NOI18N
0285:
0286:                jLabel3.setLabelFor(sourceLevel);
0287:                org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
0288:                        org.openide.util.NbBundle.getMessage(
0289:                                SourceFoldersPanel.class,
0290:                                "LBL_SourceFoldersPanel_jLabel3")); // NOI18N
0291:                gridBagConstraints = new java.awt.GridBagConstraints();
0292:                gridBagConstraints.gridx = 0;
0293:                gridBagConstraints.gridy = 11;
0294:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0295:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
0296:                add(jLabel3, gridBagConstraints);
0297:                jLabel3.getAccessibleContext().setAccessibleName(
0298:                        org.openide.util.NbBundle.getMessage(
0299:                                SourceFoldersPanel.class,
0300:                                "ACSD_SourceLevel_Label")); // NOI18N
0301:                jLabel3.getAccessibleContext().setAccessibleDescription(
0302:                        org.openide.util.NbBundle.getMessage(
0303:                                SourceFoldersPanel.class,
0304:                                "ACSD_SourceFoldersPanel_jLabel3")); // NOI18N
0305:
0306:                sourceLevel.addItemListener(new java.awt.event.ItemListener() {
0307:                    public void itemStateChanged(java.awt.event.ItemEvent evt) {
0308:                        sourceLevelItemStateChanged(evt);
0309:                    }
0310:                });
0311:                gridBagConstraints = new java.awt.GridBagConstraints();
0312:                gridBagConstraints.gridx = 1;
0313:                gridBagConstraints.gridy = 11;
0314:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0315:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0316:                gridBagConstraints.weightx = 0.5;
0317:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 16);
0318:                add(sourceLevel, gridBagConstraints);
0319:                sourceLevel.getAccessibleContext().setAccessibleName(
0320:                        org.openide.util.NbBundle.getMessage(
0321:                                SourceFoldersPanel.class,
0322:                                "ACSD_SourceLevel_Name")); // NOI18N
0323:                java.util.ResourceBundle bundle = java.util.ResourceBundle
0324:                        .getBundle("org/netbeans/modules/java/freeform/ui/Bundle"); // NOI18N
0325:                sourceLevel.getAccessibleContext().setAccessibleDescription(
0326:                        bundle.getString("AD_SourceFoldersPanel_sourceLevel")); // NOI18N
0327:
0328:                org.openide.awt.Mnemonics.setLocalizedText(addFolder,
0329:                        org.openide.util.NbBundle.getMessage(
0330:                                SourceFoldersPanel.class,
0331:                                "BTN_SourceFoldersPanel_addFolder")); // NOI18N
0332:                addFolder
0333:                        .addActionListener(new java.awt.event.ActionListener() {
0334:                            public void actionPerformed(
0335:                                    java.awt.event.ActionEvent evt) {
0336:                                addFolderActionPerformed(evt);
0337:                            }
0338:                        });
0339:                gridBagConstraints = new java.awt.GridBagConstraints();
0340:                gridBagConstraints.gridx = 3;
0341:                gridBagConstraints.gridy = 2;
0342:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0343:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0344:                add(addFolder, gridBagConstraints);
0345:                addFolder.getAccessibleContext().setAccessibleDescription(
0346:                        org.openide.util.NbBundle.getMessage(
0347:                                SourceFoldersPanel.class,
0348:                                "ACSD_SourceFoldersPanel_addFolder")); // NOI18N
0349:
0350:                org.openide.awt.Mnemonics.setLocalizedText(removeFolder,
0351:                        org.openide.util.NbBundle.getMessage(
0352:                                SourceFoldersPanel.class,
0353:                                "BTN_SourceFoldersPanel_removeFolder")); // NOI18N
0354:                removeFolder
0355:                        .addActionListener(new java.awt.event.ActionListener() {
0356:                            public void actionPerformed(
0357:                                    java.awt.event.ActionEvent evt) {
0358:                                removeFolderActionPerformed(evt);
0359:                            }
0360:                        });
0361:                gridBagConstraints = new java.awt.GridBagConstraints();
0362:                gridBagConstraints.gridx = 3;
0363:                gridBagConstraints.gridy = 3;
0364:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0365:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0366:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0367:                add(removeFolder, gridBagConstraints);
0368:                removeFolder.getAccessibleContext().setAccessibleDescription(
0369:                        org.openide.util.NbBundle.getMessage(
0370:                                SourceFoldersPanel.class,
0371:                                "ACSD_SourceFoldersPanel_removeFolder")); // NOI18N
0372:
0373:                jScrollPane1
0374:                        .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
0375:                jScrollPane1.setViewportView(sourceFolders);
0376:                sourceFolders.getAccessibleContext().setAccessibleDescription(
0377:                        org.openide.util.NbBundle.getMessage(
0378:                                SourceFoldersPanel.class,
0379:                                "ACSD_SourceFoldersPanel_sourceFolders")); // NOI18N
0380:
0381:                gridBagConstraints = new java.awt.GridBagConstraints();
0382:                gridBagConstraints.gridx = 0;
0383:                gridBagConstraints.gridy = 2;
0384:                gridBagConstraints.gridwidth = 3;
0385:                gridBagConstraints.gridheight = 4;
0386:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0387:                gridBagConstraints.weightx = 1.0;
0388:                gridBagConstraints.weighty = 0.5;
0389:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 8);
0390:                add(jScrollPane1, gridBagConstraints);
0391:                jScrollPane1.getAccessibleContext().setAccessibleDescription(
0392:                        org.openide.util.NbBundle.getMessage(
0393:                                SourceFoldersPanel.class,
0394:                                "ACSD_SourceFoldersPanel_jScrollPanel1")); // NOI18N
0395:
0396:                jScrollPane2
0397:                        .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
0398:                jScrollPane2.setViewportView(testFolders);
0399:                testFolders
0400:                        .getAccessibleContext()
0401:                        .setAccessibleDescription(
0402:                                bundle
0403:                                        .getString("ACSD_SourceFoldersPanel_testFolders")); // NOI18N
0404:
0405:                gridBagConstraints = new java.awt.GridBagConstraints();
0406:                gridBagConstraints.gridx = 0;
0407:                gridBagConstraints.gridy = 7;
0408:                gridBagConstraints.gridwidth = 3;
0409:                gridBagConstraints.gridheight = 4;
0410:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0411:                gridBagConstraints.weightx = 1.0;
0412:                gridBagConstraints.weighty = 0.5;
0413:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 8, 8);
0414:                add(jScrollPane2, gridBagConstraints);
0415:                jScrollPane2.getAccessibleContext().setAccessibleDescription(
0416:                        bundle.getString("AD_SourceFoldersPanel_jScrollPane2")); // NOI18N
0417:
0418:                jLabel4.setLabelFor(testFolders);
0419:                org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
0420:                        org.openide.util.NbBundle.getMessage(
0421:                                SourceFoldersPanel.class,
0422:                                "LBL_TestSourceFoldersPanel")); // NOI18N
0423:                gridBagConstraints = new java.awt.GridBagConstraints();
0424:                gridBagConstraints.gridx = 0;
0425:                gridBagConstraints.gridy = 6;
0426:                gridBagConstraints.gridwidth = 3;
0427:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0428:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0429:                add(jLabel4, gridBagConstraints);
0430:
0431:                org.openide.awt.Mnemonics.setLocalizedText(addTestFolder,
0432:                        org.openide.util.NbBundle.getMessage(
0433:                                SourceFoldersPanel.class,
0434:                                "BTN_SourceFoldersPanel_addTestFolder")); // NOI18N
0435:                addTestFolder
0436:                        .addActionListener(new java.awt.event.ActionListener() {
0437:                            public void actionPerformed(
0438:                                    java.awt.event.ActionEvent evt) {
0439:                                addTestFolderActionPerformed(evt);
0440:                            }
0441:                        });
0442:                gridBagConstraints = new java.awt.GridBagConstraints();
0443:                gridBagConstraints.gridx = 3;
0444:                gridBagConstraints.gridy = 7;
0445:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0446:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0447:                add(addTestFolder, gridBagConstraints);
0448:                addTestFolder
0449:                        .getAccessibleContext()
0450:                        .setAccessibleDescription(
0451:                                bundle
0452:                                        .getString("AD_SourceFoldersPanel_addTestFolder")); // NOI18N
0453:
0454:                org.openide.awt.Mnemonics.setLocalizedText(removeTestFolder,
0455:                        org.openide.util.NbBundle.getMessage(
0456:                                SourceFoldersPanel.class,
0457:                                "BTN_SourceFoldersPanel_removeTestFolder")); // NOI18N
0458:                removeTestFolder
0459:                        .addActionListener(new java.awt.event.ActionListener() {
0460:                            public void actionPerformed(
0461:                                    java.awt.event.ActionEvent evt) {
0462:                                removeTestFolderActionPerformed(evt);
0463:                            }
0464:                        });
0465:                gridBagConstraints = new java.awt.GridBagConstraints();
0466:                gridBagConstraints.gridx = 3;
0467:                gridBagConstraints.gridy = 8;
0468:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0469:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0470:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0471:                add(removeTestFolder, gridBagConstraints);
0472:                removeTestFolder
0473:                        .getAccessibleContext()
0474:                        .setAccessibleDescription(
0475:                                bundle
0476:                                        .getString("AD_SourceFoldersPanel_removeTestFolder")); // NOI18N
0477:
0478:                org.openide.awt.Mnemonics.setLocalizedText(upFolder,
0479:                        org.openide.util.NbBundle.getMessage(
0480:                                SourceFoldersPanel.class,
0481:                                "BTN_SourceFoldersPanel_upFolder")); // NOI18N
0482:                upFolder.addActionListener(new java.awt.event.ActionListener() {
0483:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
0484:                        upFolderActionPerformed(evt);
0485:                    }
0486:                });
0487:                gridBagConstraints = new java.awt.GridBagConstraints();
0488:                gridBagConstraints.gridx = 3;
0489:                gridBagConstraints.gridy = 4;
0490:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0491:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0492:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0493:                add(upFolder, gridBagConstraints);
0494:                upFolder.getAccessibleContext().setAccessibleDescription(
0495:                        bundle.getString("AD_SourceFoldersPanel_upFolder")); // NOI18N
0496:
0497:                org.openide.awt.Mnemonics.setLocalizedText(downFolder,
0498:                        org.openide.util.NbBundle.getMessage(
0499:                                SourceFoldersPanel.class,
0500:                                "BTN_SourceFoldersPanel_downFolder")); // NOI18N
0501:                downFolder
0502:                        .addActionListener(new java.awt.event.ActionListener() {
0503:                            public void actionPerformed(
0504:                                    java.awt.event.ActionEvent evt) {
0505:                                downFolderActionPerformed(evt);
0506:                            }
0507:                        });
0508:                gridBagConstraints = new java.awt.GridBagConstraints();
0509:                gridBagConstraints.gridx = 3;
0510:                gridBagConstraints.gridy = 5;
0511:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0512:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0513:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0514:                add(downFolder, gridBagConstraints);
0515:                downFolder.getAccessibleContext().setAccessibleDescription(
0516:                        bundle.getString("AD_SourceFoldersPanel_downFolder")); // NOI18N
0517:
0518:                org.openide.awt.Mnemonics.setLocalizedText(downTestFolder,
0519:                        org.openide.util.NbBundle.getMessage(
0520:                                SourceFoldersPanel.class,
0521:                                "BTN_SourceFoldersPanel_downTestFolder")); // NOI18N
0522:                downTestFolder
0523:                        .addActionListener(new java.awt.event.ActionListener() {
0524:                            public void actionPerformed(
0525:                                    java.awt.event.ActionEvent evt) {
0526:                                downTestFolderActionPerformed(evt);
0527:                            }
0528:                        });
0529:                gridBagConstraints = new java.awt.GridBagConstraints();
0530:                gridBagConstraints.gridx = 3;
0531:                gridBagConstraints.gridy = 10;
0532:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0533:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0534:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0535:                add(downTestFolder, gridBagConstraints);
0536:                downTestFolder
0537:                        .getAccessibleContext()
0538:                        .setAccessibleDescription(
0539:                                bundle
0540:                                        .getString("AD_SourceFoldersPanel_downTestFolder")); // NOI18N
0541:
0542:                org.openide.awt.Mnemonics.setLocalizedText(upTestFolder,
0543:                        org.openide.util.NbBundle.getMessage(
0544:                                SourceFoldersPanel.class,
0545:                                "BTN_SourceFoldersPanel_upTestFolder")); // NOI18N
0546:                upTestFolder
0547:                        .addActionListener(new java.awt.event.ActionListener() {
0548:                            public void actionPerformed(
0549:                                    java.awt.event.ActionEvent evt) {
0550:                                upTestFolderActionPerformed(evt);
0551:                            }
0552:                        });
0553:                gridBagConstraints = new java.awt.GridBagConstraints();
0554:                gridBagConstraints.gridx = 3;
0555:                gridBagConstraints.gridy = 9;
0556:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0557:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0558:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0559:                add(upTestFolder, gridBagConstraints);
0560:                upTestFolder.getAccessibleContext().setAccessibleDescription(
0561:                        bundle.getString("AD_SourceFoldersPanel_upTestFolder")); // NOI18N
0562:
0563:                org.openide.awt.Mnemonics
0564:                        .setLocalizedText(
0565:                                includesExcludesButton,
0566:                                org.openide.util.NbBundle
0567:                                        .getMessage(SourceFoldersPanel.class,
0568:                                                "SourceFoldersPanel.includesExcludesButton.text")); // NOI18N
0569:                includesExcludesButton
0570:                        .addActionListener(new java.awt.event.ActionListener() {
0571:                            public void actionPerformed(
0572:                                    java.awt.event.ActionEvent evt) {
0573:                                includesExcludesButtonActionPerformed(evt);
0574:                            }
0575:                        });
0576:                gridBagConstraints = new java.awt.GridBagConstraints();
0577:                gridBagConstraints.gridx = 2;
0578:                gridBagConstraints.gridy = 11;
0579:                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0580:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 8);
0581:                add(includesExcludesButton, gridBagConstraints);
0582:                includesExcludesButton.getAccessibleContext()
0583:                        .setAccessibleName(
0584:                                org.openide.util.NbBundle.getMessage(
0585:                                        SourceFoldersPanel.class,
0586:                                        "ACSD_Includes-Excludes_Name")); // NOI18N
0587:                includesExcludesButton.getAccessibleContext()
0588:                        .setAccessibleDescription(
0589:                                org.openide.util.NbBundle.getMessage(
0590:                                        SourceFoldersPanel.class,
0591:                                        "ACSD_Includes-Excludes_Desc")); // NOI18N
0592:
0593:                org.openide.awt.Mnemonics.setLocalizedText(encodingLabel,
0594:                        org.openide.util.NbBundle.getMessage(
0595:                                SourceFoldersPanel.class, "LBL_Encoding")); // NOI18N
0596:                gridBagConstraints = new java.awt.GridBagConstraints();
0597:                gridBagConstraints.gridx = 0;
0598:                gridBagConstraints.gridy = 12;
0599:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0600:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 6);
0601:                add(encodingLabel, gridBagConstraints);
0602:                encodingLabel.getAccessibleContext().setAccessibleName(
0603:                        org.openide.util.NbBundle.getMessage(
0604:                                SourceFoldersPanel.class,
0605:                                "ACSD_Encoding_Label_Name")); // NOI18N
0606:                encodingLabel.getAccessibleContext().setAccessibleDescription(
0607:                        org.openide.util.NbBundle.getMessage(
0608:                                SourceFoldersPanel.class,
0609:                                "ACSD_Encoding_Label_Desc")); // NOI18N
0610:
0611:                encodingComboBox.setRenderer(new EncodingRenderer());
0612:                encodingComboBox
0613:                        .addActionListener(new java.awt.event.ActionListener() {
0614:                            public void actionPerformed(
0615:                                    java.awt.event.ActionEvent evt) {
0616:                                encodingComboBoxActionPerformed(evt);
0617:                            }
0618:                        });
0619:                gridBagConstraints = new java.awt.GridBagConstraints();
0620:                gridBagConstraints.gridx = 1;
0621:                gridBagConstraints.gridy = 12;
0622:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0623:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0624:                gridBagConstraints.weightx = 0.5;
0625:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 16);
0626:                add(encodingComboBox, gridBagConstraints);
0627:                encodingComboBox.getAccessibleContext()
0628:                        .setAccessibleName(
0629:                                org.openide.util.NbBundle.getMessage(
0630:                                        SourceFoldersPanel.class,
0631:                                        "ACSD_Encoding_Name")); // NOI18N
0632:                encodingComboBox.getAccessibleContext()
0633:                        .setAccessibleDescription(
0634:                                org.openide.util.NbBundle.getMessage(
0635:                                        SourceFoldersPanel.class,
0636:                                        "ACSD_Encoding_Desc")); // NOI18N
0637:
0638:                jPanel1.setBorder(javax.swing.BorderFactory
0639:                        .createLineBorder(javax.swing.UIManager.getDefaults()
0640:                                .getColor("Label.disabledForeground")));
0641:                jPanel1.setLayout(new java.awt.GridBagLayout());
0642:
0643:                jLabel5
0644:                        .setIcon(new javax.swing.ImageIcon(
0645:                                getClass()
0646:                                        .getResource(
0647:                                                "/org/netbeans/modules/java/freeform/resources/alert_32.png"))); // NOI18N
0648:                gridBagConstraints = new java.awt.GridBagConstraints();
0649:                gridBagConstraints.gridx = 0;
0650:                gridBagConstraints.gridy = 0;
0651:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0652:                gridBagConstraints.insets = new java.awt.Insets(8, 8, 8, 0);
0653:                jPanel1.add(jLabel5, gridBagConstraints);
0654:
0655:                jTextArea1.setBackground(javax.swing.UIManager.getDefaults()
0656:                        .getColor("Panel.background"));
0657:                jTextArea1.setEditable(false);
0658:                jTextArea1.setLineWrap(true);
0659:                jTextArea1.setText(org.openide.util.NbBundle.getMessage(
0660:                        SourceFoldersPanel.class, "Freeform_Warning_Message")); // NOI18N
0661:                jTextArea1.setWrapStyleWord(true);
0662:                gridBagConstraints = new java.awt.GridBagConstraints();
0663:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0664:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0665:                gridBagConstraints.weightx = 1.0;
0666:                gridBagConstraints.insets = new java.awt.Insets(4, 10, 4, 4);
0667:                jPanel1.add(jTextArea1, gridBagConstraints);
0668:                jTextArea1.getAccessibleContext().setAccessibleName(
0669:                        org.openide.util.NbBundle.getMessage(
0670:                                SourceFoldersPanel.class,
0671:                                "ACSN_Freeform_Warning_Message")); // NOI18N
0672:                jTextArea1.getAccessibleContext().setAccessibleDescription(
0673:                        org.openide.util.NbBundle.getMessage(
0674:                                SourceFoldersPanel.class,
0675:                                "ACSD_Freeform_Warning_Message")); // NOI18N
0676:
0677:                gridBagConstraints = new java.awt.GridBagConstraints();
0678:                gridBagConstraints.gridx = 0;
0679:                gridBagConstraints.gridy = 13;
0680:                gridBagConstraints.gridwidth = 4;
0681:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0682:                gridBagConstraints.weightx = 1.0;
0683:                gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
0684:                add(jPanel1, gridBagConstraints);
0685:            }// </editor-fold>//GEN-END:initComponents
0686:
0687:            private void encodingComboBoxActionPerformed(
0688:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_encodingComboBoxActionPerformed
0689:                Object selItem = encodingComboBox.getModel().getSelectedItem();
0690:                if (selItem instanceof  Charset) {
0691:                    model.setEncoding(((Charset) selItem).name());
0692:                    // XXX Should we set this here?
0693:                    FileEncodingQuery.setDefaultEncoding((Charset) selItem);
0694:                } else {
0695:                    model.setEncoding(selItem.toString());
0696:                }
0697:            }//GEN-LAST:event_encodingComboBoxActionPerformed
0698:
0699:            private void includesExcludesButtonActionPerformed(
0700:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_includesExcludesButtonActionPerformed
0701:                // Assumes they all use the same include/exclude patterns. Close enough.
0702:                IncludeExcludeVisualizer v = new IncludeExcludeVisualizer();
0703:                List<File> roots = new ArrayList<File>();
0704:                for (JavaProjectGenerator.SourceFolder folder : model
0705:                        .getSourceFolders()) {
0706:                    v
0707:                            .setIncludePattern(folder.includes != null ? folder.includes
0708:                                    : "**");
0709:                    v
0710:                            .setExcludePattern(folder.excludes != null ? folder.excludes
0711:                                    : "");
0712:                    File f = Util.resolveFile(model.getEvaluator(), model
0713:                            .getNBProjectFolder(), folder.location);
0714:                    if (f.isDirectory()) {
0715:                        roots.add(f);
0716:                    }
0717:                }
0718:                v.setRoots(roots.toArray(new File[roots.size()]));
0719:                DialogDescriptor dd = new DialogDescriptor(v
0720:                        .getVisualizerPanel(), NbBundle.getMessage(
0721:                        SourceFoldersPanel.class,
0722:                        "SourceFoldersPanel.title.includeExclude"));
0723:                dd.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
0724:                if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer
0725:                        .getDefault().notify(dd))) {
0726:                    for (JavaProjectGenerator.SourceFolder folder : model
0727:                            .getSourceFolders()) {
0728:                        folder.includes = v.getIncludePattern().equals("**") ? null
0729:                                : v.getIncludePattern();
0730:                        folder.excludes = v.getExcludePattern().equals("") ? null
0731:                                : v.getExcludePattern();
0732:                    }
0733:                }
0734:            }//GEN-LAST:event_includesExcludesButtonActionPerformed
0735:
0736:            private void downTestFolderActionPerformed(
0737:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downTestFolderActionPerformed
0738:                int[] indeces = testFolders.getSelectedRows();
0739:                if (indeces.length == 0) {
0740:                    return;
0741:                }
0742:                for (int i = indeces.length - 1; i >= 0; i--) {
0743:                    int fromIndex = calcRealSourceIndex(indeces[i], true);
0744:                    model.moveSourceFolder(fromIndex, fromIndex + 1);
0745:                }
0746:                testFoldersModel.fireTableDataChanged();
0747:                testFolders.getSelectionModel().clearSelection();
0748:                for (int i = 0; i < indeces.length; i++) {
0749:                    testFolders.getSelectionModel().addSelectionInterval(
0750:                            indeces[i] + 1, indeces[i] + 1);
0751:                }
0752:            }//GEN-LAST:event_downTestFolderActionPerformed
0753:
0754:            private void upTestFolderActionPerformed(
0755:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upTestFolderActionPerformed
0756:                int[] indeces = testFolders.getSelectedRows();
0757:                if (indeces.length == 0) {
0758:                    return;
0759:                }
0760:                for (int i = 0; i < indeces.length; i++) {
0761:                    int fromIndex = calcRealSourceIndex(indeces[i], true);
0762:                    model.moveSourceFolder(fromIndex, fromIndex - 1);
0763:                }
0764:                testFoldersModel.fireTableDataChanged();
0765:                testFolders.getSelectionModel().clearSelection();
0766:                for (int i = 0; i < indeces.length; i++) {
0767:                    testFolders.getSelectionModel().addSelectionInterval(
0768:                            indeces[i] - 1, indeces[i] - 1);
0769:                }
0770:            }//GEN-LAST:event_upTestFolderActionPerformed
0771:
0772:            private void downFolderActionPerformed(
0773:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downFolderActionPerformed
0774:                int[] indeces = sourceFolders.getSelectedRows();
0775:                if (indeces.length == 0) {
0776:                    return;
0777:                }
0778:                for (int i = indeces.length - 1; i >= 0; i--) {
0779:                    int fromIndex = calcRealSourceIndex(indeces[i], false);
0780:                    model.moveSourceFolder(fromIndex, fromIndex + 1);
0781:                }
0782:                sourceFoldersModel.fireTableDataChanged();
0783:                sourceFolders.getSelectionModel().clearSelection();
0784:                for (int i = 0; i < indeces.length; i++) {
0785:                    sourceFolders.getSelectionModel().addSelectionInterval(
0786:                            indeces[i] + 1, indeces[i] + 1);
0787:                }
0788:            }//GEN-LAST:event_downFolderActionPerformed
0789:
0790:            private void upFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upFolderActionPerformed
0791:                int[] indeces = sourceFolders.getSelectedRows();
0792:                if (indeces.length == 0) {
0793:                    return;
0794:                }
0795:                for (int i = 0; i < indeces.length; i++) {
0796:                    int fromIndex = calcRealSourceIndex(indeces[i], false);
0797:                    model.moveSourceFolder(fromIndex, fromIndex - 1);
0798:                }
0799:                sourceFoldersModel.fireTableDataChanged();
0800:                sourceFolders.getSelectionModel().clearSelection();
0801:                for (int i = 0; i < indeces.length; i++) {
0802:                    sourceFolders.getSelectionModel().addSelectionInterval(
0803:                            indeces[i] - 1, indeces[i] - 1);
0804:                }
0805:            }//GEN-LAST:event_upFolderActionPerformed
0806:
0807:            private void removeTestFolderActionPerformed(
0808:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTestFolderActionPerformed
0809:                int[] indeces = testFolders.getSelectedRows();
0810:                if (indeces.length == 0) {
0811:                    return;
0812:                }
0813:                for (int i = indeces.length - 1; i >= 0; i--) {
0814:                    String location = getItem(indeces[i], true).location;
0815:                    model.removeSourceFolder(calcRealSourceIndex(indeces[i],
0816:                            true));
0817:                }
0818:                testFoldersModel.fireTableDataChanged();
0819:                if (listener != null) {
0820:                    listener.stateChanged(null);
0821:                }
0822:                updateButtons();
0823:            }//GEN-LAST:event_removeTestFolderActionPerformed
0824:
0825:            private void addTestFolderActionPerformed(
0826:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTestFolderActionPerformed
0827:                doAddFolderActionPerformed(evt, true);
0828:            }//GEN-LAST:event_addTestFolderActionPerformed
0829:
0830:            private void sourceLevelItemStateChanged(
0831:                    java.awt.event.ItemEvent evt) {//GEN-FIRST:event_sourceLevelItemStateChanged
0832:                if (sourceLevel.getSelectedIndex() != -1 && model != null) {
0833:                    String sl = getSourceLevelValue(sourceLevel
0834:                            .getSelectedIndex());
0835:                    if (sl == null) {
0836:                        sl = (String) sourceLevel.getSelectedItem();
0837:                    }
0838:                    model.setSourceLevel(sl);
0839:                }
0840:            }//GEN-LAST:event_sourceLevelItemStateChanged
0841:
0842:            private void removeFolderActionPerformed(
0843:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeFolderActionPerformed
0844:                int[] indeces = sourceFolders.getSelectedRows();
0845:                if (indeces.length == 0) {
0846:                    return;
0847:                }
0848:                for (int i = indeces.length - 1; i >= 0; i--) {
0849:                    String location = getItem(indeces[i], false).location;
0850:                    model.removeSourceFolder(calcRealSourceIndex(indeces[i],
0851:                            false));
0852:                }
0853:                sourceFoldersModel.fireTableDataChanged();
0854:                if (listener != null) {
0855:                    listener.stateChanged(null);
0856:                }
0857:                updateButtons();
0858:            }//GEN-LAST:event_removeFolderActionPerformed
0859:
0860:            private void addFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFolderActionPerformed
0861:                doAddFolderActionPerformed(evt, false);
0862:            }//GEN-LAST:event_addFolderActionPerformed
0863:
0864:            private void doAddFolderActionPerformed(
0865:                    java.awt.event.ActionEvent evt, boolean isTests) {
0866:                JFileChooser chooser = new JFileChooser();
0867:                FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
0868:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0869:                if (model.getBaseFolder() != null) {
0870:                    File files[] = model.getBaseFolder().listFiles();
0871:                    if (files != null && files.length > 0) {
0872:                        chooser.setSelectedFile(files[0]);
0873:                    } else {
0874:                        chooser.setSelectedFile(model.getBaseFolder());
0875:                    }
0876:                }
0877:                if (isTests) {
0878:                    chooser
0879:                            .setDialogTitle(NbBundle.getMessage(
0880:                                    SourceFoldersPanel.class,
0881:                                    "LBL_Browse_Test_Folder"));
0882:                } else {
0883:                    chooser.setDialogTitle(NbBundle.getMessage(
0884:                            SourceFoldersPanel.class,
0885:                            "LBL_Browse_Source_Folder"));
0886:                }
0887:                chooser.setMultiSelectionEnabled(true);
0888:                if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this )) {
0889:                    File files[] = chooser.getSelectedFiles();
0890:                    model.setEncoding(encodingComboBox.getModel()
0891:                            .getSelectedItem().toString());
0892:                    Set<File> invalidRoots = processRoots(model, files,
0893:                            isTests, isWizard);
0894:                    if (isTests) {
0895:                        testFoldersModel.fireTableDataChanged();
0896:                    } else {
0897:                        sourceFoldersModel.fireTableDataChanged();
0898:                    }
0899:                    if (listener != null) {
0900:                        listener.stateChanged(null);
0901:                    }
0902:                    updateButtons();
0903:                    if (invalidRoots.size() > 0) {
0904:                        showInvalidRootsWarning(invalidRoots);
0905:                    }
0906:                }
0907:            }
0908:
0909:            /*package private for tests*/static Set<File> processRoots(
0910:                    ProjectModel model, File[] files, boolean isTests,
0911:                    boolean isWizard) {
0912:                Set<File> invalidRoots = new HashSet<File>();
0913:
0914:                FILE: for (File file : files) {
0915:                    File sourceLoc = FileUtil.normalizeFile(file);
0916:                    String location = Util.relativizeLocation(model
0917:                            .getBaseFolder(), model.getNBProjectFolder(),
0918:                            sourceLoc);
0919:                    Project p, this Project = isWizard ? null : FileOwnerQuery
0920:                            .getOwner(model.getNBProjectFolder().toURI());
0921:                    if ((p = FileOwnerQuery.getOwner(sourceLoc.toURI())) != null
0922:                            && (this Project == null || !this Project.equals(p))
0923:                            && !isParentOf(model.getNBProjectFolder(),
0924:                                    sourceLoc)
0925:                            && !isParentOf(model.getBaseFolder(), sourceLoc)) {
0926:                        invalidRoots.add(sourceLoc);
0927:                    } else {
0928:                        List<JavaProjectGenerator.SourceFolder> sourceFolders = model
0929:                                .getSourceFolders();
0930:                        for (JavaProjectGenerator.SourceFolder sf : sourceFolders) {
0931:                            if (location.equals(sf.location)) {
0932:                                if ((isTests && !model.isTestSourceFolder(sf))
0933:                                        || (!isTests && model
0934:                                                .isTestSourceFolder(sf))) {
0935:                                    invalidRoots.add(sourceLoc);
0936:                                }
0937:                                continue FILE;
0938:                            }
0939:                        }
0940:
0941:                        JavaProjectGenerator.SourceFolder sf = new JavaProjectGenerator.SourceFolder();
0942:                        sf.location = location;
0943:                        sf.type = ProjectModel.TYPE_JAVA;
0944:                        sf.style = JavaProjectNature.STYLE_PACKAGES;
0945:                        sf.label = getDefaultLabel(sf.location, isTests);
0946:                        if (!sourceFolders.isEmpty()) {
0947:                            JavaProjectGenerator.SourceFolder prototype = sourceFolders
0948:                                    .iterator().next();
0949:                            sf.includes = prototype.includes;
0950:                            sf.excludes = prototype.excludes;
0951:                        }
0952:                        sf.encoding = model.getEncoding();
0953:                        model.addSourceFolder(sf, isTests);
0954:                    }
0955:                }
0956:
0957:                return invalidRoots;
0958:            }
0959:
0960:            private static boolean isParentOf(File parent, File child) {
0961:                while (child != null && !child.equals(parent))
0962:                    child = child.getParentFile();
0963:
0964:                return child != null && child.equals(parent);
0965:            }
0966:
0967:            private void showInvalidRootsWarning(Set<File> invalidRoots) {
0968:                JButton closeOption = new JButton(NbBundle
0969:                        .getMessage(SourceFoldersPanel.class,
0970:                                "CTL_SourceFolderPanel_Close"));
0971:                closeOption.getAccessibleContext().setAccessibleDescription(
0972:                        NbBundle.getMessage(SourceFoldersPanel.class,
0973:                                "AD_SourceFolderPanel_Close"));
0974:                JPanel warning = new WarningDlg(invalidRoots);
0975:                String message = NbBundle.getMessage(SourceFoldersPanel.class,
0976:                        "MSG_InvalidRoot");
0977:                JOptionPane optionPane = new JOptionPane(new Object[] {
0978:                        message, warning }, JOptionPane.WARNING_MESSAGE, 0,
0979:                        null, new Object[0], null);
0980:                optionPane.getAccessibleContext().setAccessibleDescription(
0981:                        NbBundle.getMessage(SourceFoldersPanel.class,
0982:                                "AD_InvalidRootDlg"));
0983:                DialogDescriptor dd = new DialogDescriptor(optionPane, NbBundle
0984:                        .getMessage(SourceFoldersPanel.class,
0985:                                "TITLE_InvalidRoot"), true,
0986:                        new Object[] { closeOption, }, closeOption,
0987:                        DialogDescriptor.DEFAULT_ALIGN, null, null);
0988:                DialogDisplayer.getDefault().notify(dd);
0989:            }
0990:
0991:            static String getDefaultLabel(String location, boolean isTests) {
0992:                if (location.equals(".")
0993:                        || ProjectConstants.PROJECT_LOCATION_PREFIX
0994:                                .equals(location + "/")) { // NOI18N
0995:                    // #54428 - src dir *is* project dir, so use a more reasonable name.
0996:                    return isTests ? NbBundle.getMessage(
0997:                            SourceFoldersPanel.class,
0998:                            "LBL_default_test_packages") : NbBundle.getMessage(
0999:                            SourceFoldersPanel.class,
1000:                            "LBL_default_source_packages");
1001:                }
1002:                // #47386 - remove "${project.dir}/" from label
1003:                String relloc = location;
1004:                if (relloc.startsWith(ProjectConstants.PROJECT_LOCATION_PREFIX)) {
1005:                    relloc = relloc
1006:                            .substring(ProjectConstants.PROJECT_LOCATION_PREFIX
1007:                                    .length());
1008:                }
1009:                return relloc.replace('/', File.separatorChar); // NOI18N // Fix for #45816 sourceLoc.getName();
1010:            }
1011:
1012:            /**
1013:             * Convert given string value (e.g. "${project.dir}/src" to a file
1014:             * and try to relativize it.
1015:             */
1016:            public static String getLocationDisplayName(
1017:                    PropertyEvaluator evaluator, File base, String val) {
1018:                File f = Util.resolveFile(evaluator, base, val);
1019:                if (f == null) {
1020:                    return val;
1021:                }
1022:                String location = f.getAbsolutePath();
1023:                if (CollocationQuery.areCollocated(base, f)) {
1024:                    location = PropertyUtils.relativizeFile(base, f).replace(
1025:                            '/', File.separatorChar); // NOI18N
1026:                }
1027:                return location;
1028:            }
1029:
1030:            private JavaProjectGenerator.SourceFolder getItem(int index,
1031:                    boolean tests) {
1032:                return model.getSourceFolder(calcRealSourceIndex(index, tests));
1033:            }
1034:
1035:            private int calcRealSourceIndex(int index, boolean tests) {
1036:                int realIndex = 0;
1037:                for (int i = 0; i < model.getSourceFoldersCount(); i++) {
1038:                    JavaProjectGenerator.SourceFolder sf = model
1039:                            .getSourceFolder(i);
1040:                    boolean isTest = model.isTestSourceFolder(sf);
1041:                    if (tests && !isTest) {
1042:                        continue;
1043:                    }
1044:                    if (!tests && isTest) {
1045:                        continue;
1046:                    }
1047:                    if (index == realIndex) {
1048:                        return i;
1049:                    }
1050:                    realIndex++;
1051:                }
1052:                throw new ArrayIndexOutOfBoundsException("index=" + index
1053:                        + " tests=" + tests + " realIndex=" + realIndex);
1054:            }
1055:
1056:            public boolean hasSomeSourceFolder() {
1057:                return model.getSourceFoldersCount() > 0;
1058:            }
1059:
1060:            // Variables declaration - do not modify//GEN-BEGIN:variables
1061:            private javax.swing.JButton addFolder;
1062:            private javax.swing.JButton addTestFolder;
1063:            private javax.swing.JButton downFolder;
1064:            private javax.swing.JButton downTestFolder;
1065:            private javax.swing.JComboBox encodingComboBox;
1066:            private javax.swing.JLabel encodingLabel;
1067:            private javax.swing.JButton includesExcludesButton;
1068:            private javax.swing.JLabel jLabel1;
1069:            private javax.swing.JLabel jLabel2;
1070:            private javax.swing.JLabel jLabel3;
1071:            private javax.swing.JLabel jLabel4;
1072:            private javax.swing.JLabel jLabel5;
1073:            private javax.swing.JPanel jPanel1;
1074:            private javax.swing.JScrollPane jScrollPane1;
1075:            private javax.swing.JScrollPane jScrollPane2;
1076:            private javax.swing.JTextArea jTextArea1;
1077:            private javax.swing.JButton removeFolder;
1078:            private javax.swing.JButton removeTestFolder;
1079:            private javax.swing.JTable sourceFolders;
1080:            private javax.swing.JComboBox sourceLevel;
1081:            private javax.swing.JTable testFolders;
1082:            private javax.swing.JButton upFolder;
1083:            private javax.swing.JButton upTestFolder;
1084:
1085:            // End of variables declaration//GEN-END:variables
1086:
1087:            public void setModel(ProjectModel model,
1088:                    AntProjectHelper projectHelper) {
1089:                this .model = model;
1090:                updateSourceLevelCombo(model.getSourceLevel());
1091:                updateEncodingCombo();
1092:                updateButtons();
1093:                sourceFoldersModel.fireTableDataChanged();
1094:            }
1095:
1096:            // XXX: this is copy of FreeformProjectGenerator.getAntScript
1097:            private static FileObject getAntScript(AntProjectHelper helper,
1098:                    PropertyEvaluator ev) {
1099:                //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
1100:                String antScript = ev
1101:                        .getProperty(ProjectConstants.PROP_ANT_SCRIPT);
1102:                if (antScript != null) {
1103:                    File f = helper.resolveFile(antScript);
1104:                    if (!f.exists()) {
1105:                        return null;
1106:                    }
1107:                    FileObject fo = FileUtil.toFileObject(f);
1108:                    return fo;
1109:                } else {
1110:                    FileObject fo = helper.getProjectDirectory().getFileObject(
1111:                            "build.xml"); // NOI18N
1112:                    return fo;
1113:                }
1114:            }
1115:
1116:            private class SourcesModel extends AbstractTableModel {
1117:
1118:                private boolean tests;
1119:
1120:                public SourcesModel(boolean tests) {
1121:                    this .tests = tests;
1122:                }
1123:
1124:                public int getColumnCount() {
1125:                    return isWizard ? 1 : 2;
1126:                }
1127:
1128:                public String getColumnName(int column) {
1129:                    switch (column) {
1130:                    case 0:
1131:                        return org.openide.util.NbBundle.getMessage(
1132:                                SourceFoldersPanel.class,
1133:                                "LBL_SourceFoldersPanel_Package");
1134:                    default:
1135:                        return org.openide.util.NbBundle.getMessage(
1136:                                SourceFoldersPanel.class,
1137:                                "LBL_SourceFoldersPanel_Label");
1138:                    }
1139:                }
1140:
1141:                public int getRowCount() {
1142:                    if (model == null)
1143:                        return 0;
1144:                    int count = 0;
1145:                    for (int i = 0; i < model.getSourceFoldersCount(); i++) {
1146:                        JavaProjectGenerator.SourceFolder sf = model
1147:                                .getSourceFolder(i);
1148:                        boolean isTest = model.isTestSourceFolder(sf);
1149:                        if (tests && isTest) {
1150:                            count++;
1151:                        }
1152:                        if (!tests && !isTest) {
1153:                            count++;
1154:                        }
1155:                    }
1156:                    return count;
1157:                }
1158:
1159:                public Object getValueAt(int rowIndex, int columnIndex) {
1160:                    if (columnIndex == 0) {
1161:                        String loc = getItem(rowIndex, tests).location;
1162:                        loc = getLocationDisplayName(model.getEvaluator(),
1163:                                model.getNBProjectFolder(), loc);
1164:                        return loc;
1165:                    } else {
1166:                        return getItem(rowIndex, tests).label;
1167:                    }
1168:                }
1169:
1170:                public boolean isCellEditable(int row, int column) {
1171:                    if (column == 1) {
1172:                        return true;
1173:                    } else {
1174:                        return false;
1175:                    }
1176:                }
1177:
1178:                public Class getColumnClass(int column) {
1179:                    return String.class;
1180:                }
1181:
1182:                public void setValueAt(Object val, int rowIndex, int columnIndex) {
1183:                    JavaProjectGenerator.SourceFolder sf = getItem(rowIndex,
1184:                            tests);
1185:                    sf.label = (String) val;
1186:                    if (sf.label.length() == 0) {
1187:                        sf.label = getDefaultLabel(sf.location, tests);
1188:                    }
1189:                }
1190:
1191:            }
1192:
1193:            private class EncodingModel extends DefaultComboBoxModel {
1194:                public EncodingModel() {
1195:                    Object selEnc = null;
1196:                    if (model.getEncoding() == null) {
1197:                        addElement(ProjectModel.NO_ENCODING);
1198:                        selEnc = ProjectModel.NO_ENCODING;
1199:                    }
1200:                    for (Charset cset : Charset.availableCharsets().values()) {
1201:                        if (cset.name().equals(model.getEncoding())) {
1202:                            selEnc = cset;
1203:                        }
1204:                        addElement(cset);
1205:                    }
1206:                    if (isWizard) {
1207:                        setSelectedItem(FileEncodingQuery.getDefaultEncoding());
1208:                    } else {
1209:                        if (selEnc != null) {
1210:                            setSelectedItem(selEnc);
1211:                        }
1212:                    }
1213:                }
1214:            }
1215:
1216:            private static class EncodingRenderer extends
1217:                    DefaultListCellRenderer implements  UIResource {
1218:
1219:                public EncodingRenderer() {
1220:                    setOpaque(true);
1221:                }
1222:
1223:                @Override
1224:                public Component getListCellRendererComponent(JList list,
1225:                        Object value, int index, boolean isSelected,
1226:                        boolean cellHasFocus) {
1227:                    setName("ComboBox.listRenderer"); // NOI18N
1228:                    String dispName = null;
1229:                    if (value instanceof  Charset) {
1230:                        dispName = ((Charset) value).displayName();
1231:                    } else {
1232:                        dispName = value.toString();
1233:                    }
1234:                    setText(dispName);
1235:                    setIcon(null);
1236:                    if (isSelected) {
1237:                        setBackground(list.getSelectionBackground());
1238:                        setForeground(list.getSelectionForeground());
1239:                    } else {
1240:                        setBackground(list.getBackground());
1241:                        setForeground(list.getForeground());
1242:                    }
1243:                    return this ;
1244:                }
1245:
1246:                @Override
1247:                public String getName() {
1248:                    String name = super .getName();
1249:                    return name == null ? "ComboBox.renderer" : name; // NOI18N
1250:                }
1251:
1252:            }
1253:
1254:            private class ToolTipRenderer extends DefaultTableCellRenderer {
1255:
1256:                public Component getTableCellRendererComponent(JTable table,
1257:                        Object value, boolean isSelected, boolean hasFocus,
1258:                        int row, int column) {
1259:                    Component c = super .getTableCellRendererComponent(table,
1260:                            value, isSelected, hasFocus, row, column);
1261:                    if (c instanceof  JComponent) {
1262:                        ((JComponent) c).setToolTipText((String) value);
1263:                    }
1264:                    return c;
1265:                }
1266:
1267:            }
1268:
1269:            private static class WarningDlg extends JPanel {
1270:
1271:                public WarningDlg(Set invalidRoots) {
1272:                    this .initGui(invalidRoots);
1273:                }
1274:
1275:                private void initGui(Set invalidRoots) {
1276:                    setLayout(new GridBagLayout());
1277:                    JLabel label = new JLabel();
1278:                    org.openide.awt.Mnemonics.setLocalizedText(label, NbBundle
1279:                            .getMessage(SourceFoldersPanel.class,
1280:                                    "LBL_InvalidRoot"));
1281:                    GridBagConstraints c = new GridBagConstraints();
1282:                    c.gridx = GridBagConstraints.RELATIVE;
1283:                    c.gridy = GridBagConstraints.RELATIVE;
1284:                    c.gridwidth = GridBagConstraints.REMAINDER;
1285:                    c.fill = GridBagConstraints.HORIZONTAL;
1286:                    c.anchor = GridBagConstraints.NORTHWEST;
1287:                    c.weightx = 1.0;
1288:                    c.insets = new Insets(12, 0, 6, 0);
1289:                    ((GridBagLayout) this .getLayout()).setConstraints(label, c);
1290:                    this .add(label);
1291:                    JList roots = new JList(invalidRoots.toArray());
1292:                    roots.setCellRenderer(new InvalidRootRenderer(true));
1293:                    JScrollPane p = new JScrollPane(roots);
1294:                    c = new GridBagConstraints();
1295:                    c.gridx = GridBagConstraints.RELATIVE;
1296:                    c.gridy = GridBagConstraints.RELATIVE;
1297:                    c.gridwidth = GridBagConstraints.REMAINDER;
1298:                    c.fill = GridBagConstraints.BOTH;
1299:                    c.anchor = GridBagConstraints.NORTHWEST;
1300:                    c.weightx = c.weighty = 1.0;
1301:                    c.insets = new Insets(0, 0, 12, 0);
1302:                    ((GridBagLayout) this .getLayout()).setConstraints(p, c);
1303:                    this .add(p);
1304:                    label.setLabelFor(roots);
1305:                    roots.getAccessibleContext().setAccessibleDescription(
1306:                            NbBundle.getMessage(SourceFoldersPanel.class,
1307:                                    "AD_InvalidRoot"));
1308:                    JLabel label2 = new JLabel();
1309:                    label2.setText(NbBundle.getMessage(
1310:                            SourceFoldersPanel.class, "MSG_InvalidRoot2"));
1311:                    c = new GridBagConstraints();
1312:                    c.gridx = GridBagConstraints.RELATIVE;
1313:                    c.gridy = GridBagConstraints.RELATIVE;
1314:                    c.gridwidth = GridBagConstraints.REMAINDER;
1315:                    c.fill = GridBagConstraints.HORIZONTAL;
1316:                    c.anchor = GridBagConstraints.NORTHWEST;
1317:                    c.weightx = 1.0;
1318:                    c.insets = new Insets(0, 0, 0, 0);
1319:                    ((GridBagLayout) this .getLayout())
1320:                            .setConstraints(label2, c);
1321:                    this .add(label2);
1322:                }
1323:
1324:                private static class InvalidRootRenderer extends
1325:                        DefaultListCellRenderer {
1326:
1327:                    private boolean projectConflict;
1328:
1329:                    public InvalidRootRenderer(boolean projectConflict) {
1330:                        this .projectConflict = projectConflict;
1331:                    }
1332:
1333:                    public Component getListCellRendererComponent(JList list,
1334:                            Object value, int index, boolean isSelected,
1335:                            boolean cellHasFocus) {
1336:                        File f = (File) value;
1337:                        String message = f.getAbsolutePath();
1338:                        if (projectConflict) {
1339:                            Project p = FileOwnerQuery.getOwner(f.toURI());
1340:                            if (p != null) {
1341:                                ProjectInformation pi = ProjectUtils
1342:                                        .getInformation(p);
1343:                                String projectName = pi.getDisplayName();
1344:                                message = NbBundle.getMessage(
1345:                                        SourceFoldersPanel.class,
1346:                                        "TXT_RootOwnedByProject", message,
1347:                                        projectName);
1348:                            }
1349:                        }
1350:                        return super.getListCellRendererComponent(list,
1351:                                message, index, isSelected, cellHasFocus);
1352:                    }
1353:                }
1354:            }
1355:
1356:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.