001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.compapp.projects.jbi.ui.wizards;
043:
044: import java.io.File;
045: import java.text.MessageFormat;
046:
047: import javax.swing.JFileChooser;
048: import javax.swing.event.DocumentEvent;
049: import javax.swing.event.DocumentListener;
050:
051: import org.openide.WizardDescriptor;
052:
053: public class PanelProjectAppVisual extends SettingsPanel implements
054: DocumentListener {
055:
056: private PanelConfigureProjectApp panel;
057:
058: /** Creates new form PanelProjectLocationVisual */
059: public PanelProjectAppVisual(PanelConfigureProjectApp panel) {
060: initComponents();
061: this .panel = panel;
062:
063: // Register listener on the textFields to make the automatic updates
064: /// projectNameTextField.getDocument().addDocumentListener(this);
065: /// projectLocationTextField.getDocument().addDocumentListener(this);
066: }
067:
068: /** This method is called from within the constructor to
069: * initialize the form.
070: * WARNING: Do NOT modify this code. The content of this method is
071: * always regenerated by the Form Editor.
072: */
073: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
074: private void initComponents() {
075: Label = new javax.swing.JLabel();
076: setAsMainCheckBox = new javax.swing.JCheckBox();
077: jLabel1 = new javax.swing.JLabel();
078: Button = new javax.swing.JButton();
079: jList1 = new javax.swing.JList();
080: jButton1 = new javax.swing.JButton();
081:
082: Label
083: .setDisplayedMnemonic(org.openide.util.NbBundle
084: .getMessage(PanelProjectAppVisual.class,
085: "LBL_NWP1_ProjectName_LabelMnemonic")
086: .charAt(0));
087: org.openide.awt.Mnemonics.setLocalizedText(Label,
088: org.openide.util.NbBundle.getMessage(
089: PanelProjectAppVisual.class,
090: "LBL_NWP1_SpecifyCreateApplication_Label"));
091:
092: setAsMainCheckBox.setSelected(true);
093: org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox,
094: org.openide.util.NbBundle.getMessage(
095: PanelProjectAppVisual.class,
096: "LBL_NWP1_AddToApplication_CheckBox"));
097: setAsMainCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
098:
099: jLabel1.setLabelFor(jList1);
100: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
101: org.openide.util.NbBundle.getMessage(
102: PanelProjectAppVisual.class,
103: "LBL_NWP1_CreatedProjectFolder_Lablel"));
104:
105: org.openide.awt.Mnemonics.setLocalizedText(Button,
106: org.openide.util.NbBundle.getMessage(
107: PanelProjectAppVisual.class,
108: "LBL_NWP1_BrowseLocation_Button"));
109: Button.setActionCommand("BROWSE");
110:
111: org.openide.awt.Mnemonics.setLocalizedText(jButton1,
112: org.openide.util.NbBundle.getMessage(
113: PanelProjectAppVisual.class,
114: "LBL_NWP1_NewProject_Button"));
115:
116: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
117: this );
118: this .setLayout(layout);
119: layout
120: .setHorizontalGroup(layout
121: .createParallelGroup(
122: org.jdesktop.layout.GroupLayout.LEADING)
123: .add(
124: layout
125: .createSequentialGroup()
126: .addContainerGap()
127: .add(
128: layout
129: .createParallelGroup(
130: org.jdesktop.layout.GroupLayout.LEADING)
131: .add(
132: layout
133: .createSequentialGroup()
134: .add(
135: layout
136: .createParallelGroup(
137: org.jdesktop.layout.GroupLayout.LEADING)
138: .add(
139: setAsMainCheckBox)
140: .add(
141: layout
142: .createSequentialGroup()
143: .add(
144: jLabel1)
145: .addPreferredGap(
146: org.jdesktop.layout.LayoutStyle.RELATED)
147: .add(
148: jList1,
149: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
150: 325,
151: Short.MAX_VALUE)))
152: .addPreferredGap(
153: org.jdesktop.layout.LayoutStyle.RELATED)
154: .add(
155: Button,
156: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
157: 97,
158: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
159: .add(
160: org.jdesktop.layout.GroupLayout.TRAILING,
161: jButton1)
162: .add(
163: Label,
164: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
165: 509,
166: Short.MAX_VALUE))
167: .addContainerGap()));
168:
169: layout.linkSize(new java.awt.Component[] { Button, jButton1 },
170: org.jdesktop.layout.GroupLayout.HORIZONTAL);
171:
172: layout
173: .setVerticalGroup(layout
174: .createParallelGroup(
175: org.jdesktop.layout.GroupLayout.LEADING)
176: .add(
177: layout
178: .createSequentialGroup()
179: .addContainerGap()
180: .add(Label)
181: .addPreferredGap(
182: org.jdesktop.layout.LayoutStyle.RELATED)
183: .add(setAsMainCheckBox)
184: .addPreferredGap(
185: org.jdesktop.layout.LayoutStyle.RELATED)
186: .add(
187: layout
188: .createParallelGroup(
189: org.jdesktop.layout.GroupLayout.BASELINE)
190: .add(
191: jLabel1,
192: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
193: 23,
194: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
195: .add(
196: jList1,
197: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
198: 23,
199: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
200: .add(Button))
201: .addPreferredGap(
202: org.jdesktop.layout.LayoutStyle.RELATED)
203: .add(jButton1).add(193, 193,
204: 193)));
205: }// </editor-fold>//GEN-END:initComponents
206:
207: public void addNotify() {
208: super .addNotify();
209: //same problem as in 31086, initial focus on Cancel button
210: /// projectNameTextField.requestFocus();
211: }
212:
213: boolean valid(WizardDescriptor wizardDescriptor) {
214: /// if (projectNameTextField.getText().length() == 0) {
215: /// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(PanelProjectLocationVisual.class,"MSG_IllegalProjectName")); // NOI18N
216: /// return false; // Display name not specified
217: /// }
218:
219: /// File destFolder = new File(createdFolderTextField.getText());
220: /// File[] children = destFolder.listFiles();
221: /// if (destFolder.exists() && children != null && children.length > 0) {
222: // Folder exists and is not empty
223: /// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(PanelProjectLocationVisual.class,"MSG_ProjectFolderExists")); // NOI18N
224: /// return false;
225: /// }
226:
227: /// wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); // NOI18N
228: return true;
229: }
230:
231: void store(WizardDescriptor d) {
232: /// String name = projectNameTextField.getText().trim();
233:
234: /// d.putProperty(WizardProperties.PROJECT_DIR, new File(createdFolderTextField.getText().trim()));
235: /// d.putProperty(WizardProperties.NAME, name);
236:
237: /// File projectsDir = new File(this.projectLocationTextField.getText());
238: /// if (projectsDir.isDirectory()) {
239: /// ProjectChooser.setProjectsFolder (projectsDir);
240: /// }
241: }
242:
243: void read(WizardDescriptor settings) {
244: /// File projectLocation = (File) settings.getProperty(WizardProperties.PROJECT_DIR);
245: /// if (projectLocation == null)
246: /// projectLocation = ProjectChooser.getProjectsFolder();
247: /// else
248: /// projectLocation = projectLocation.getParentFile();
249:
250: /// projectLocationTextField.setText(projectLocation.getAbsolutePath());
251:
252: /// String projectName = (String) settings.getProperty(WizardProperties.NAME);
253: /// if (projectName == null) {
254: /// int baseCount = FoldersListSettings.getDefault().getNewProjectCount() + 1;
255: /// String formater = NbBundle.getMessage(PanelProjectLocationVisual.class, "LBL_NPW1_DefaultProjectName");
256: /// while ((projectName = validFreeProjectName(projectLocation, formater, baseCount)) == null)
257: /// baseCount++;
258: /// settings.putProperty(NewJbiProjectWizardIterator.PROP_NAME_INDEX, new Integer(baseCount));
259: /// }
260:
261: /// projectNameTextField.setText(projectName);
262: /// projectNameTextField.selectAll();
263: }
264:
265: // Variables declaration - do not modify//GEN-BEGIN:variables
266: private javax.swing.JButton Button;
267: private javax.swing.JLabel Label;
268: private javax.swing.JButton jButton1;
269: private javax.swing.JLabel jLabel1;
270: private javax.swing.JList jList1;
271: private javax.swing.JCheckBox setAsMainCheckBox;
272:
273: // End of variables declaration//GEN-END:variables
274:
275: private static JFileChooser createChooser() {
276: JFileChooser chooser = new JFileChooser();
277: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
278: chooser.setAcceptAllFileFilterUsed(false);
279:
280: return chooser;
281: }
282:
283: private String validFreeProjectName(final File parentFolder,
284: final String formater, final int index) {
285: String name = MessageFormat.format(formater,
286: new Object[] { new Integer(index) });
287: File file = new File(parentFolder, name);
288: return file.exists() ? null : name;
289: }
290:
291: // Implementation of DocumentListener --------------------------------------
292: public void changedUpdate(DocumentEvent e) {
293: updateTexts(e);
294: }
295:
296: public void insertUpdate(DocumentEvent e) {
297: updateTexts(e);
298: }
299:
300: public void removeUpdate(DocumentEvent e) {
301: updateTexts(e);
302: }
303:
304: // End if implementation of DocumentListener -------------------------------
305:
306: /** Handles changes in the project name and project directory
307: */
308: private void updateTexts(DocumentEvent e) {
309: /// createdFolderTextField.setText(getCreatedFolderPath());
310:
311: /// panel.fireChangeEvent(); // Notify that the panel changed
312: }
313:
314: /// private String getCreatedFolderPath() {
315: /// StringBuffer folder = new StringBuffer(projectLocationTextField.getText().trim());
316: /// if (!projectLocationTextField.getText().endsWith(File.separator))
317: /// folder.append(File.separatorChar);
318: /// folder.append(projectNameTextField.getText().trim());
319:
320: /// return folder.toString();
321: /// }
322:
323: }
324:
325: //TODO implement check for project folder name and location
|