KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > ui > customizer > PlatformUiSupport


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.clientproject.ui.customizer;
21
22 import java.awt.Component JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.text.MessageFormat JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Set JavaDoc;
30 import java.util.TreeSet JavaDoc;
31 import javax.swing.AbstractListModel JavaDoc;
32 import javax.swing.ComboBoxModel JavaDoc;
33 import javax.swing.JButton JavaDoc;
34 import javax.swing.JList JavaDoc;
35 import javax.swing.ListCellRenderer JavaDoc;
36 import javax.swing.event.ListDataEvent JavaDoc;
37 import javax.swing.event.ListDataListener JavaDoc;
38 import org.netbeans.api.java.platform.JavaPlatform;
39 import org.netbeans.api.java.platform.JavaPlatformManager;
40 import org.netbeans.api.java.platform.Specification;
41 import org.netbeans.modules.j2ee.clientproject.AppClientProjectType;
42 import org.netbeans.modules.j2ee.clientproject.UpdateHelper;
43 import org.netbeans.spi.project.support.ant.EditableProperties;
44 import org.openide.DialogDisplayer;
45 import org.openide.ErrorManager;
46 import org.openide.NotifyDescriptor;
47 import org.openide.awt.HtmlRenderer;
48 import org.openide.modules.SpecificationVersion;
49 import org.openide.util.NbBundle;
50 import org.openide.util.WeakListeners;
51 import org.w3c.dom.Element JavaDoc;
52 import org.w3c.dom.NodeList JavaDoc;
53
54 /**
55  * Support class for {@link JavaPlatform} manipulation in j2seproject customizer.
56  * @author tzezula
57  */

58 public class PlatformUiSupport {
59     
60     
61     private PlatformUiSupport() {
62     }
63     
64     /**
65      * Creates {@link ComboBoxModel} of J2SE platforms.
66      * The model listens on the {@link JavaPlatformManager} and update its
67      * state according to changes
68      * @param activePlatform the active project's platform
69      * @return {@link ComboBoxModel}
70      */

71     public static ComboBoxModel JavaDoc createPlatformComboBoxModel(String JavaDoc activePlatform) {
72         return new PlatformComboBoxModel(activePlatform);
73     }
74     
75     
76     /**
77      * Creates a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel}
78      * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} method.
79      * @return {@link ListCellRenderer}
80      */

81     public static ListCellRenderer JavaDoc createPlatformListCellRenderer() {
82         return new PlatformListCellRenderer();
83     }
84     
85     /**
86      * Like {@link #storePlatform}, but platformName may be null (in which case the default platform is used)
87      */

88     public static void storePlatform(EditableProperties props, UpdateHelper helper, String JavaDoc platformName, SpecificationVersion sourceLevel) {
89         PlatformKey platformKey;
90         if (platformName != null) {
91             platformKey = new PlatformKey(PlatformUiSupport.findPlatform(platformName));
92         } else {
93             platformKey = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform());
94         }
95         storePlatform(props, helper, platformKey, sourceLevel);
96     }
97     
98     public static JavaPlatform findPlatform(String JavaDoc displayName) {
99         JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms(displayName, new Specification("j2se", null)); //NOI18N
100
return platforms.length == 0 ? null : platforms[0];
101     }
102     
103     /**
104      * Stores active platform, javac.source and javac.target into the project's metadata
105      * @param props project's shared properties
106      * @param helper to read/update project.xml
107      * @param platformKey the PatformKey got from the platform model
108      * @param sourceLevel source level
109      */

110     public static void storePlatform(EditableProperties props, UpdateHelper helper, Object JavaDoc platformKey, SpecificationVersion sourceLevel) {
111         assert platformKey instanceof PlatformKey;
112         PlatformKey pk = (PlatformKey) platformKey;
113         JavaPlatform platform = getPlatform(pk);
114         //null means active broken (unresolved) platform, no need to do anything
115
if (platform != null) {
116             SpecificationVersion jdk13 = new SpecificationVersion("1.3"); //NOI18N
117
String JavaDoc platformAntName = (String JavaDoc) platform.getProperties().get("platform.ant.name"); //NOI18N
118
assert platformAntName != null;
119             props.put(AppClientProjectProperties.JAVA_PLATFORM, platformAntName);
120             Element JavaDoc root = helper.getPrimaryConfigurationData(true);
121             boolean defaultPlatform = pk.isDefaultPlatform();
122             boolean changed = false;
123             NodeList JavaDoc explicitPlatformNodes = root.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"explicit-platform"); //NOI18N
124
if (defaultPlatform) {
125                 if (explicitPlatformNodes.getLength()==1) {
126                     root.removeChild(explicitPlatformNodes.item(0));
127                     changed = true;
128                 }
129             } else {
130                 Element JavaDoc explicitPlatform;
131                 switch (explicitPlatformNodes.getLength()) {
132                     case 0:
133                         explicitPlatform = root.getOwnerDocument().createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "explicit-platform"); //NOI18N
134
NodeList JavaDoc sourceRootNodes = root.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N
135
assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; //NOI18N
136
root.insertBefore(explicitPlatform, sourceRootNodes.item(0));
137                         changed = true;
138                         break;
139                     case 1:
140                         explicitPlatform = (Element JavaDoc)explicitPlatformNodes.item(0);
141                         break;
142                     default:
143                         throw new AssertionError JavaDoc("Broken project.xml file"); //NOI18N
144
}
145                 String JavaDoc explicitSourceAttrValue = explicitPlatform.getAttribute("explicit-source-supported"); //NOI18N
146
if (jdk13.compareTo(platform.getSpecification().getVersion())>=0 &&
147                         !"false".equals(explicitSourceAttrValue)) { //NOI18N
148
explicitPlatform.setAttribute("explicit-source-supported","false"); //NOI18N
149
changed = true;
150                 } else if (jdk13.compareTo(platform.getSpecification().getVersion())<0 &&
151                         !"true".equals(explicitSourceAttrValue)) { //NOI18N
152
explicitPlatform.setAttribute("explicit-source-supported","true"); //NOI18N
153
changed = true;
154                 }
155             }
156             
157             if (sourceLevel == null) {
158                 sourceLevel = platform.getSpecification().getVersion();
159             }
160             String JavaDoc javacSource = sourceLevel.toString();
161             // #89131: these levels are not actually distinct from 1.5.
162
if (javacSource.equals("1.6") || javacSource.equals("1.7"))
163                 javacSource = "1.5";
164             String JavaDoc javacTarget = jdk13.compareTo(sourceLevel)>=0 ? "1.1" : javacSource; //NOI18N
165
if (!javacSource.equals(props.getProperty(AppClientProjectProperties.JAVAC_SOURCE))) {
166                 props.setProperty(AppClientProjectProperties.JAVAC_SOURCE, javacSource);
167             }
168             if (!javacTarget.equals(props.getProperty(AppClientProjectProperties.JAVAC_TARGET))) {
169                 props.setProperty(AppClientProjectProperties.JAVAC_TARGET, javacTarget);
170             }
171             
172             if (changed) {
173                 helper.putPrimaryConfigurationData(root, true);
174             }
175         }
176     }
177     
178     
179     /**
180      * Returns a {@link JavaPlatform} for an item obtained from the ComboBoxModel created by
181      * the {@link PlatformUiSupport#createComboBoxModel} method
182      * @param platformKey an item obtained from ComboBoxModel created by {@link PlatformUiSupport#createComboBoxModel}
183      * @return JavaPlatform or null in case when platform is broken
184      * @exception {@link IllegalArgumentException} is thrown in case when parameter in not an object created by
185      * platform combobox model.
186      */

187     public static JavaPlatform getPlatform(Object JavaDoc platformKey) {
188         if (platformKey instanceof PlatformKey) {
189             return getPlatform((PlatformKey)platformKey);
190         } else {
191             throw new IllegalArgumentException JavaDoc();
192         }
193     }
194     
195     /**
196      * Creates {@link ComboBoxModel} of source levels for active platform.
197      * The model listens on the platform's {@link ComboBoxModel} and update its
198      * state according to changes
199      * @param platformComboBoxModel the platform's model used for listenning
200      * @param initialValue initial source level value
201      * @return {@link ComboBoxModel} of {@link SpecificationVersion}
202      */

203     public static ComboBoxModel JavaDoc createSourceLevelComboBoxModel(ComboBoxModel JavaDoc platformComboBoxModel, String JavaDoc initialValue, String JavaDoc j2eePlatform) {
204         return new SourceLevelComboBoxModel(platformComboBoxModel, initialValue, j2eePlatform);
205     }
206     
207     public static ListCellRenderer JavaDoc createSourceLevelListCellRenderer() {
208         return new SourceLevelListCellRenderer();
209     }
210     
211     
212     private static JavaPlatform getPlatform(PlatformKey platformKey) {
213         return platformKey.platform;
214     }
215     
216     
217     /**
218      * This class represents a JavaPlatform in the {@link ListModel}
219      * created by the {@link PlatformUiSupport#createPlatformComboBoxModel}
220      * method.
221      */

222     private static class PlatformKey implements Comparable JavaDoc {
223         
224         private String JavaDoc name;
225         private JavaPlatform platform;
226         
227         /**
228          * Creates a PlatformKey for a broken platform
229          * @param name the ant name of the broken platform
230          */

231         public PlatformKey(String JavaDoc name) {
232             assert name != null;
233             this.name = name;
234         }
235         
236         /**
237          * Creates a PlatformKey for a platform
238          * @param platform the {@link JavaPlatform}
239          */

240         public PlatformKey(JavaPlatform platform) {
241             assert platform != null;
242             this.platform = platform;
243         }
244         
245         public int compareTo(Object JavaDoc o) {
246             return this.getDisplayName().compareTo(((PlatformKey)o).getDisplayName());
247         }
248         
249         public boolean equals(Object JavaDoc other) {
250             if (other instanceof PlatformKey) {
251                 PlatformKey otherKey = (PlatformKey)other;
252                 return (this.platform == null ? otherKey.platform == null : this.platform.equals(otherKey.platform)) &&
253                         otherKey.getDisplayName().equals(this.getDisplayName());
254             } else {
255                 return false;
256             }
257         }
258         
259         public int hashCode() {
260             return getDisplayName().hashCode();
261         }
262         
263         public String JavaDoc toString() {
264             return getDisplayName();
265         }
266         
267         public synchronized String JavaDoc getDisplayName() {
268             if (this.name == null) {
269                 this.name = this.platform.getDisplayName();
270             }
271             return this.name;
272         }
273         
274         public boolean isDefaultPlatform() {
275             if (this.platform == null) {
276                 return false;
277             }
278             return this.platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform());
279         }
280         
281         public boolean isBroken() {
282             return this.platform == null;
283         }
284         
285     }
286     
287     private static final class SourceLevelKey implements Comparable JavaDoc {
288         
289         final SpecificationVersion sourceLevel;
290         final boolean broken;
291         
292         public SourceLevelKey(final SpecificationVersion sourceLevel) {
293             this(sourceLevel, false);
294         }
295         
296         public SourceLevelKey(final SpecificationVersion sourceLevel, final boolean broken) {
297             assert sourceLevel != null : "Source level cannot be null"; //NOI18N
298
this.sourceLevel = sourceLevel;
299             this.broken = broken;
300         }
301         
302         public SpecificationVersion getSourceLevel() {
303             return this.sourceLevel;
304         }
305         
306         public boolean isBroken() {
307             return this.broken;
308         }
309         
310         public int compareTo(final Object JavaDoc other) {
311             assert other instanceof SourceLevelKey : "Illegal argument of SourceLevelKey.compareTo()"; //NOI18N
312
SourceLevelKey otherKey = (SourceLevelKey) other;
313             return this.sourceLevel.compareTo(otherKey.sourceLevel);
314         }
315         
316         public /*@Override*/ boolean equals(final Object JavaDoc other) {
317             return (other instanceof SourceLevelKey) &&
318                     ((SourceLevelKey)other).sourceLevel.equals(this.sourceLevel);
319         }
320         
321         public /*@Override*/ int hashCode() {
322             return this.sourceLevel.hashCode();
323         }
324         
325         public /*@Override*/ String JavaDoc toString() {
326             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
327             if (this.broken) {
328                 buffer.append("Broken: "); //NOI18N
329
}
330             buffer.append(this.sourceLevel.toString());
331             return buffer.toString();
332         }
333         
334     }
335     
336     private static class PlatformComboBoxModel extends AbstractListModel JavaDoc implements ComboBoxModel JavaDoc, PropertyChangeListener JavaDoc {
337         
338         private final JavaPlatformManager pm;
339         private PlatformKey[] platformNamesCache;
340         private String JavaDoc initialPlatform;
341         private PlatformKey selectedPlatform;
342         
343         public PlatformComboBoxModel(String JavaDoc initialPlatform) {
344             this.pm = JavaPlatformManager.getDefault();
345             this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm));
346             this.initialPlatform = initialPlatform;
347         }
348         
349         public int getSize() {
350             PlatformKey[] platformNames = getPlatformNames();
351             return platformNames.length;
352         }
353         
354         public Object JavaDoc getElementAt(int index) {
355             PlatformKey[] platformNames = getPlatformNames();
356             assert index >=0 && index< platformNames.length;
357             return platformNames[index];
358         }
359         
360         public Object JavaDoc getSelectedItem() {
361             this.getPlatformNames(); //Force setting of selectedPlatform if it is not alredy done
362
return this.selectedPlatform;
363         }
364         
365         public void setSelectedItem(Object JavaDoc obj) {
366             this.selectedPlatform = (PlatformKey) obj;
367             this.fireContentsChanged(this, -1, -1);
368         }
369         
370         public void propertyChange(PropertyChangeEvent JavaDoc event) {
371             if (JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(event.getPropertyName())) {
372                 synchronized (this) {
373                     this.platformNamesCache = null;
374                 }
375                 this.fireContentsChanged(this, -1, -1);
376             }
377         }
378         
379         private synchronized PlatformKey[] getPlatformNames() {
380             if (this.platformNamesCache == null) {
381                 JavaPlatform[] platforms = pm.getPlatforms(null, new Specification("j2se",null)); //NOI18N
382
Set JavaDoc<PlatformKey> orderedNames = new TreeSet JavaDoc<PlatformKey>();
383                 boolean activeFound = false;
384                 for (int i=0; i< platforms.length; i++) {
385                     if (platforms[i].getInstallFolders().size()>0) {
386                         PlatformKey pk = new PlatformKey(platforms[i]);
387                         orderedNames.add(pk);
388                         if (!activeFound && initialPlatform != null) {
389                             String JavaDoc antName = (String JavaDoc) platforms[i].getProperties().get("platform.ant.name"); //NOI18N
390
if (initialPlatform.equals(antName)) {
391                                 if (this.selectedPlatform == null) {
392                                     this.selectedPlatform = pk;
393                                     initialPlatform = null;
394                                 }
395                                 activeFound = true;
396                             }
397                         }
398                     }
399                 }
400                 if (!activeFound) {
401                     if (initialPlatform == null) {
402                         if (this.selectedPlatform == null || !orderedNames.contains(this.selectedPlatform)) {
403                             this.selectedPlatform = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform());
404                         }
405                     } else {
406                         PlatformKey pk = new PlatformKey(this.initialPlatform);
407                         orderedNames.add(pk);
408                         if (this.selectedPlatform == null) {
409                             this.selectedPlatform = pk;
410                         }
411                     }
412                 }
413                 this.platformNamesCache = orderedNames.toArray(new PlatformKey[orderedNames.size()]);
414             }
415             return this.platformNamesCache;
416         }
417         
418     }
419     
420     private static class PlatformListCellRenderer implements ListCellRenderer JavaDoc {
421         
422         private final ListCellRenderer JavaDoc delegate;
423         
424         public PlatformListCellRenderer() {
425             this.delegate = HtmlRenderer.createRenderer();
426         }
427         
428         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
429             String JavaDoc name;
430             if (value == null) {
431                 name = ""; //NOI18N
432
} else {
433                 assert value instanceof PlatformKey : "Wrong model"; //NOI18N
434
PlatformKey key = (PlatformKey) value;
435                 if (key.isBroken()) {
436                     name = "<html><font color=\"#A40000\">" + //NOI18N
437
NbBundle.getMessage(PlatformUiSupport.class,"TXT_BrokenPlatformFmt", key.getDisplayName());
438                 } else {
439                     name = key.getDisplayName();
440                 }
441             }
442             return this.delegate.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus);
443         }
444     }
445     
446     private static class SourceLevelComboBoxModel extends AbstractListModel JavaDoc implements ComboBoxModel JavaDoc, ListDataListener JavaDoc {
447         
448         private static final String JavaDoc VERSION_PREFIX = "1."; //The version prefix // NOI18N
449
private static final int INITIAL_VERSION_MINOR = 2; //1.2
450
// if project is JAVA EE 5 show only 1.5 and higher
451
private static final int INITIAL_VERSION_MINOR_JAVA_EE_5 = 5; // 1.5
452

453         private SpecificationVersion selectedSourceLevel;
454         private SpecificationVersion[] sourceLevelCache;
455         private final ComboBoxModel JavaDoc platformComboBoxModel;
456         private PlatformKey activePlatform;
457         private String JavaDoc j2eePlatform = null;
458         
459         public SourceLevelComboBoxModel(ComboBoxModel JavaDoc platformComboBoxModel, String JavaDoc initialValue) {
460             this.platformComboBoxModel = platformComboBoxModel;
461             this.activePlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
462             this.platformComboBoxModel.addListDataListener(this);
463             if (initialValue != null && initialValue.length()>0) {
464                 try {
465                     this.selectedSourceLevel = new SpecificationVersion (initialValue);
466                 } catch (NumberFormatException JavaDoc nfe) {
467                     // If the javac.source has invalid value, do not preselect and log it.
468
ErrorManager.getDefault().log("Invalid javac.source: " + initialValue);
469                 }
470             }
471         }
472         
473         public SourceLevelComboBoxModel(ComboBoxModel JavaDoc platformComboBoxModel, String JavaDoc initialValue, String JavaDoc j2eePlatform) {
474             this(platformComboBoxModel, initialValue);
475             this.j2eePlatform = j2eePlatform;
476         }
477         
478         public int getSize() {
479 // SourceLevelKey[] sLevels = getSourceLevels ();
480
SpecificationVersion[] sLevels = getSourceLevels();
481             return sLevels.length;
482         }
483         
484         public Object JavaDoc getElementAt(int index) {
485             SpecificationVersion[] sLevels = getSourceLevels();
486             assert index >=0 && index< sLevels.length;
487             return sLevels[index];
488         }
489         
490         public Object JavaDoc getSelectedItem() {
491             List JavaDoc sLevels = Arrays.asList(getSourceLevels());
492             if (this.selectedSourceLevel != null) {
493                 if (!sLevels.contains(this.selectedSourceLevel)) {
494                     if (sLevels.size()>0) {
495                         this.selectedSourceLevel = (SpecificationVersion) sLevels.get(sLevels.size()-1);
496                     } else {
497                         this.selectedSourceLevel = null;
498                     }
499                 }
500             }
501             return this.selectedSourceLevel;
502         }
503         
504         public void setSelectedItem(Object JavaDoc obj) {
505             this.selectedSourceLevel = (SpecificationVersion) obj;
506             this.fireContentsChanged(this, -1, -1);
507         }
508         
509         public void intervalAdded(ListDataEvent JavaDoc e) {
510         }
511         
512         public void intervalRemoved(ListDataEvent JavaDoc e) {
513         }
514         
515         public void contentsChanged(ListDataEvent JavaDoc e) {
516             PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
517             JavaPlatform platform = getPlatform(selectedPlatform);
518             if (platform != null) {
519                 SpecificationVersion version = platform.getSpecification().getVersion();
520                 if (this.selectedSourceLevel != null && this.selectedSourceLevel.compareTo(version)>0 &&
521                         !shouldChangePlatform(selectedSourceLevel, version)) {
522                     //Restore original
523
this.platformComboBoxModel.setSelectedItem(this.activePlatform);
524                     return;
525                 }
526             }
527             this.activePlatform = selectedPlatform;
528             resetCache();
529         }
530         
531         private void resetCache() {
532             synchronized (this) {
533                 this.sourceLevelCache = null;
534             }
535             this.fireContentsChanged(this, -1, -1);
536         }
537         
538         private SpecificationVersion[] getSourceLevels() {
539             if (this.sourceLevelCache == null) {
540                 PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
541                 JavaPlatform platform = getPlatform(selectedPlatform);
542                 List JavaDoc<SpecificationVersion> sLevels = new ArrayList JavaDoc<SpecificationVersion>();
543                 //If platform == null broken platform, the source level range is unknown
544
//The source level combo box should be empty and disabled
545
if (platform != null) {
546                     SpecificationVersion version = platform.getSpecification().getVersion();
547                     int index = INITIAL_VERSION_MINOR;
548                     // #71619 - source level lower than 1.5 won't be shown for Java EE 5 project
549
if (j2eePlatform != null && j2eePlatform.equals(AppClientProjectProperties.JAVA_EE_5)) {
550                         index = INITIAL_VERSION_MINOR_JAVA_EE_5;
551                     }
552                     SpecificationVersion template = new SpecificationVersion(VERSION_PREFIX + Integer.toString(index++));
553                     while (template.compareTo(version)<=0) {
554                         sLevels.add(template);
555                         template = new SpecificationVersion(VERSION_PREFIX + Integer.toString(index++));
556                     }
557                 }
558                 this.sourceLevelCache = sLevels.toArray(new SpecificationVersion[sLevels.size()]);
559             }
560             return this.sourceLevelCache;
561         }
562         
563         private static boolean shouldChangePlatform(SpecificationVersion selectedSourceLevel, SpecificationVersion platformSourceLevel) {
564             JButton JavaDoc changeOption = new JButton JavaDoc(NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform"));
565             changeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform"));
566             String JavaDoc message = MessageFormat.format(NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatform"),new Object JavaDoc[] {
567                 selectedSourceLevel.toString(),
568                 platformSourceLevel.toString(),
569             });
570             return DialogDisplayer.getDefault().notify(
571                     new NotifyDescriptor(message,
572                     NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatformTitle"),
573                     NotifyDescriptor.DEFAULT_OPTION,
574                     NotifyDescriptor.WARNING_MESSAGE,
575                     new Object JavaDoc[] {
576                 changeOption,
577                 NotifyDescriptor.CANCEL_OPTION
578             },
579                     changeOption)) == changeOption;
580         }
581     }
582     
583     private static class SourceLevelListCellRenderer implements ListCellRenderer JavaDoc {
584         
585         ListCellRenderer JavaDoc delegate;
586         
587         public SourceLevelListCellRenderer() {
588             this.delegate = HtmlRenderer.createRenderer();
589         }
590         
591         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
592             String JavaDoc message;
593             if (value == null) {
594                 message = ""; //NOI18N
595
} else {
596                 assert value instanceof SpecificationVersion;
597                 SpecificationVersion key = (SpecificationVersion) value;
598                 message = key.toString();
599             }
600             return this.delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus);
601         }
602     }
603     
604 }
605
Popular Tags