KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > platformdefinition > J2SEPlatformCustomizer


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 package org.netbeans.modules.java.j2seplatform.platformdefinition;
20
21
22 import java.awt.*;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.io.File JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.net.URL JavaDoc;
31 import java.net.URI JavaDoc;
32 import java.net.MalformedURLException JavaDoc;
33 import javax.swing.*;
34 import javax.swing.filechooser.FileFilter JavaDoc;
35 import javax.swing.event.ListSelectionListener JavaDoc;
36 import javax.swing.event.ListSelectionEvent JavaDoc;
37 import org.openide.NotifyDescriptor;
38 import org.openide.ErrorManager;
39 import org.openide.filesystems.FileUtil;
40 import org.openide.util.NbBundle;
41 import org.netbeans.api.java.classpath.ClassPath;
42 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
43
44
45
46 public class J2SEPlatformCustomizer extends JTabbedPane {
47
48     private static final int CLASSPATH = 0;
49     private static final int SOURCES = 1;
50     private static final int JAVADOC = 2;
51
52     private J2SEPlatformImpl platform;
53
54     public J2SEPlatformCustomizer (J2SEPlatformImpl platform) {
55         this.platform = platform;
56         this.initComponents ();
57     }
58
59
60     private void initComponents () {
61         this.getAccessibleContext().setAccessibleName (NbBundle.getMessage(J2SEPlatformCustomizer.class,"AN_J2SEPlatformCustomizer"));
62         this.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(J2SEPlatformCustomizer.class,"AD_J2SEPlatformCustomizer"));
63         this.addTab(NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_Classes"), createPathTab(CLASSPATH));
64         this.addTab(NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_Sources"), createPathTab(SOURCES));
65         this.addTab(NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_Javadoc"), createPathTab(JAVADOC));
66     }
67
68
69     private JComponent createPathTab (int type) {
70         return new PathView (this.platform, type);
71     }
72
73
74     private static class PathView extends JPanel {
75
76         private JList resources;
77         private JButton addButton;
78 // private JButton addURLButton;
79
private JButton removeButton;
80         private JButton moveUpButton;
81         private JButton moveDownButton;
82         private int type;
83         private File JavaDoc currentDir;
84
85         public PathView (J2SEPlatformImpl platform, int type) {
86             this.type = type;
87             this.initComponents (platform);
88         }
89
90         private void initComponents (J2SEPlatformImpl platform) {
91             this.setLayout(new GridBagLayout());
92             JLabel label = new JLabel ();
93             String JavaDoc key = null;
94             String JavaDoc mneKey = null;
95             String JavaDoc ad = null;
96             switch (type) {
97                 case CLASSPATH:
98                     key = "TXT_JDKClasspath"; //NOI18N
99
mneKey = "MNE_JDKClasspath"; //NOI18N
100
ad = "AD_JDKClasspath"; //NOI18N
101
break;
102                 case SOURCES:
103                     key = "TXT_JDKSources"; //NOI18N
104
mneKey = "MNE_JDKSources"; //NOI18N
105
ad = "AD_JDKSources"; //NOI18N
106
break;
107                 case JAVADOC:
108                     key = "TXT_JDKJavadoc"; //NOI18N
109
mneKey = "MNE_JDKJavadoc"; //NOI8N
110
ad = "AD_JDKJavadoc"; //NOI8N
111
break;
112                 default:
113                     assert false : "Illegal type of panel"; //NOI18N
114
return;
115             }
116             label.setText (NbBundle.getMessage(J2SEPlatformCustomizer.class,key));
117             label.setDisplayedMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class,mneKey).charAt(0));
118             GridBagConstraints c = new GridBagConstraints();
119             c.gridx = GridBagConstraints.RELATIVE;
120             c.gridy = GridBagConstraints.RELATIVE;
121             c.gridwidth = GridBagConstraints.REMAINDER;
122             c.insets = new Insets (6,6,2,6);
123             c.fill = GridBagConstraints.HORIZONTAL;
124             c.weightx = 1.0;
125             ((GridBagLayout)this.getLayout()).setConstraints(label,c);
126             this.add (label);
127             this.resources = new JList(new PathModel(platform,type));
128             label.setLabelFor (this.resources);
129             this.resources.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(J2SEPlatformCustomizer.class,ad));
130             this.resources.addListSelectionListener(new ListSelectionListener JavaDoc() {
131                 public void valueChanged(ListSelectionEvent JavaDoc e) {
132                     selectionChanged ();
133                 }
134             });
135             JScrollPane spane = new JScrollPane (this.resources);
136             c = new GridBagConstraints();
137             c.gridx = GridBagConstraints.RELATIVE;
138             c.gridy = GridBagConstraints.RELATIVE;
139             c.gridwidth = 1;
140             c.gridheight = 5;
141             c.insets = new Insets (0,6,6,6);
142             c.fill = GridBagConstraints.BOTH;
143             c.weightx = 1.0;
144             c.weighty = 1.0;
145             ((GridBagLayout)this.getLayout()).setConstraints(spane,c);
146             this.add (spane);
147             if (type == SOURCES || type == JAVADOC) {
148                 this.addButton = new JButton ();
149                 String JavaDoc text;
150                 char mne;
151                 if (type == SOURCES) {
152                     text = NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_Add");
153                     mne = NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_Add").charAt(0);
154                     ad = NbBundle.getMessage(J2SEPlatformCustomizer.class, "AD_Add");
155                 }
156                 else {
157                     text = NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_AddZip");
158                     mne = NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_AddZip").charAt(0);
159                     ad = NbBundle.getMessage(J2SEPlatformCustomizer.class, "AD_AddZip");
160                 }
161                 this.addButton.setText(text);
162                 this.addButton.setMnemonic(mne);
163                 this.addButton.getAccessibleContext().setAccessibleDescription (ad);
164                 addButton.addActionListener( new ActionListener JavaDoc () {
165                     public void actionPerformed(ActionEvent JavaDoc e) {
166                         addPathElement ();
167                     }
168                 });
169                 c = new GridBagConstraints();
170                 c.gridx = 1;
171                 c.gridy = 1;
172                 c.gridwidth = GridBagConstraints.REMAINDER;
173                 c.fill = GridBagConstraints.HORIZONTAL;
174                 c.anchor = GridBagConstraints.NORTHWEST;
175                 c.insets = new Insets (0,6,0,6);
176                 ((GridBagLayout)this.getLayout()).setConstraints(addButton,c);
177                 this.add (addButton);
178 // if (this.type == JAVADOC) {
179
// addURLButton = new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_AddURL"));
180
// addURLButton.setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_AddURL").charAt(0));
181
// addURLButton.addActionListener(new ActionListener () {
182
// public void actionPerformed(ActionEvent e) {
183
// addURLElement ();
184
// }
185
// });
186
// c = new GridBagConstraints();
187
// c.gridx = 1;
188
// c.gridy = 2;
189
// c.gridwidth = GridBagConstraints.REMAINDER;
190
// c.fill = GridBagConstraints.HORIZONTAL;
191
// c.anchor = GridBagConstraints.NORTHWEST;
192
// c.insets = new Insets (0,6,6,12);
193
// ((GridBagLayout)this.getLayout()).setConstraints(addURLButton,c);
194
// this.add (addURLButton);
195
// }
196
removeButton = new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_Remove"));
197                 removeButton.setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_Remove").charAt(0));
198                 removeButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(J2SEPlatformCustomizer.class,"AD_Remove"));
199                 removeButton.addActionListener( new ActionListener JavaDoc () {
200                     public void actionPerformed(ActionEvent JavaDoc e) {
201                         removePathElement ();
202                     }
203                 });
204                 removeButton.setEnabled(false);
205                 c = new GridBagConstraints();
206                 c.gridx = 1;
207                 c.gridy = 3;
208                 c.gridwidth = GridBagConstraints.REMAINDER;
209                 c.fill = GridBagConstraints.HORIZONTAL;
210                 c.anchor = GridBagConstraints.NORTHWEST;
211                 c.insets = new Insets (12,6,0,6);
212                 ((GridBagLayout)this.getLayout()).setConstraints(removeButton,c);
213                 this.add (removeButton);
214                 moveUpButton = new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_Up"));
215                 moveUpButton.setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_Up").charAt(0));
216                 moveUpButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(J2SEPlatformCustomizer.class,"AD_Up"));
217                 moveUpButton.addActionListener( new ActionListener JavaDoc () {
218                     public void actionPerformed(ActionEvent JavaDoc e) {
219                         moveUpPathElement ();
220                     }
221                 });
222                 moveUpButton.setEnabled(false);
223                 c = new GridBagConstraints();
224                 c.gridx = 1;
225                 c.gridy = 4;
226                 c.gridwidth = GridBagConstraints.REMAINDER;
227                 c.fill = GridBagConstraints.HORIZONTAL;
228                 c.anchor = GridBagConstraints.NORTHWEST;
229                 c.insets = new Insets (12,6,0,6);
230                 ((GridBagLayout)this.getLayout()).setConstraints(moveUpButton,c);
231                 this.add (moveUpButton);
232                 moveDownButton = new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_Down"));
233                 moveDownButton.setMnemonic (NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_Down").charAt(0));
234                 moveDownButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(J2SEPlatformCustomizer.class,"AD_Down"));
235                 moveDownButton.addActionListener( new ActionListener JavaDoc () {
236                     public void actionPerformed(ActionEvent JavaDoc e) {
237                         moveDownPathElement ();
238                     }
239                 });
240                 moveDownButton.setEnabled(false);
241                 c = new GridBagConstraints();
242                 c.gridx = 1;
243                 c.gridy = 5;
244                 c.gridwidth = GridBagConstraints.REMAINDER;
245                 c.fill = GridBagConstraints.HORIZONTAL;
246                 c.anchor = GridBagConstraints.NORTHWEST;
247                 c.insets = new Insets (5,6,6,6);
248                 ((GridBagLayout)this.getLayout()).setConstraints(moveDownButton,c);
249                 this.add (moveDownButton);
250             }
251         }
252
253 // private void addURLElement() {
254
// JPanel p = new JPanel ();
255
// GridBagLayout lm = new GridBagLayout();
256
// p.setLayout (lm);
257
// GridBagConstraints c = new GridBagConstraints ();
258
// c.gridx = c.gridy = GridBagConstraints.RELATIVE;
259
// c.insets = new Insets (12,12,12,6);
260
// c.anchor = GridBagConstraints.NORTHWEST;
261
// JLabel label = new JLabel (NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_AddJavadocURLMessage"));
262
// label.setDisplayedMnemonic ('U');
263
// lm.setConstraints(label,c);
264
// p.add (label);
265
// c = new GridBagConstraints ();
266
// c.gridx = c.gridy = GridBagConstraints.RELATIVE;
267
// c.gridwidth = GridBagConstraints.REMAINDER;
268
// c.insets = new Insets (12,0,12,6);
269
// c.fill = GridBagConstraints.HORIZONTAL;
270
// c.anchor = GridBagConstraints.NORTHWEST;
271
// JTextField text = new JTextField ();
272
// text.setColumns(30);
273
// text.setText (NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_DefaultProtocol"));
274
// text.selectAll();
275
// label.setLabelFor(text);
276
// lm.setConstraints(text,c);
277
// p.add (text);
278
// JButton[] options = new JButton[] {
279
// new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_AddJavadocURLTitle")),
280
// new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_Cancel"))
281
// };
282
// options[0].setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class,"MNE_Add").charAt(0));
283
// options[1].setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class,"MNE_Cancel").charAt(0));
284
// DialogDescriptor input = new DialogDescriptor (
285
// p,
286
// NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_AddJavadocURLTitle"),
287
// true, options, options[0], DialogDescriptor.DEFAULT_ALIGN, null, null);
288
// if (DialogDisplayer.getDefault().notify(input) == options[0]) {
289
// try {
290
// String value = text.getText();
291
// URL url = new URL (value);
292
// ((PathModel)this.resources.getModel()).addPath(url);
293
// this.resources.setSelectedIndex (this.resources.getModel().getSize()-1);
294
// } catch (MalformedURLException mue) {
295
// DialogDescriptor.Message message = new DialogDescriptor.Message (
296
// NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_InvalidURLFormat"),
297
// DialogDescriptor.ERROR_MESSAGE);
298
// DialogDisplayer.getDefault().notify(message);
299
// }
300
// }
301
// }
302

303         private void addPathElement () {
304             JFileChooser chooser = new JFileChooser ();
305             FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
306             chooser.setMultiSelectionEnabled (true);
307             String JavaDoc title = null;
308             String JavaDoc message = null;
309             String JavaDoc approveButtonName = null;
310             String JavaDoc approveButtonNameMne = null;
311             if (this.type == SOURCES) {
312                 title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
313                 message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Sources");
314                 approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
315                 approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenSources");
316             }
317             else if (this.type == JAVADOC) {
318                 title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
319                 message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Javadoc");
320                 approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
321                 approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenJavadoc");
322             }
323             chooser.setDialogTitle(title);
324             chooser.setApproveButtonText(approveButtonName);
325             chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
326             chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
327             //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
328
chooser.setAcceptAllFileFilterUsed( false );
329             chooser.setFileFilter (new SimpleFileFilter(message,new String JavaDoc[] {"ZIP","JAR"})); //NOI18N
330
if (this.currentDir != null) {
331                 chooser.setCurrentDirectory(this.currentDir);
332             }
333             if (chooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
334                 File JavaDoc[] fs = chooser.getSelectedFiles();
335                 PathModel model = (PathModel) this.resources.getModel();
336                 boolean addingFailed = false;
337                 int firstIndex = this.resources.getModel().getSize();
338                 for (int i = 0; i < fs.length; i++) {
339                     File JavaDoc f = fs[i];
340                     //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
341
// E.g. for /foo/src it returns /foo/src/src
342
// Try to convert it back by removing last invalid name component
343
if (!f.exists()) {
344                         File JavaDoc parent = f.getParentFile();
345                         if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
346                             f = parent;
347                         }
348                     }
349                     addingFailed|=!model.addPath (f);
350                 }
351                 if (addingFailed) {
352                     new NotifyDescriptor.Message (NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_CanNotAddResolve"),
353                             NotifyDescriptor.ERROR_MESSAGE);
354                 }
355                 int lastIndex = this.resources.getModel().getSize()-1;
356                 if (firstIndex<=lastIndex) {
357                     int[] toSelect = new int[lastIndex-firstIndex+1];
358                     for (int i = 0; i < toSelect.length; i++) {
359                         toSelect[i] = firstIndex+i;
360                     }
361                     this.resources.setSelectedIndices(toSelect);
362                 }
363                 this.currentDir = FileUtil.normalizeFile(chooser.getCurrentDirectory());
364             }
365         }
366
367         private void removePathElement () {
368             int[] indices = this.resources.getSelectedIndices();
369             if (indices.length == 0) {
370                 return;
371             }
372             PathModel model = (PathModel) this.resources.getModel();
373             model.removePath (indices);
374             if ( indices[indices.length-1]-indices.length+1 < this.resources.getModel().getSize()) {
375                 this.resources.setSelectedIndex (indices[indices.length-1]-indices.length+1);
376             }
377             else if (indices[0]>0) {
378                 this.resources.setSelectedIndex (indices[0]-1);
379             }
380         }
381
382         private void moveDownPathElement () {
383             int[] indices = this.resources.getSelectedIndices();
384             if (indices.length == 0) {
385                 return;
386             }
387             PathModel model = (PathModel) this.resources.getModel();
388             model.moveDownPath (indices);
389             for (int i=0; i< indices.length; i++) {
390                 indices[i] = indices[i] + 1;
391             }
392             this.resources.setSelectedIndices (indices);
393         }
394
395         private void moveUpPathElement () {
396             int[] indices = this.resources.getSelectedIndices();
397             if (indices.length == 0) {
398                 return;
399             }
400             PathModel model = (PathModel) this.resources.getModel();
401             model.moveUpPath (indices);
402             for (int i=0; i< indices.length; i++) {
403                 indices[i] = indices[i] - 1;
404             }
405             this.resources.setSelectedIndices (indices);
406         }
407
408         private void selectionChanged () {
409             if (this.type == CLASSPATH) {
410                 return;
411             }
412             int indices[] = this.resources.getSelectedIndices();
413             this.removeButton.setEnabled (indices.length > 0);
414             this.moveUpButton.setEnabled (indices.length > 0 && indices[0]>0);
415             this.moveDownButton.setEnabled(indices.length > 0 && indices[indices.length-1]<this.resources.getModel().getSize()-1);
416         }
417
418     }
419
420
421     private static class PathModel extends AbstractListModel/*<String>*/ {
422
423         private J2SEPlatformImpl platform;
424         private int type;
425         private java.util.List JavaDoc data;
426
427         public PathModel (J2SEPlatformImpl platform, int type) {
428             this.platform = platform;
429             this.type = type;
430         }
431
432         public int getSize() {
433             return this.getData().size();
434         }
435
436         public Object JavaDoc getElementAt(int index) {
437             java.util.List JavaDoc list = this.getData();
438             URL JavaDoc url = (URL JavaDoc)list.get(index);
439             if ("jar".equals(url.getProtocol())) { //NOI18N
440
URL JavaDoc fileURL = FileUtil.getArchiveFile (url);
441                 if (FileUtil.getArchiveRoot(fileURL).equals(url)) {
442                     // really the root
443
url = fileURL;
444                 } else {
445                     // some subdir, just show it as is
446
return url.toExternalForm();
447                 }
448             }
449             if ("file".equals(url.getProtocol())) {
450                 File JavaDoc f = new File JavaDoc (URI.create(url.toExternalForm()));
451                 return f.getAbsolutePath();
452             }
453             else {
454                 return url.toExternalForm();
455             }
456         }
457
458         private void removePath (int[] indices) {
459             java.util.List JavaDoc data = getData();
460             for (int i=indices.length-1; i>=0; i--) {
461                 data.remove(indices[i]);
462             }
463             updatePlatform ();
464             fireIntervalRemoved(this,indices[0],indices[indices.length-1]);
465         }
466
467         private void moveUpPath (int[] indices) {
468             java.util.List JavaDoc data = getData ();
469             for (int i=0; i<indices.length; i++) {
470                 Object JavaDoc p2 = data.get (indices[i]);
471                 Object JavaDoc p1 = data.set (indices[i]-1,p2);
472                 data.set (indices[i],p1);
473             }
474             updatePlatform ();
475             fireContentsChanged(this,indices[0]-1,indices[indices.length-1]);
476         }
477
478         private void moveDownPath (int[] indices) {
479             java.util.List JavaDoc data = getData ();
480             for (int i=indices.length-1; i>=0; i--) {
481                 Object JavaDoc p1 = data.get (indices[i]);
482                 Object JavaDoc p2 = data.set (indices[i]+1,p1);
483                 data.set (indices[i],p2);
484             }
485             updatePlatform();
486             fireContentsChanged(this,indices[0],indices[indices.length-1]+1);
487         }
488
489         private boolean addPath (File JavaDoc f) {
490             try {
491                 URL JavaDoc url = f.toURI().toURL();
492                 return this.addPath (url);
493             } catch (MalformedURLException JavaDoc mue) {
494                 return false;
495             }
496         }
497
498         private boolean addPath (URL JavaDoc url) {
499             if (FileUtil.isArchiveFile(url)) {
500                 url = FileUtil.getArchiveRoot (url);
501             }
502             else if (!url.toExternalForm().endsWith("/")){
503                 try {
504                     url = new URL JavaDoc (url.toExternalForm()+"/");
505                 } catch (MalformedURLException JavaDoc mue) {
506                     ErrorManager.getDefault().notify(mue);
507                 }
508             }
509             java.util.List JavaDoc data = getData();
510             int oldSize = data.size ();
511             data.add (url);
512             updatePlatform();
513             fireIntervalAdded(this,oldSize,oldSize);
514             return true;
515         }
516
517         private synchronized java.util.List JavaDoc getData () {
518             if (this.data == null) {
519                 switch (this.type) {
520                     case CLASSPATH:
521                         this.data = getPathList (this.platform.getBootstrapLibraries());
522                         break;
523                     case SOURCES:
524                         this.data = getPathList (this.platform.getSourceFolders());
525                         break;
526                     case JAVADOC:
527                         this.data = new ArrayList JavaDoc(this.platform.getJavadocFolders());
528                         break;
529                 }
530             }
531             return this.data;
532         }
533
534         private static java.util.List JavaDoc getPathList (ClassPath cp) {
535             java.util.List JavaDoc result = new ArrayList JavaDoc ();
536             for (Iterator JavaDoc it = cp.entries().iterator(); it.hasNext();) {
537                 ClassPath.Entry entry = (ClassPath.Entry) it.next ();
538                 result.add (entry.getURL());
539             }
540             return result;
541         }
542
543         private static ClassPath createClassPath (java.util.List JavaDoc/*<URL>*/ roots) {
544             java.util.List JavaDoc resources = new ArrayList JavaDoc ();
545             for (Iterator JavaDoc it = roots.iterator(); it.hasNext();) {
546                 URL JavaDoc url = (URL JavaDoc) it.next ();
547                 resources.add (ClassPathSupport.createResource(url));
548             }
549             return ClassPathSupport.createClassPath(resources);
550         }
551
552         private void updatePlatform () {
553             switch (this.type) {
554                 case SOURCES:
555                     this.platform.setSourceFolders(createClassPath(data));
556                     break;
557                 case JAVADOC:
558                     this.platform.setJavadocFolders (data);
559                     break;
560                 default:
561                     assert false : "Trying to update unknown property"; //NOI18N
562
}
563         }
564     }
565
566
567     private static class SimpleFileFilter extends FileFilter JavaDoc {
568
569         private String JavaDoc description;
570         private Collection JavaDoc extensions;
571
572
573         public SimpleFileFilter (String JavaDoc description, String JavaDoc[] extensions) {
574             this.description = description;
575             this.extensions = Arrays.asList(extensions);
576         }
577
578         public boolean accept(File JavaDoc f) {
579             if (f.isDirectory())
580                 return true;
581             String JavaDoc name = f.getName();
582             int index = name.lastIndexOf('.'); //NOI18N
583
if (index <= 0 || index==name.length()-1)
584                 return false;
585             String JavaDoc extension = name.substring (index+1).toUpperCase();
586             return this.extensions.contains(extension);
587         }
588
589         public String JavaDoc getDescription() {
590             return this.description;
591         }
592     }
593
594
595 }
596
Popular Tags