ada.project/src/org/netbeans/modules/ada/project/ui/wizards/ExistingAdaProjectPanelVisual.java
Add JVM compiler support.
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * If you wish your version of this file to be governed by only the CDDL
25 * or only the GPL Version 2, indicate your decision by adding
26 * "[Contributor] elects to include this software in this distribution
27 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28 * single choice of license, a recipient has the option to distribute
29 * your version of this file under either the CDDL, the GPL Version 2 or
30 * to extend the choice of license to its licensees as provided above.
31 * However, if you add GPL Version 2 code and therefore, elected the GPL
32 * Version 2 license, then the option applies only if the new code is
33 * made subject to such option by the copyright holder.
37 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40 package org.netbeans.modules.ada.project.ui.wizards;
43 import javax.swing.JFileChooser;
44 import javax.swing.event.DocumentEvent;
45 import javax.swing.event.DocumentListener;
46 import javax.swing.text.Document;
47 import org.netbeans.spi.project.ui.support.ProjectChooser;
48 import org.openide.WizardDescriptor;
49 import org.openide.WizardValidationException;
50 import org.openide.filesystems.FileUtil;
51 import org.openide.util.NbBundle;
55 * @author Andrea Lucarelli
57 class ExistingAdaProjectPanelVisual extends SettingsPanel implements DocumentListener {
59 private PanelConfigureProject panel;
63 * Creates new form ExistingAdaProjectPanelVisual
65 public ExistingAdaProjectPanelVisual(final PanelConfigureProject panel) {
72 private void postInitComponents () {
73 this.projectFolderTextField.getDocument().addDocumentListener(this);
74 this.projectNameTextField.getDocument().addDocumentListener(this);
77 /** This method is called from within the constructor to
78 * initialize the form.
79 * WARNING: Do NOT modify this code. The content of this method is
80 * always regenerated by the Form Editor.
82 @SuppressWarnings("unchecked")
83 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
84 private void initComponents() {
86 jLabel1 = new javax.swing.JLabel();
87 jLabel2 = new javax.swing.JLabel();
88 projectNameTextField = new javax.swing.JTextField();
89 projectFolderTextField = new javax.swing.JTextField();
90 browse = new javax.swing.JButton();
92 jLabel1.setLabelFor(projectNameTextField);
93 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "ExistingAdaProjectPanelVisual.projectName.text")); // NOI18N
95 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "ExistingAdaProjectPanelVisual.projectFolder.text")); // NOI18N
97 org.openide.awt.Mnemonics.setLocalizedText(browse, org.openide.util.NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "ExistingAdaProjectPanelVisual.browse.text")); // NOI18N
98 browse.addActionListener(new java.awt.event.ActionListener() {
99 public void actionPerformed(java.awt.event.ActionEvent evt) {
104 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
105 this.setLayout(layout);
106 layout.setHorizontalGroup(
107 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
108 .add(layout.createSequentialGroup()
109 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
112 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
113 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
114 .add(layout.createSequentialGroup()
115 .add(projectFolderTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
118 .add(projectNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE))
121 layout.setVerticalGroup(
122 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
123 .add(layout.createSequentialGroup()
125 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
127 .add(projectNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
128 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
129 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
131 .add(projectFolderTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
133 .addContainerGap(29, Short.MAX_VALUE))
135 }// </editor-fold>//GEN-END:initComponents
137 private void browseAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseAction
138 JFileChooser chooser = new JFileChooser();
139 FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
140 chooser.setDialogTitle(NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "LBL_SelectProjectFolder"));
141 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
142 String path = this.projectFolderTextField.getText();
143 if (path.length() > 0) {
144 File f = new File(path);
146 chooser.setSelectedFile(f);
149 if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
150 File projectDir = chooser.getSelectedFile();
151 projectFolderTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath());
153 panel.fireChangeEvent();
154 }//GEN-LAST:event_browseAction
157 // Variables declaration - do not modify//GEN-BEGIN:variables
158 private javax.swing.JButton browse;
159 private javax.swing.JLabel jLabel1;
160 private javax.swing.JLabel jLabel2;
161 private javax.swing.JTextField projectFolderTextField;
162 private javax.swing.JTextField projectNameTextField;
163 // End of variables declaration//GEN-END:variables
166 void store(WizardDescriptor settings) {
167 assert settings != null;
168 String name = projectNameTextField.getText().trim();
169 String folder = projectFolderTextField.getText().trim();
170 settings.putProperty(NewAdaProjectWizardIterator.PROP_PROJECT_LOCATION, FileUtil.normalizeFile(new File(folder)));
171 settings.putProperty(NewAdaProjectWizardIterator.PROP_PROJECT_NAME, name);
175 void read(WizardDescriptor settings) {
176 File projectLocation = (File) settings.getProperty(NewAdaProjectWizardIterator.PROP_PROJECT_LOCATION);
177 String defaultName = null;
178 if (projectLocation == null || projectLocation.getParentFile() == null || !projectLocation.getParentFile().isDirectory()) {
179 defaultName = NewAdaProjectWizardIterator.getFreeFolderName(ProjectChooser.getProjectsFolder(), "AdaApplication"); //NOI18N
180 projectLocation = new File (ProjectChooser.getProjectsFolder(),defaultName);
182 this.projectFolderTextField.setText(projectLocation.getAbsolutePath());
184 String projectName = (String) settings.getProperty(NewAdaProjectWizardIterator.PROP_PROJECT_NAME);
185 if (projectName == null) {
186 assert defaultName != null;
187 projectName = defaultName;
189 this.projectNameTextField.setText(projectName);
190 this.projectNameTextField.selectAll();
194 boolean valid(WizardDescriptor settings) {
195 if (projectNameTextField.getText().length() == 0) {
196 settings.putProperty("WizardPanel_errorMessage",
197 NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "ERR_WrongName"));
198 return false; // Display name not specified
200 File f = FileUtil.normalizeFile(new File(projectFolderTextField.getText()).getAbsoluteFile());
201 if (f.exists() && !f.isDirectory()) {
202 String message = NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "ERR_WrongProjectFolder");
203 settings.putProperty("WizardPanel_errorMessage", message);
207 if (f.exists() && !f.canWrite()) {
208 settings.putProperty("WizardPanel_errorMessage",
209 NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "ERR_ReadOnlyProjectFolder"));
213 if (f.exists() && FileUtil.toFileObject(f) == null) {
214 String message = NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "ERR_WrongProjectFolder");
215 settings.putProperty("WizardPanel_errorMessage", message);
219 File[] kids = f.listFiles();
221 for (File kid : kids) {
222 if ("nbproject".equals(kid.getName())) { //NOI18N
223 settings.putProperty("WizardPanel_errorMessage",
224 NbBundle.getMessage(ExistingAdaProjectPanelVisual.class, "ERR_AlreadyAnProject"));
229 settings.putProperty("WizardPanel_errorMessage", ""); //NOI18N
234 void validate(WizardDescriptor settings) throws WizardValidationException {
237 public void insertUpdate(DocumentEvent e) {
241 public void removeUpdate(DocumentEvent e) {
245 public void changedUpdate(DocumentEvent e) {
249 private void handleDocChange () {
250 this.panel.fireChangeEvent();