KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > BasicInfoVisualPanel


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

19
20 package org.netbeans.modules.apisupport.project.ui.wizard;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import javax.swing.ButtonModel JavaDoc;
28 import javax.swing.JComboBox JavaDoc;
29 import javax.swing.JFileChooser JavaDoc;
30 import javax.swing.event.DocumentEvent JavaDoc;
31 import javax.swing.event.DocumentListener JavaDoc;
32 import org.netbeans.api.project.Project;
33 import org.netbeans.api.project.ProjectManager;
34 import org.netbeans.api.project.ProjectUtils;
35 import org.netbeans.modules.apisupport.project.ui.ModuleUISettings;
36 import org.netbeans.modules.apisupport.project.universe.ModuleList;
37 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
38 import org.netbeans.modules.apisupport.project.ui.UIUtil;
39 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils;
40 import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory;
41 import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizer;
42 import org.netbeans.spi.project.ui.support.ProjectChooser;
43 import org.openide.DialogDescriptor;
44 import org.openide.DialogDisplayer;
45 import org.openide.ErrorManager;
46 import org.openide.filesystems.FileUtil;
47 import org.openide.util.NbBundle;
48
49 /**
50  * First panel of <code>NewNbModuleWizardIterator</code>. Allow user to enter
51  * basic module information:
52  *
53  * <ul>
54  * <li>Project name</li>
55  * <li>Project Location</li>
56  * <li>Project Folder</li>
57  * <li>If should be set as a Main Project</li>
58  * <li>NetBeans Platform (for standalone modules)</li>
59  * <li>Module Suite (for suite modules)</li>
60  * </ul>
61  *
62  * @author Martin Krauskopf
63  */

64 public class BasicInfoVisualPanel extends BasicVisualPanel.NewTemplatePanel {
65     
66     private ButtonModel JavaDoc lastSelectedType;
67     private static String JavaDoc lastSelectedSuite;
68     private boolean locationUpdated;
69     private boolean nameUpdated;
70     private boolean moduleTypeGroupAttached = true;
71     private boolean mainProjectTouched;
72     
73     /** Creates new form BasicInfoVisualPanel */
74     public BasicInfoVisualPanel(final NewModuleProjectData data) {
75         super(data);
76         initComponents();
77         initAccessibility();
78         initPlatformCombos();
79         setComponentsVisibility();
80         switch (data.getWizardType()) {
81             case NewNbModuleWizardIterator.TYPE_SUITE:
82                 detachModuleTypeGroup();
83                 break;
84             case NewNbModuleWizardIterator.TYPE_MODULE:
85             case NewNbModuleWizardIterator.TYPE_SUITE_COMPONENT:
86                 if (moduleSuiteValue.getItemCount() > 0) {
87                     restoreSelectedSuite();
88                     suiteComponent.setSelected(true);
89                     mainProject.setSelected(false);
90                 }
91                 break;
92             case NewNbModuleWizardIterator.TYPE_LIBRARY_MODULE:
93                 moduleSuite.setText(getMessage("LBL_Add_to_Suite")); // NOI18N
94
suiteComponent.setSelected(true);
95                 if (moduleSuiteValue.getItemCount() > 0) {
96                     restoreSelectedSuite();
97                 }
98                 break;
99             default:
100                 assert false : "Unknown wizard type = " + data.getWizardType();
101         }
102         attachDocumentListeners();
103         setInitialLocation();
104         setInitialProjectName();
105         updateEnabled();
106     }
107     
108     private void setInitialLocation() {
109         if (isSuiteComponent()) {
110             computeAndSetLocation((String JavaDoc) moduleSuiteValue.getSelectedItem(), true);
111         } else { // suite or standalone module
112
String JavaDoc location = computeLocationValue(ProjectChooser.getProjectsFolder().getAbsolutePath());
113             File JavaDoc locationF = new File JavaDoc(location);
114             if (SuiteUtils.isSuite(locationF)) {
115                 computeAndSetLocation(locationF.getParent(), true);
116             } else {
117                 setLocation(location, true);
118             }
119         }
120     }
121     
122     private void initAccessibility() {
123         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_BasicInfoVisualPanel"));
124         browseButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_BrowseButton"));
125         browseSuiteButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_BrowseSuiteButton"));
126         folderValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_FolderValue"));
127         locationValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_LocationValue"));
128         mainProject.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_MainProject"));
129         managePlatform.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ManagePlatform"));
130         manageSuitePlatform.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ManageSuitePlatform"));
131         moduleSuiteValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModuleSuiteValue"));
132         nameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_NameValue"));
133         platformValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PlatformValue"));
134         standAloneModule.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_StandAloneModule"));
135         suiteComponent.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_SuiteModule"));
136         suitePlatformValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_SuitePlatformValue"));
137     }
138     
139     private void setComponentsVisibility() {
140         boolean isSuiteWizard = isSuiteWizard();
141         boolean isSuiteComponentWizard = isSuiteComponentWizard();
142         boolean isLibraryWizard = isLibraryWizard();
143         
144         typeChooserPanel.setVisible(!isSuiteWizard);
145         suitePlatform.setVisible(isSuiteWizard);
146         suitePlatformValue.setVisible(isSuiteWizard);
147         manageSuitePlatform.setVisible(isSuiteWizard);
148         mainProject.setVisible(!isLibraryWizard);
149         
150         suiteComponent.setVisible(!isLibraryWizard);
151         platform.setVisible(!isLibraryWizard);
152         platformValue.setVisible(!isLibraryWizard);
153         managePlatform.setVisible(!isLibraryWizard);
154         standAloneModule.setVisible(!isLibraryWizard);
155         mainProject.setSelected(!isLibraryWizard);
156         
157         standAloneModule.setVisible(!isSuiteComponentWizard && !isLibraryWizard);
158         platform.setVisible(!isSuiteComponentWizard && !isLibraryWizard);
159         platformValue.setVisible(!isSuiteComponentWizard && !isLibraryWizard);
160         managePlatform.setVisible(!isSuiteComponentWizard && !isLibraryWizard);
161         suiteComponent.setVisible(!isSuiteComponentWizard && !isLibraryWizard);
162     }
163     
164     private void restoreSelectedSuite() {
165         String JavaDoc preferredSuiteDir = getPreferredSuiteDir();
166         if (preferredSuiteDir != null) {
167             lastSelectedSuite = preferredSuiteDir;
168         }
169         if (lastSelectedSuite != null) {
170             int max = moduleSuiteValue.getModel().getSize();
171             for (int i=0; i < max; i++) {
172                 if (lastSelectedSuite.equals(moduleSuiteValue.getModel().getElementAt(i))) {
173                     moduleSuiteValue.setSelectedItem(lastSelectedSuite);
174                     break;
175                 }
176             }
177         }
178     }
179     
180     private String JavaDoc getPreferredSuiteDir() {
181         return (String JavaDoc) getSettings().getProperty(NewNbModuleWizardIterator.PREFERRED_SUITE_DIR);
182     }
183     
184     private boolean isOneSuiteDedicatedMode() {
185         Boolean JavaDoc b = (Boolean JavaDoc) getSettings().getProperty(
186                 NewNbModuleWizardIterator.ONE_SUITE_DEDICATED_MODE);
187         return b != null ? b.booleanValue() : false;
188     }
189     
190     private String JavaDoc getNameValue() {
191         return nameValue.getText().trim();
192     }
193     
194     private String JavaDoc getLocationValue() {
195         return locationValue.getText().trim();
196     }
197     
198     private File JavaDoc getLocationFile() {
199         return new File JavaDoc(getLocationValue());
200     }
201     
202     private void updateEnabled() {
203         boolean isNetBeansOrg = isNetBeansOrgFolder();
204         standAloneModule.setEnabled(!isNetBeansOrg);
205         suiteComponent.setEnabled(!isNetBeansOrg);
206         
207         boolean standalone = isStandAlone();
208         boolean suiteModuleSelected = isSuiteComponent();
209         platform.setEnabled(standalone);
210         platformValue.setEnabled(standalone);
211         managePlatform.setEnabled(standalone);
212         moduleSuite.setEnabled(suiteModuleSelected);
213         moduleSuiteValue.setEnabled(suiteModuleSelected && !isOneSuiteDedicatedMode());
214         browseSuiteButton.setEnabled(suiteModuleSelected && !isOneSuiteDedicatedMode());
215     }
216     
217     void updateAndCheck() {
218         updateGUI();
219         
220         if ("".equals(getNameValue())) {
221             setError(getMessage("MSG_NameCannotBeEmpty"));
222         } else if ("".equals(getLocationValue())) {
223             setError(getMessage("MSG_LocationCannotBeEmpty"));
224         } else if (isLibraryWizard() && isNetBeansOrgFolder()) {
225             setError(getMessage("MSG_LibraryWrapperForNBOrgUnsupported"));
226         } else if (isSuiteComponent() && moduleSuiteValue.getSelectedItem() == null) {
227             setError(getMessage("MSG_ChooseRegularSuite"));
228         } else if (isStandAlone() &&
229                 (platformValue.getSelectedItem() == null || !((NbPlatform) platformValue.getSelectedItem()).isValid())) {
230             setError(getMessage("MSG_ChosenPlatformIsInvalid"));
231         } else if (isSuiteWizard() &&
232                 (suitePlatformValue.getSelectedItem() == null || !((NbPlatform) suitePlatformValue.getSelectedItem()).isValid())) {
233             setError(getMessage("MSG_ChosenPlatformIsInvalid"));
234         } else if (getFolder().exists()) {
235             setError(getMessage("MSG_ProjectFolderExists"));
236         } else if (!getLocationFile().exists()) {
237             setError(getMessage("MSG_LocationMustExist"));
238         } else if (!getLocationFile().canWrite()) {
239             setError(getMessage("MSG_LocationNotWritable"));
240         } else {
241             markValid();
242         }
243     }
244     
245     private void updateGUI() {
246         // update project folder
247
folderValue.setText(getFolder().getPath());
248         
249         if (isSuiteWizard() || isNetBeansOrgFolder()) {
250             detachModuleTypeGroup();
251         } else {
252             attachModuleTypeGroup();
253         }
254         updateEnabled();
255     }
256     
257     private void detachModuleTypeGroup() {
258         if (moduleTypeGroupAttached) {
259             lastSelectedType = moduleTypeGroup.getSelection();
260             moduleTypeGroup.remove(standAloneModule);
261             moduleTypeGroup.remove(suiteComponent);
262             standAloneModule.setSelected(false);
263             suiteComponent.setSelected(false);
264             moduleTypeGroupAttached = false;
265         }
266     }
267     
268     private void attachModuleTypeGroup() {
269         if (!moduleTypeGroupAttached) {
270             moduleTypeGroup.add(standAloneModule);
271             moduleTypeGroup.add(suiteComponent);
272             if (isLibraryWizard()) {
273                 suiteComponent.setSelected(true);
274             } else {
275                 moduleTypeGroup.setSelected(lastSelectedType, true);
276             }
277             moduleTypeGroupAttached = true;
278         }
279     }
280     
281     /** Set <em>next</em> free project name. */
282     private void setProjectName(String JavaDoc formater, int counter) {
283         String JavaDoc name;
284         while ((name = validFreeModuleName(formater, counter)) == null) {
285             counter++;
286         }
287         nameValue.setText(name);
288     }
289     
290     // stolen (then adjusted) from j2seproject
291
private String JavaDoc validFreeModuleName(String JavaDoc formater, int index) {
292         String JavaDoc name = MessageFormat.format(formater, new Object JavaDoc[]{ new Integer JavaDoc(index) });
293         File JavaDoc file = new File JavaDoc(getLocationValue(), name);
294         return file.exists() ? null : name;
295     }
296     
297     /** Stores collected data into model. */
298     void storeData() {
299         getData().setProjectName(getNameValue());
300         getData().setProjectLocation(getLocationValue());
301         getData().setProjectFolder(folderValue.getText());
302         getData().setMainProject(mainProject.isSelected());
303         getData().setNetBeansOrg(isNetBeansOrgFolder());
304         getData().setStandalone(isStandAlone());
305         getData().setSuiteRoot((String JavaDoc) moduleSuiteValue.getSelectedItem());
306         if (isSuiteWizard() && suitePlatformValue.getSelectedItem() != null) {
307             getData().setPlatformID(((NbPlatform) suitePlatformValue.getSelectedItem()).getID());
308         } else if (platformValue.getSelectedItem() != null) {
309             getData().setPlatformID(((NbPlatform) platformValue.getSelectedItem()).getID());
310         }
311     }
312     
313     void refreshData() {
314         if (getData().getProjectName() != null) {
315             nameValue.setText(getData().getProjectName());
316         } else {
317             setInitialProjectName();
318         }
319     }
320     
321     private void setInitialProjectName() {
322         String JavaDoc bundlekey = null;
323         int counter = 0;
324         switch (getData().getWizardType()) {
325             case NewNbModuleWizardIterator.TYPE_SUITE:
326                 counter = ModuleUISettings.getDefault().getNewSuiteCounter() + 1;
327                 bundlekey = "TXT_Suite"; //NOI18N
328
getData().setSuiteCounter(counter);
329                 break;
330             case NewNbModuleWizardIterator.TYPE_MODULE:
331             case NewNbModuleWizardIterator.TYPE_SUITE_COMPONENT:
332                 counter = ModuleUISettings.getDefault().getNewModuleCounter() + 1;
333                 bundlekey = "TXT_Module"; //NOI18N
334
getData().setModuleCounter(counter);
335                 break;
336             case NewNbModuleWizardIterator.TYPE_LIBRARY_MODULE:
337                 counter = ModuleUISettings.getDefault().getNewModuleCounter() + 1;
338                 bundlekey = "TXT_Library"; //NOI18N
339
getData().setModuleCounter(counter);
340                 break;
341             default:
342                 assert false : "Unknown wizard type = " + getData().getWizardType();
343         }
344         setProjectName(getMessage(bundlekey), counter);
345         nameValue.select(0, nameValue.getText().length());
346         nameUpdated = false;
347     }
348     
349     private void attachDocumentListeners() {
350         DocumentListener JavaDoc fieldsDL = new UIUtil.DocumentAdapter() {
351             public void insertUpdate(DocumentEvent JavaDoc e) { updateAndCheck(); }
352         };
353         nameValue.getDocument().addDocumentListener(fieldsDL);
354         nameValue.getDocument().addDocumentListener(new UIUtil.DocumentAdapter() {
355             public void insertUpdate(DocumentEvent JavaDoc e) { nameUpdated = true; }
356         });
357         locationValue.getDocument().addDocumentListener(fieldsDL);
358         locationValue.getDocument().addDocumentListener(new UIUtil.DocumentAdapter() {
359             public void insertUpdate(DocumentEvent JavaDoc e) { locationUpdated = true; }
360         });
361         ActionListener JavaDoc plafAL = new ActionListener JavaDoc() {
362             public void actionPerformed(ActionEvent JavaDoc e) {
363                 updateAndCheck();
364             }
365         };
366         platformValue.addActionListener(plafAL);
367         suitePlatformValue.addActionListener(plafAL);
368     }
369     
370     private File JavaDoc getFolder() {
371         StringBuffer JavaDoc destFolder = new StringBuffer JavaDoc(getLocationValue());
372         if (destFolder.length() != 0) {
373             destFolder.append(File.separator);
374         }
375         destFolder.append(getNameValue());
376         return FileUtil.normalizeFile(new File JavaDoc(destFolder.toString()));
377     }
378     
379     private boolean isNetBeansOrgFolder() {
380         return ModuleList.findNetBeansOrg(getFolder()) != null;
381     }
382     
383     private static String JavaDoc getMessage(String JavaDoc key) {
384         return NbBundle.getMessage(BasicInfoVisualPanel.class, key);
385     }
386     
387     private void initPlatformCombos() {
388         if (platformValue.getItemCount() <= 0) {
389             return;
390         }
391         boolean set = false;
392         String JavaDoc idToSelect = ModuleUISettings.getDefault().getLastUsedPlatformID();
393         for (int i = 0; i < platformValue.getItemCount(); i++) {
394             if (((NbPlatform) platformValue.getItemAt(i)).getID().equals(idToSelect)) {
395                 platformValue.setSelectedIndex(i);
396                 suitePlatformValue.setSelectedIndex(i);
397                 set = true;
398                 break;
399             }
400         }
401         if (!set) {
402             NbPlatform defPlaf = NbPlatform.getDefaultPlatform();
403             platformValue.setSelectedItem(defPlaf == null ? platformValue.getItemAt(0) : defPlaf);
404             suitePlatformValue.setSelectedItem(defPlaf == null ? suitePlatformValue.getItemAt(0) : defPlaf);
405         }
406     }
407     
408     private void setLocation(String JavaDoc location, boolean silently) {
409         boolean revert = silently && !locationUpdated;
410         locationValue.setText(location);
411         locationUpdated = revert ^ true;
412     }
413     
414     private void computeAndSetLocation(String JavaDoc value, boolean silently) {
415         setLocation(computeLocationValue(value), silently);
416     }
417     
418     private String JavaDoc computeLocationValue(String JavaDoc value) {
419         if (value == null) {
420             value = System.getProperty("user.home"); // NOI18N
421
}
422         File JavaDoc file = new File JavaDoc(value);
423         if (!file.exists() && file.getParent() != null) {
424             return computeLocationValue(file.getParent());
425         } else {
426             return file.exists() ? value : System.getProperty("user.home"); // NOI18N
427
}
428     }
429     
430     private boolean isStandAlone() {
431         return standAloneModule.isSelected();
432     }
433     
434     private boolean isSuiteComponent() {
435         return suiteComponent.isSelected();
436     }
437     
438     /** This method is called from within the constructor to
439      * initialize the form.
440      * WARNING: Do NOT modify this code. The content of this method is
441      * always regenerated by the Form Editor.
442      */

443     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
444
private void initComponents() {
445         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
446
447         moduleTypeGroup = new javax.swing.ButtonGroup JavaDoc();
448         infoPanel = new javax.swing.JPanel JavaDoc();
449         nameLbl = new javax.swing.JLabel JavaDoc();
450         locationLbl = new javax.swing.JLabel JavaDoc();
451         folderLbl = new javax.swing.JLabel JavaDoc();
452         nameValue = new javax.swing.JTextField JavaDoc();
453         locationValue = new javax.swing.JTextField JavaDoc();
454         browseButton = new javax.swing.JButton JavaDoc();
455         filler = new javax.swing.JLabel JavaDoc();
456         folderValue = new javax.swing.JTextField JavaDoc();
457         suitePlatform = new javax.swing.JLabel JavaDoc();
458         suitePlatformValue = PlatformComponentFactory.getNbPlatformsComboxBox();
459         manageSuitePlatform = new javax.swing.JButton JavaDoc();
460         separator3 = new javax.swing.JSeparator JavaDoc();
461         mainProject = new javax.swing.JCheckBox JavaDoc();
462         typeChooserPanel = new javax.swing.JPanel JavaDoc();
463         standAloneModule = new javax.swing.JRadioButton JavaDoc();
464         platform = new javax.swing.JLabel JavaDoc();
465         platformValue = PlatformComponentFactory.getNbPlatformsComboxBox();
466         managePlatform = new javax.swing.JButton JavaDoc();
467         suiteComponent = new javax.swing.JRadioButton JavaDoc();
468         moduleSuite = new javax.swing.JLabel JavaDoc();
469         moduleSuiteValue = PlatformComponentFactory.getSuitesComboBox();
470         browseSuiteButton = new javax.swing.JButton JavaDoc();
471         chooserFiller = new javax.swing.JLabel JavaDoc();
472         pnlThouShaltBeholdLayout = new javax.swing.JPanel JavaDoc();
473
474         setLayout(new java.awt.GridBagLayout JavaDoc());
475
476         infoPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
477
478         nameLbl.setLabelFor(nameValue);
479         org.openide.awt.Mnemonics.setLocalizedText(nameLbl, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "LBL_ProjectName"));
480         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
481         gridBagConstraints.gridx = 0;
482         gridBagConstraints.gridy = 0;
483         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
484         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
485         infoPanel.add(nameLbl, gridBagConstraints);
486
487         locationLbl.setLabelFor(locationValue);
488         org.openide.awt.Mnemonics.setLocalizedText(locationLbl, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "LBL_ProjectLocation"));
489         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
490         gridBagConstraints.gridx = 0;
491         gridBagConstraints.gridy = 1;
492         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
493         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 12);
494         infoPanel.add(locationLbl, gridBagConstraints);
495
496         folderLbl.setLabelFor(folderValue);
497         org.openide.awt.Mnemonics.setLocalizedText(folderLbl, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "LBL_ProjectFolder"));
498         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
499         gridBagConstraints.gridx = 0;
500         gridBagConstraints.gridy = 2;
501         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
502         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
503         infoPanel.add(folderLbl, gridBagConstraints);
504
505         nameValue.setHorizontalAlignment(javax.swing.JTextField.LEFT);
506         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
507         gridBagConstraints.gridx = 1;
508         gridBagConstraints.gridy = 0;
509         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
510         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
511         gridBagConstraints.weightx = 1.0;
512         infoPanel.add(nameValue, gridBagConstraints);
513
514         locationValue.setHorizontalAlignment(javax.swing.JTextField.LEFT);
515         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
516         gridBagConstraints.gridx = 1;
517         gridBagConstraints.gridy = 1;
518         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
519         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
520         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
521         infoPanel.add(locationValue, gridBagConstraints);
522
523         org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "CTL_BrowseButton_o"));
524         browseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
525             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
526                 browseLocation(evt);
527             }
528         });
529
530         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
531         gridBagConstraints.gridx = 2;
532         gridBagConstraints.gridy = 1;
533         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 6, 0);
534         infoPanel.add(browseButton, gridBagConstraints);
535
536         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
537         gridBagConstraints.gridx = 1;
538         gridBagConstraints.gridy = 5;
539         gridBagConstraints.weighty = 1.0;
540         infoPanel.add(filler, gridBagConstraints);
541
542         folderValue.setEditable(false);
543         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
544         gridBagConstraints.gridx = 1;
545         gridBagConstraints.gridy = 2;
546         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
547         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
548         infoPanel.add(folderValue, gridBagConstraints);
549
550         suitePlatform.setLabelFor(suitePlatformValue);
551         org.openide.awt.Mnemonics.setLocalizedText(suitePlatform, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "LBL_NetBeansPlatform"));
552         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
553         gridBagConstraints.gridx = 0;
554         gridBagConstraints.gridy = 4;
555         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
556         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 12);
557         infoPanel.add(suitePlatform, gridBagConstraints);
558
559         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
560         gridBagConstraints.gridx = 1;
561         gridBagConstraints.gridy = 4;
562         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
563         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
564         gridBagConstraints.weightx = 1.0;
565         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
566         infoPanel.add(suitePlatformValue, gridBagConstraints);
567
568         org.openide.awt.Mnemonics.setLocalizedText(manageSuitePlatform, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "CTL_ManagePlatforms_g"));
569         manageSuitePlatform.addActionListener(new java.awt.event.ActionListener JavaDoc() {
570             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
571                 manageSuitePlatformActionPerformed(evt);
572             }
573         });
574
575         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
576         gridBagConstraints.gridx = 2;
577         gridBagConstraints.gridy = 4;
578         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
579         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
580         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 6, 0);
581         infoPanel.add(manageSuitePlatform, gridBagConstraints);
582
583         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
584         gridBagConstraints.gridx = 0;
585         gridBagConstraints.gridy = 3;
586         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
587         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
588         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
589         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 6, 0);
590         infoPanel.add(separator3, gridBagConstraints);
591
592         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
593         gridBagConstraints.gridx = 0;
594         gridBagConstraints.gridy = 0;
595         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
596         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
597         add(infoPanel, gridBagConstraints);
598
599         mainProject.setSelected(true);
600         org.openide.awt.Mnemonics.setLocalizedText(mainProject, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "CTL_SetAsMainProject"));
601         mainProject.addActionListener(new java.awt.event.ActionListener JavaDoc() {
602             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
603                 mainProjectActionPerformed(evt);
604             }
605         });
606
607         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
608         gridBagConstraints.gridx = 0;
609         gridBagConstraints.gridy = 2;
610         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
611         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
612         add(mainProject, gridBagConstraints);
613
614         typeChooserPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
615
616         moduleTypeGroup.add(standAloneModule);
617         standAloneModule.setSelected(true);
618         org.openide.awt.Mnemonics.setLocalizedText(standAloneModule, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "CTL_StandaloneModule"));
619         standAloneModule.addActionListener(new java.awt.event.ActionListener JavaDoc() {
620             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
621                 typeChanged(evt);
622             }
623         });
624
625         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
626         gridBagConstraints.gridx = 0;
627         gridBagConstraints.gridy = 0;
628         gridBagConstraints.gridwidth = 3;
629         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
630         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
631         typeChooserPanel.add(standAloneModule, gridBagConstraints);
632
633         platform.setLabelFor(platformValue);
634         org.openide.awt.Mnemonics.setLocalizedText(platform, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "LBL_NetBeansPlatform"));
635         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
636         gridBagConstraints.gridx = 0;
637         gridBagConstraints.gridy = 1;
638         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
639         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 18, 0, 12);
640         typeChooserPanel.add(platform, gridBagConstraints);
641
642         platformValue.addActionListener(new java.awt.event.ActionListener JavaDoc() {
643             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
644                 platformChosen(evt);
645             }
646         });
647
648         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
649         gridBagConstraints.gridx = 1;
650         gridBagConstraints.gridy = 1;
651         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
652         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
653         gridBagConstraints.weightx = 1.0;
654         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
655         typeChooserPanel.add(platformValue, gridBagConstraints);
656
657         org.openide.awt.Mnemonics.setLocalizedText(managePlatform, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "CTL_ManagePlatforms_g"));
658         managePlatform.addActionListener(new java.awt.event.ActionListener JavaDoc() {
659             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
660                 managePlatformActionPerformed(evt);
661             }
662         });
663
664         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
665         gridBagConstraints.gridx = 2;
666         gridBagConstraints.gridy = 1;
667         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
668         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
669         typeChooserPanel.add(managePlatform, gridBagConstraints);
670
671         moduleTypeGroup.add(suiteComponent);
672         org.openide.awt.Mnemonics.setLocalizedText(suiteComponent, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "CTL_AddToModuleSuite"));
673         suiteComponent.addActionListener(new java.awt.event.ActionListener JavaDoc() {
674             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
675                 typeChanged(evt);
676             }
677         });
678
679         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
680         gridBagConstraints.gridx = 0;
681         gridBagConstraints.gridy = 2;
682         gridBagConstraints.gridwidth = 3;
683         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
684         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 0, 0);
685         typeChooserPanel.add(suiteComponent, gridBagConstraints);
686
687         moduleSuite.setLabelFor(moduleSuiteValue);
688         org.openide.awt.Mnemonics.setLocalizedText(moduleSuite, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "LBL_ModuleSuite"));
689         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
690         gridBagConstraints.gridx = 0;
691         gridBagConstraints.gridy = 3;
692         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
693         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 18, 0, 12);
694         typeChooserPanel.add(moduleSuite, gridBagConstraints);
695
696         moduleSuiteValue.addActionListener(new java.awt.event.ActionListener JavaDoc() {
697             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
698                 moduleSuiteChosen(evt);
699             }
700         });
701
702         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
703         gridBagConstraints.gridx = 1;
704         gridBagConstraints.gridy = 3;
705         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
706         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
707         gridBagConstraints.weightx = 1.0;
708         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 12);
709         typeChooserPanel.add(moduleSuiteValue, gridBagConstraints);
710
711         org.openide.awt.Mnemonics.setLocalizedText(browseSuiteButton, org.openide.util.NbBundle.getMessage(BasicInfoVisualPanel.class, "CTL_BrowseButton_w"));
712         browseSuiteButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
713             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
714                 browseModuleSuite(evt);
715             }
716         });
717
718         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
719         gridBagConstraints.gridx = 2;
720         gridBagConstraints.gridy = 3;
721         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
722         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
723         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
724         typeChooserPanel.add(browseSuiteButton, gridBagConstraints);
725
726         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
727         gridBagConstraints.gridx = 0;
728         gridBagConstraints.gridy = 4;
729         gridBagConstraints.weighty = 1.0;
730         typeChooserPanel.add(chooserFiller, gridBagConstraints);
731
732         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
733         gridBagConstraints.gridx = 0;
734         gridBagConstraints.gridy = 1;
735         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
736         add(typeChooserPanel, gridBagConstraints);
737
738         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
739         gridBagConstraints.gridx = 0;
740         gridBagConstraints.gridy = 3;
741         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
742         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
743         gridBagConstraints.weightx = 1.0;
744         gridBagConstraints.weighty = 1.0;
745         add(pnlThouShaltBeholdLayout, gridBagConstraints);
746
747     }// </editor-fold>//GEN-END:initComponents
748

749     private void manageSuitePlatformActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manageSuitePlatformActionPerformed
750
managePlatform(suitePlatformValue);
751     }//GEN-LAST:event_manageSuitePlatformActionPerformed
752

753     private void mainProjectActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_mainProjectActionPerformed
754
mainProjectTouched = true;
755     }//GEN-LAST:event_mainProjectActionPerformed
756

757     private void managePlatformActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_managePlatformActionPerformed
758
managePlatform(platformValue);
759     }//GEN-LAST:event_managePlatformActionPerformed
760

761     private void managePlatform(final JComboBox JavaDoc platformCombo) {
762         NbPlatformCustomizer.showCustomizer();
763         platformCombo.setModel(new PlatformComponentFactory.NbPlatformListModel()); // refresh
764
platformCombo.requestFocus();
765         updateAndCheck();
766     }
767     
768     private void platformChosen(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_platformChosen
769
updateAndCheck();
770     }//GEN-LAST:event_platformChosen
771

772     private void moduleSuiteChosen(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_moduleSuiteChosen
773
if (!locationUpdated) {
774             String JavaDoc suite = (String JavaDoc) moduleSuiteValue.getSelectedItem();
775             computeAndSetLocation(suite, true);
776             lastSelectedSuite = suite;
777         }
778         updateAndCheck();
779     }//GEN-LAST:event_moduleSuiteChosen
780

781     private void browseModuleSuite(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseModuleSuite
782
JFileChooser JavaDoc chooser = ProjectChooser.projectChooser();
783         int option = chooser.showOpenDialog(this);
784         if (option == JFileChooser.APPROVE_OPTION) {
785             File JavaDoc projectDir = chooser.getSelectedFile();
786             UIUtil.setProjectChooserDirParent(projectDir);
787             try {
788                 Project suite = ProjectManager.getDefault().findProject(
789                         FileUtil.toFileObject(projectDir));
790                 if (suite != null) {
791                     String JavaDoc suiteDir = SuiteUtils.getSuiteDirectoryPath(suite);
792                     if (suiteDir != null) {
793                         // register for this session
794
PlatformComponentFactory.addUserSuite(suiteDir);
795                         // add to current combobox
796
moduleSuiteValue.addItem(suiteDir);
797                         moduleSuiteValue.setSelectedItem(suiteDir);
798                     } else {
799                         DialogDisplayer.getDefault().notify(new DialogDescriptor.Message(
800                                 NbBundle.getMessage(BasicInfoVisualPanel.class, "MSG_NotRegularSuite",
801                                 ProjectUtils.getInformation(suite).getDisplayName())));
802                     }
803                 }
804             } catch (IOException JavaDoc e) {
805                 ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
806             }
807         }
808     }//GEN-LAST:event_browseModuleSuite
809

810     private void typeChanged(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_typeChanged
811
if (!mainProjectTouched) {
812             mainProject.setSelected(isStandAlone());
813         }
814         if (!locationUpdated) {
815             setInitialLocation();
816         }
817         if (!nameUpdated) {
818             setInitialProjectName();
819         }
820         updateAndCheck();
821     }//GEN-LAST:event_typeChanged
822

823     private void browseLocation(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseLocation
824
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(getLocationValue());
825         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
826         int ret = chooser.showOpenDialog(this);
827         if (ret == JFileChooser.APPROVE_OPTION) {
828             computeAndSetLocation(chooser.getSelectedFile().getAbsolutePath(), false);
829         }
830     }//GEN-LAST:event_browseLocation
831

832     // Variables declaration - do not modify//GEN-BEGIN:variables
833
private javax.swing.JButton JavaDoc browseButton;
834     private javax.swing.JButton JavaDoc browseSuiteButton;
835     private javax.swing.JLabel JavaDoc chooserFiller;
836     private javax.swing.JLabel JavaDoc filler;
837     private javax.swing.JLabel JavaDoc folderLbl;
838     private javax.swing.JTextField JavaDoc folderValue;
839     private javax.swing.JPanel JavaDoc infoPanel;
840     private javax.swing.JLabel JavaDoc locationLbl;
841     private javax.swing.JTextField JavaDoc locationValue;
842     private javax.swing.JCheckBox JavaDoc mainProject;
843     private javax.swing.JButton JavaDoc managePlatform;
844     private javax.swing.JButton JavaDoc manageSuitePlatform;
845     private javax.swing.JLabel JavaDoc moduleSuite;
846     private javax.swing.JComboBox JavaDoc moduleSuiteValue;
847     private javax.swing.ButtonGroup JavaDoc moduleTypeGroup;
848     private javax.swing.JLabel JavaDoc nameLbl;
849     javax.swing.JTextField JavaDoc nameValue;
850     private javax.swing.JLabel JavaDoc platform;
851     private javax.swing.JComboBox JavaDoc platformValue;
852     private javax.swing.JPanel JavaDoc pnlThouShaltBeholdLayout;
853     private javax.swing.JSeparator JavaDoc separator3;
854     private javax.swing.JRadioButton JavaDoc standAloneModule;
855     private javax.swing.JRadioButton JavaDoc suiteComponent;
856     private javax.swing.JLabel JavaDoc suitePlatform;
857     private javax.swing.JComboBox JavaDoc suitePlatformValue;
858     private javax.swing.JPanel JavaDoc typeChooserPanel;
859     // End of variables declaration//GEN-END:variables
860

861 }
862
Popular Tags