KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > wizard > DetectPanel


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.java.j2seplatform.wizard;
21
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.awt.GridBagLayout JavaDoc;
24 import java.io.File JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import java.net.URI JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.*;
29 import javax.swing.event.*;
30 import javax.swing.*;
31 import javax.swing.filechooser.FileFilter JavaDoc;
32 import org.netbeans.api.java.classpath.ClassPath;
33 import org.netbeans.api.progress.ProgressHandle;
34 import org.netbeans.api.progress.ProgressHandleFactory;
35 import org.netbeans.spi.project.support.ant.PropertyUtils;
36
37 import org.openide.filesystems.*;
38 import org.openide.util.NbBundle;
39 import org.openide.util.RequestProcessor;
40 import org.openide.util.Task;
41 import org.openide.util.TaskListener;
42 import org.openide.util.HelpCtx;
43
44 import org.netbeans.api.java.platform.JavaPlatform;
45 import org.netbeans.api.java.platform.JavaPlatformManager;
46 import org.netbeans.modules.java.j2seplatform.platformdefinition.J2SEPlatformImpl;
47 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
48 import org.openide.ErrorManager;
49 import org.openide.WizardDescriptor;
50
51 /**
52  * This Panel launches autoconfiguration during the New J2SE Platform sequence.
53  * The UI views properties of the platform, reacts to the end of detection by
54  * updating itself. It triggers the detection task when the button is pressed.
55  * The inner class WizardPanel acts as a controller, reacts to the UI completness
56  * (jdk name filled in) and autoconfig result (passed successfully) - and manages
57  * Next/Finish button (valid state) according to those.
58  *
59  * @author Svata Dedic
60  */

61 public class DetectPanel extends javax.swing.JPanel JavaDoc {
62
63     private NewJ2SEPlatform primaryPlatform;
64     private ArrayList listeners;
65
66     /**
67      * Creates a detect panel
68      * start the task and update on its completion
69      * @param p the platform being customized.
70      */

71     public DetectPanel(NewJ2SEPlatform primaryPlatform) {
72         initComponents();
73         postInitComponents ();
74         putClientProperty("WizardPanel_contentData",
75             new String JavaDoc[] {
76                 NbBundle.getMessage(DetectPanel.class,"TITLE_PlatformName"),
77         });
78         this.primaryPlatform = primaryPlatform;
79         this.setName (NbBundle.getMessage(DetectPanel.class,"TITLE_PlatformName"));
80     }
81
82     public void addNotify() {
83         super.addNotify();
84     }
85
86     private void postInitComponents () {
87         this.jdkName.getDocument().addDocumentListener (new DocumentListener () {
88
89             public void insertUpdate(DocumentEvent e) {
90                 handleNameChange ();
91             }
92
93             public void removeUpdate(DocumentEvent e) {
94                 handleNameChange ();
95             }
96
97             public void changedUpdate(DocumentEvent e) {
98                 handleNameChange ();
99             }
100         });
101         this.progressLabel.setVisible(false);
102         this.progressPanel.setVisible(false);
103     }
104
105     private void handleNameChange () {
106         this.fireChange();
107     }
108
109     /** This method is called from within the constructor to
110      * initialize the form.
111      * WARNING: Do NOT modify this code. The content of this method is
112      * always regenerated by the Form Editor.
113      */

114     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
115
private void initComponents() {
116         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
117
118         jLabel3 = new javax.swing.JLabel JavaDoc();
119         jdkName = new javax.swing.JTextField JavaDoc();
120         jPanel1 = new javax.swing.JPanel JavaDoc();
121         jLabel1 = new javax.swing.JLabel JavaDoc();
122         jLabel4 = new javax.swing.JLabel JavaDoc();
123         javadoc = new javax.swing.JTextField JavaDoc();
124         sources = new javax.swing.JTextField JavaDoc();
125         jButton1 = new javax.swing.JButton JavaDoc();
126         jButton2 = new javax.swing.JButton JavaDoc();
127         jPanel2 = new javax.swing.JPanel JavaDoc();
128         progressLabel = new javax.swing.JLabel JavaDoc();
129         progressPanel = new javax.swing.JPanel JavaDoc();
130
131         setLayout(new java.awt.GridBagLayout JavaDoc());
132
133         getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_DetectPanel"));
134         jLabel3.setLabelFor(jdkName);
135         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, NbBundle.getBundle(DetectPanel.class).getString("LBL_DetailsPanel_Name"));
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
138         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
139         add(jLabel3, gridBagConstraints);
140
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
143         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
144         gridBagConstraints.weightx = 1.0;
145         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
146         add(jdkName, gridBagConstraints);
147         jdkName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_PlatformName"));
148
149         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
150
151         jLabel1.setLabelFor(sources);
152         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("TXT_Sources"));
153         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
154         gridBagConstraints.gridx = 0;
155         gridBagConstraints.gridy = 0;
156         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
157         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
158         jPanel1.add(jLabel1, gridBagConstraints);
159
160         jLabel4.setLabelFor(javadoc);
161         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, NbBundle.getBundle(DetectPanel.class).getString("TXT_JavaDoc"));
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 0;
164         gridBagConstraints.gridy = 1;
165         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
167         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
168         jPanel1.add(jLabel4, gridBagConstraints);
169
170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.gridx = 1;
172         gridBagConstraints.gridy = 1;
173         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
174         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
175         gridBagConstraints.weightx = 1.0;
176         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
177         jPanel1.add(javadoc, gridBagConstraints);
178         javadoc.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_PlatformJavadoc"));
179
180         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridx = 1;
182         gridBagConstraints.gridy = 0;
183         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
184         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
185         gridBagConstraints.weightx = 1.0;
186         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
187         jPanel1.add(sources, gridBagConstraints);
188         sources.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_PlatformSources"));
189
190         org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("LBL_BrowseSources"));
191         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
192             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
193                 selectSources(evt);
194             }
195         });
196
197         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
198         gridBagConstraints.gridx = 2;
199         gridBagConstraints.gridy = 0;
200         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
201         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
202         jPanel1.add(jButton1, gridBagConstraints);
203         jButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_SelectSources"));
204
205         org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("LBL_BrowseJavadoc"));
206         jButton2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
207             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
208                 selectJavadoc(evt);
209             }
210         });
211
212         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213         gridBagConstraints.gridx = 2;
214         gridBagConstraints.gridy = 1;
215         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
216         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
217         jPanel1.add(jButton2, gridBagConstraints);
218         jButton2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_SelectJavadoc"));
219
220         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 0;
222         gridBagConstraints.gridy = 1;
223         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
224         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
225         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
226         gridBagConstraints.weightx = 1.0;
227         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 0, 0, 0);
228         add(jPanel1, gridBagConstraints);
229
230         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
231         gridBagConstraints.gridx = 0;
232         gridBagConstraints.gridy = 2;
233         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
234         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
235         gridBagConstraints.weightx = 1.0;
236         gridBagConstraints.weighty = 1.0;
237         add(jPanel2, gridBagConstraints);
238
239         progressLabel.setLabelFor(progressPanel);
240         org.openide.awt.Mnemonics.setLocalizedText(progressLabel, java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seplatform/wizard/Bundle").getString("TXT_PlatfromDetectProgress"));
241         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
242         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
243         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
244         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
245         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 6, 0);
246         add(progressLabel, gridBagConstraints);
247
248         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
249         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
250         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
251         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
252         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
253         add(progressPanel, gridBagConstraints);
254
255     }
256     // </editor-fold>//GEN-END:initComponents
257

258     private void selectJavadoc(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_selectJavadoc
259
String JavaDoc newValue = this.browse(this.javadoc.getText(),NbBundle.getMessage(DetectPanel.class,"TXT_SelectJavadoc"));
260         if (newValue != null) {
261             this.javadoc.setText(newValue);
262         }
263         
264     }//GEN-LAST:event_selectJavadoc
265

266     private void selectSources(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_selectSources
267
String JavaDoc newValue = this.browse(this.sources.getText(),NbBundle.getMessage(DetectPanel.class,"TXT_SelectSources"));
268         if (newValue != null) {
269             this.sources.setText(newValue);
270         }
271     }//GEN-LAST:event_selectSources
272

273     public final synchronized void addChangeListener (ChangeListener listener) {
274         if (this.listeners == null)
275             this.listeners = new ArrayList ();
276         this.listeners.add (listener);
277     }
278
279     public final synchronized void removeChangeListener (ChangeListener listener) {
280         if (this.listeners == null)
281             return;
282         this.listeners.remove (listener);
283     }
284
285     public String JavaDoc getPlatformName() {
286         return jdkName.getText();
287     }
288     
289     String JavaDoc getSources () {
290         String JavaDoc val = this.sources.getText();
291         return val.length() == 0 ? null : val;
292     }
293
294     void setSources (String JavaDoc sources) {
295         this.sources.setText (sources == null ? "" : sources); //NOI18N
296
}
297
298     String JavaDoc getJavadoc () {
299         String JavaDoc val = this.javadoc.getText();
300         return val.length() == 0 ? null : val;
301     }
302
303     void setJavadoc (String JavaDoc jdoc) {
304         this.javadoc.setText(jdoc == null ? "" : jdoc); //NOI18N
305
}
306
307     protected final void fireChange () {
308         Iterator it = null;
309         synchronized (this) {
310             if (this.listeners == null)
311                 return;
312             it = ((ArrayList)this.listeners.clone()).iterator();
313         }
314         ChangeEvent event = new ChangeEvent (this);
315         while (it.hasNext()) {
316             ((ChangeListener)it.next()).stateChanged(event);
317         }
318     }
319
320     /**
321      * Updates static information from the detected platform's properties
322      */

323     void updateData() {
324         Map m = primaryPlatform.getSystemProperties();
325         // if the name is empty, fill something in:
326
if ("".equals(jdkName.getText())) {
327             jdkName.setText(getInitialName (m));
328             this.jdkName.selectAll();
329         }
330     }
331
332
333     private static String JavaDoc getInitialName (Map m) {
334         String JavaDoc vmVersion = (String JavaDoc)m.get("java.specification.version"); //NOI18N
335
StringBuilder JavaDoc result = new StringBuilder JavaDoc(NbBundle.getMessage(DetectPanel.class,"TXT_DetectPanel_Java"));
336         if (vmVersion != null) {
337             result.append (vmVersion);
338         }
339         return result.toString();
340     }
341     
342     
343     private String JavaDoc browse (String JavaDoc oldValue, String JavaDoc title) {
344         JFileChooser chooser = new JFileChooser ();
345         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
346         chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
347         chooser.setFileFilter (new FileFilter JavaDoc () {
348             public boolean accept(File JavaDoc f) {
349                 return (f.exists() && f.canRead() && (f.isDirectory() || (f.getName().endsWith(".zip") || f.getName().endsWith(".jar"))));
350             }
351
352             public String JavaDoc getDescription() {
353                 return NbBundle.getMessage(DetectPanel.class,"TXT_ZipFilter");
354             }
355         });
356         File JavaDoc f = new File JavaDoc (oldValue);
357         chooser.setSelectedFile(f);
358         chooser.setDialogTitle (title);
359         if (chooser.showOpenDialog (this) == JFileChooser.APPROVE_OPTION) {
360             return chooser.getSelectedFile().getAbsolutePath();
361         }
362         return null;
363     }
364
365     // Variables declaration - do not modify//GEN-BEGIN:variables
366
private javax.swing.JButton JavaDoc jButton1;
367     private javax.swing.JButton JavaDoc jButton2;
368     private javax.swing.JLabel JavaDoc jLabel1;
369     private javax.swing.JLabel JavaDoc jLabel3;
370     private javax.swing.JLabel JavaDoc jLabel4;
371     private javax.swing.JPanel JavaDoc jPanel1;
372     private javax.swing.JPanel JavaDoc jPanel2;
373     private javax.swing.JTextField JavaDoc javadoc;
374     private javax.swing.JTextField JavaDoc jdkName;
375     private javax.swing.JLabel JavaDoc progressLabel;
376     private javax.swing.JPanel JavaDoc progressPanel;
377     private javax.swing.JTextField JavaDoc sources;
378     // End of variables declaration//GEN-END:variables
379

380     /**
381      * Controller for the outer class: manages wizard panel's valid state
382      * according to the user's input and detection state.
383      */

384     static class WizardPanel implements WizardDescriptor.Panel, TaskListener, ChangeListener {
385         private DetectPanel component;
386         private RequestProcessor.Task task;
387         private final J2SEWizardIterator iterator;
388         private Collection changeList = new ArrayList();
389         private boolean detected;
390         private boolean valid;
391         private boolean firstPass=true;
392         private WizardDescriptor wiz;
393         private ProgressHandle progressHandle;
394
395         WizardPanel(J2SEWizardIterator iterator) {
396         this.iterator = iterator;
397         }
398
399         public void addChangeListener(ChangeListener l) {
400             changeList.add(l);
401         }
402
403         public java.awt.Component JavaDoc getComponent() {
404             if (component == null) {
405                 final NewJ2SEPlatform primaryPlatform = this.iterator.getPlatform();
406                 final NewJ2SEPlatform secondaryPlatform = this.iterator.getSecondaryPlatform();
407                 component = new DetectPanel(primaryPlatform);
408                 component.addChangeListener (this);
409                 task = RequestProcessor.getDefault().create(
410                     new Runnable JavaDoc() {
411                         public void run() {
412                             primaryPlatform.run();
413                             if (secondaryPlatform != null) {
414                                 secondaryPlatform.run();
415                             }
416                         }
417                 });
418                 task.addTaskListener(this);
419             }
420             return component;
421         }
422
423         void setValid(boolean v) {
424             if (v == valid)
425                 return;
426             valid = v;
427             fireStateChange();
428         }
429
430         public HelpCtx getHelp() {
431             return new HelpCtx (DetectPanel.class);
432         }
433
434         public boolean isValid() {
435             return valid;
436         }
437
438         public void readSettings(Object JavaDoc settings) {
439             this.wiz = (WizardDescriptor) settings;
440             JavaPlatform platform = this.iterator.getPlatform();
441             String JavaDoc srcPath = null;
442             String JavaDoc jdocPath = null;
443             ClassPath src = platform.getSourceFolders();
444             if (src.entries().size()>0) {
445                 URL JavaDoc folderRoot = ((ClassPath.Entry)src.entries().get(0)).getURL();
446                 if ("jar".equals(folderRoot.getProtocol())) { //NOI18N
447
folderRoot = FileUtil.getArchiveFile (folderRoot);
448                 }
449                 srcPath = new File JavaDoc(URI.create(folderRoot.toExternalForm())).getAbsolutePath();
450             }
451             else if (firstPass) {
452                 Iterator il = platform.getInstallFolders().iterator();
453                 if (il.hasNext()) {
454                     File JavaDoc base = FileUtil.toFile ((FileObject)il.next());
455                     if (base!=null) {
456                         File JavaDoc f = new File JavaDoc (base,"src.zip"); //NOI18N
457
if (f.canRead()) {
458                             srcPath = f.getAbsolutePath();
459                         }
460                         else {
461                             f = new File JavaDoc (base,"src.jar"); //NOI18N
462
if (f.canRead()) {
463                                 srcPath = f.getAbsolutePath();
464                             }
465                         }
466                     }
467                 }
468             }
469             List jdoc = platform.getJavadocFolders();
470             if (jdoc.size()>0) {
471                 URL JavaDoc folderRoot = (URL JavaDoc)jdoc.get(0);
472                 if ("jar".equals(folderRoot.getProtocol())) {
473                     folderRoot = FileUtil.getArchiveFile (folderRoot);
474                 }
475                 jdocPath = new File JavaDoc (URI.create(folderRoot.toExternalForm())).getAbsolutePath();
476             }
477             else if (firstPass) {
478                 Iterator il = platform.getInstallFolders().iterator();
479                 if (il.hasNext()) {
480                     File JavaDoc base = FileUtil.toFile ((FileObject)il.next());
481                     if (base!=null) {
482                         File JavaDoc f = new File JavaDoc (base,"docs"); //NOI18N
483
if (f.isDirectory() && f.canRead()) {
484                             jdocPath = f.getAbsolutePath();
485                         }
486                     }
487                 }
488                 firstPass = false;
489             }
490             this.component.setSources (srcPath);
491             this.component.setJavadoc (jdocPath);
492             this.component.jdkName.setEditable(false);
493             this.component.progressPanel.setVisible (true);
494             this.component.progressLabel.setVisible (true);
495             
496             this.progressHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(DetectPanel.class,"TXT_PlatfromDetectProgress"));
497             this.component.progressPanel.removeAll();
498             this.component.progressPanel.setLayout (new GridBagLayout JavaDoc ());
499             GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc ();
500             c.gridx = c.gridy = GridBagConstraints.RELATIVE;
501             c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER;
502             c.fill = GridBagConstraints.HORIZONTAL;
503             c.weightx = 1.0;
504             JComponent pc = ProgressHandleFactory.createProgressComponent(this.progressHandle);
505             ((GridBagLayout JavaDoc)this.component.progressPanel.getLayout ()).setConstraints(pc,c);
506             this.component.progressPanel.add (pc);
507             this.progressHandle.start ();
508             task.schedule(0);
509         }
510
511         void fireStateChange() {
512             ChangeListener[] ll;
513             synchronized (this) {
514                 if (changeList.isEmpty())
515                     return;
516                 ll = (ChangeListener[])changeList.toArray(new ChangeListener[0]);
517             }
518             ChangeEvent ev = new ChangeEvent(this);
519             for (int i = 0; i < ll.length; i++)
520                 ll[i].stateChanged(ev);
521         }
522
523         public void removeChangeListener(ChangeListener l) {
524             changeList.remove(l);
525         }
526
527     /**
528      Updates the Platform's display name with the one the user
529      has entered. Stores user-customized display name into the Platform.
530      */

531         public void storeSettings(Object JavaDoc settings) {
532             if (isValid()) {
533                 String JavaDoc name = component.getPlatformName();
534                 List src = new ArrayList ();
535                 List jdoc = new ArrayList ();
536                 String JavaDoc srcPath = this.component.getSources();
537                 if (srcPath!=null) {
538                     File JavaDoc f = new File JavaDoc (srcPath);
539                     try {
540                         URL JavaDoc url = f.toURI().toURL();
541                         if (FileUtil.isArchiveFile(url)) {
542                             url = FileUtil.getArchiveRoot(url);
543                             FileObject fo = URLMapper.findFileObject(url);
544                             if (fo != null) {
545                                 fo = fo.getFileObject("src"); //NOI18N
546
if (fo != null) {
547                                     url = fo.getURL();
548                                 }
549                             }
550                             src.add (ClassPathSupport.createResource(url));
551                         }
552                         else {
553                             src.add (ClassPathSupport.createResource(url));
554                         }
555                     } catch (MalformedURLException JavaDoc mue) {
556                         ErrorManager.getDefault().notify (mue);
557                     }
558                     catch (FileStateInvalidException e) {
559                         ErrorManager.getDefault().notify(e);
560                     }
561                 }
562                 String JavaDoc jdocPath = this.component.getJavadoc();
563                 if (jdocPath!=null) {
564                     File JavaDoc f = new File JavaDoc (jdocPath);
565                     try {
566                         URL JavaDoc url = f.toURI().toURL();
567                         if (FileUtil.isArchiveFile(url)) {
568                             url = FileUtil.getArchiveRoot(url);
569                         }
570                         else if (!f.exists()){
571                             url = new URL JavaDoc (url.toExternalForm()+'/');
572                         }
573                         jdoc.add (url);
574                     } catch (MalformedURLException JavaDoc mue) {
575                         ErrorManager.getDefault().notify (mue);
576                     }
577                 }
578                 
579                 NewJ2SEPlatform platform = this.iterator.getPlatform();
580                 platform.setDisplayName (name);
581                 platform.setAntName (createAntName (name));
582                 platform.setSourceFolders (ClassPathSupport.createClassPath(src));
583                 platform.setJavadocFolders (jdoc);
584                 
585                 platform = this.iterator.getSecondaryPlatform();
586                 if (platform != null) {
587                     name = NbBundle.getMessage(DetectPanel.class,"FMT_64BIT", name);
588                     platform.setDisplayName (name);
589                     platform.setAntName (createAntName(name));
590                     platform.setSourceFolders (ClassPathSupport.createClassPath(src));
591                     platform.setJavadocFolders (jdoc);
592                 }
593             }
594         }
595
596         /**
597          * Revalidates the Wizard Panel
598          */

599         public void taskFinished(Task task) {
600             SwingUtilities.invokeLater( new Runnable JavaDoc () {
601                 public void run () {
602                     component.updateData ();
603                     component.jdkName.setEditable(true);
604                     assert progressHandle != null;
605                     progressHandle.finish ();
606                     component.progressPanel.setVisible (false);
607                     component.progressLabel.setVisible (false);
608                     detected = iterator.getPlatform().isValid();
609                     checkValid ();
610                 }
611             });
612         }
613
614
615         public void stateChanged(ChangeEvent e) {
616              this.checkValid();
617         }
618
619         private void checkValid () {
620             this.wiz.putProperty( "WizardPanel_errorMessage", ""); //NOI18N
621
String JavaDoc name = this.component.getPlatformName ();
622             boolean validDisplayName = name.length() > 0;
623             boolean usedDisplayName = false;
624             if (!detected) {
625                 this.wiz.putProperty( "WizardPanel_errorMessage",NbBundle.getMessage(DetectPanel.class,"ERROR_NoSDKRegistry")); //NOI18N
626
}
627             else if (!validDisplayName) {
628                 this.wiz.putProperty( "WizardPanel_errorMessage",NbBundle.getMessage(DetectPanel.class,"ERROR_InvalidDisplayName")); //NOI18N
629
}
630             else {
631                 JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms();
632                 for (int i=0; i<platforms.length; i++) {
633                     if (name.equals (platforms[i].getDisplayName())) {
634                         usedDisplayName = true;
635                         this.wiz.putProperty( "WizardPanel_errorMessage",NbBundle.getMessage(DetectPanel.class,"ERROR_UsedDisplayName")); //NOI18N
636
break;
637                     }
638                 }
639             }
640             boolean v = detected && validDisplayName && !usedDisplayName;
641             setValid(v);
642         }
643
644         private static String JavaDoc createAntName (String JavaDoc name) {
645             if (name == null || name.length() == 0) {
646                 throw new IllegalArgumentException JavaDoc ();
647             }
648             String JavaDoc antName = PropertyUtils.getUsablePropertyName(name);
649             if (platformExists (antName)) {
650                 String JavaDoc baseName = antName;
651                 int index = 1;
652                 antName = baseName + Integer.toString (index);
653                 while (platformExists (antName)) {
654                     index ++;
655                     antName = baseName + Integer.toString (index);
656                 }
657             }
658             return antName;
659         }
660         
661         private static boolean platformExists (String JavaDoc antName) {
662             JavaPlatformManager mgr = JavaPlatformManager.getDefault();
663             JavaPlatform[] platforms = mgr.getInstalledPlatforms();
664             for (int i=0; i < platforms.length; i++) {
665                 if (platforms[i] instanceof J2SEPlatformImpl) {
666                     String JavaDoc val = ((J2SEPlatformImpl)platforms[i]).getAntName();
667                     if (antName.equals(val)) {
668                         return true;
669                     }
670                 }
671             }
672             return false;
673         }
674         
675     }
676 }
677
Popular Tags