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