KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > blueprints > ui > BluePrintsPanel


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.j2ee.blueprints.ui;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Cursor JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.Font JavaDoc;
26 import java.awt.FontMetrics JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.awt.geom.Rectangle2D JavaDoc;
30 import java.io.ByteArrayOutputStream JavaDoc;
31 import java.io.File JavaDoc;
32 import java.io.FileOutputStream JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.InputStream JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.Hashtable JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.Map JavaDoc;
40 import java.util.ResourceBundle JavaDoc;
41 import java.util.Set JavaDoc;
42 import javax.swing.ComboBoxModel JavaDoc;
43 import javax.swing.DefaultComboBoxModel JavaDoc;
44 import javax.swing.DefaultListCellRenderer JavaDoc;
45 import javax.swing.ImageIcon JavaDoc;
46 import javax.swing.JLabel JavaDoc;
47 import javax.swing.JList JavaDoc;
48 import javax.swing.JOptionPane JavaDoc;
49 import javax.swing.JScrollBar JavaDoc;
50 import javax.swing.JScrollPane JavaDoc;
51 import javax.swing.SwingUtilities JavaDoc;
52 import javax.swing.border.EmptyBorder JavaDoc;
53 import javax.swing.text.BadLocationException JavaDoc;
54 import javax.swing.text.html.HTMLEditorKit JavaDoc;
55 import org.netbeans.modules.j2ee.blueprints.catalog.SolutionsCatalog;
56 import org.netbeans.modules.j2ee.blueprints.catalog.bpcatalogxmlparser.Nbcatalog;
57 import org.netbeans.modules.j2ee.blueprints.catalog.bpcatalogxmlparser.Nbcategory;
58 import org.netbeans.modules.j2ee.blueprints.catalog.bpcatalogxmlparser.Nbexample;
59 import org.netbeans.modules.j2ee.blueprints.catalog.bpcatalogxmlparser.Nbsolution;
60 import org.netbeans.modules.j2ee.blueprints.catalog.bpcatalogxmlparser.Nbwriteup;
61 import org.openide.ErrorManager;
62 import org.openide.filesystems.FileUtil;
63 import org.openide.util.NbBundle;
64 import org.openide.filesystems.FileObject;
65 import org.openide.loaders.DataObject;
66 import org.openide.filesystems.Repository;
67 import org.openide.cookies.InstanceCookie;
68 import javax.swing.Action JavaDoc;
69
70
71 /**
72  * Browser for BluePrints Solutions Catalog Entries.
73  *
74  * The user can browse categories and articles, design documents and
75  * launch a wizard to create new projects from a template.
76  *
77  * @author Mark Roth
78  * @author Yutaka Yoshida
79  * @author Ludo
80  * @author Richard Gregor
81  */

82 public class BluePrintsPanel extends javax.swing.JPanel JavaDoc {
83     
84     /** Creates new form TitlePanel */
85     public BluePrintsPanel() {
86         initComponents();
87         initTabs();
88         initComboBox();
89     }
90     
91     /** This method is called from within the constructor to
92      * initialize the form.
93      * WARNING: Do NOT modify this code. The content of this method is
94      * always regenerated by the Form Editor.
95      */

96     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
97
private void initComponents() {
98         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
99
100         jPopupMenu1 = new javax.swing.JPopupMenu JavaDoc();
101         titlePanel = new javax.swing.JPanel JavaDoc();
102         sunLogoLbl = new javax.swing.JLabel JavaDoc();
103         titleSubPnl = new javax.swing.JPanel JavaDoc();
104         titleLbl = new AntialiasedJLabel();
105         titleSubLbl = new AntialiasedJLabel();
106         toolbarPanel = new javax.swing.JPanel JavaDoc();
107         entryCbx = new javax.swing.JComboBox JavaDoc();
108         tabbedPnl = new javax.swing.JTabbedPane JavaDoc();
109         categoryPnl = new CategoryTab(this);
110         solutionPnl = new SolutionTab(this);
111         designPnl = new DesignTab(this);
112         examplePnl = new ExampleTab(this);
113         homePnl = new HomeTab(this);
114
115         setLayout(new java.awt.GridBagLayout JavaDoc());
116
117         setBackground(new java.awt.Color JavaDoc(255, 255, 255));
118         titlePanel.setLayout(new java.awt.GridBagLayout JavaDoc());
119
120         titlePanel.setOpaque(false);
121         sunLogoLbl.setBackground(new java.awt.Color JavaDoc(89, 79, 191));
122         sunLogoLbl.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/j2ee/blueprints/ui/resources/logo_sun.gif")));
123         sunLogoLbl.setOpaque(true);
124         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
125         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
126         titlePanel.add(sunLogoLbl, gridBagConstraints);
127
128         titleSubPnl.setLayout(new java.awt.GridBagLayout JavaDoc());
129
130         titleLbl.setBackground(new java.awt.Color JavaDoc(251, 226, 73));
131         titleLbl.setFont(new java.awt.Font JavaDoc("Dialog", 1, 24));
132         titleLbl.setForeground(new java.awt.Color JavaDoc(89, 79, 191));
133         titleLbl.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("NB_title"));
134         titleLbl.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 12, 1, 1));
135         titleLbl.setOpaque(true);
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
138         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
139         gridBagConstraints.weightx = 1.0;
140         titleSubPnl.add(titleLbl, gridBagConstraints);
141
142         titleSubLbl.setBackground(new java.awt.Color JavaDoc(251, 226, 73));
143         titleSubLbl.setForeground(new java.awt.Color JavaDoc(89, 79, 191));
144         titleSubLbl.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("NB_subtitle"));
145         titleSubLbl.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 12, 1, 1));
146         titleSubLbl.setOpaque(true);
147         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
149         gridBagConstraints.weightx = 1.0;
150         titleSubPnl.add(titleSubLbl, gridBagConstraints);
151
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
154         gridBagConstraints.weightx = 1.0;
155         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
156         titlePanel.add(titleSubPnl, gridBagConstraints);
157
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
160         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
161         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
162         gridBagConstraints.weightx = 1.0;
163         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 7, 12);
164         add(titlePanel, gridBagConstraints);
165
166         toolbarPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
167
168         toolbarPanel.setOpaque(false);
169         entryCbx.setMaximumRowCount(16);
170         entryCbx.addItemListener(new java.awt.event.ItemListener JavaDoc() {
171             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
172                 entryCbxItemStateChanged(evt);
173             }
174         });
175
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
178         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
179         gridBagConstraints.weightx = 1.0;
180         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 0, 5);
181         toolbarPanel.add(entryCbx, gridBagConstraints);
182
183         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
184         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
185         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
186         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 7, 1, 7);
187         add(toolbarPanel, gridBagConstraints);
188
189         tabbedPnl.addTab(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("categoryPnl"), categoryPnl);
190
191         tabbedPnl.addTab(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("solutionPnl"), solutionPnl);
192
193         tabbedPnl.addTab(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("designPnl"), designPnl);
194
195         tabbedPnl.addTab(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("examplePnl"), examplePnl);
196
197         tabbedPnl.addTab(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("homePnl"), homePnl);
198
199         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
200         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
201         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
202         gridBagConstraints.weightx = 1.0;
203         gridBagConstraints.weighty = 1.0;
204         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 12);
205         add(tabbedPnl, gridBagConstraints);
206
207     }// </editor-fold>//GEN-END:initComponents
208

209     private void entryCbxItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_entryCbxItemStateChanged
210
if(!navigating) {
211             if(lastSelectedIndex != entryCbx.getSelectedIndex()) {
212                 // sometimes Swing calls this twice - only select the new
213
// entry if a new entry was selected.
214
lastSelectedIndex = entryCbx.getSelectedIndex();
215                 selectNewEntry();
216             }
217         }
218     }//GEN-LAST:event_entryCbxItemStateChanged
219

220     
221     // Variables declaration - do not modify//GEN-BEGIN:variables
222
private javax.swing.JPanel JavaDoc categoryPnl;
223     private javax.swing.JPanel JavaDoc designPnl;
224     private javax.swing.JComboBox JavaDoc entryCbx;
225     private javax.swing.JPanel JavaDoc examplePnl;
226     private javax.swing.JPanel JavaDoc homePnl;
227     private javax.swing.JPopupMenu JavaDoc jPopupMenu1;
228     private javax.swing.JPanel JavaDoc solutionPnl;
229     private javax.swing.JLabel JavaDoc sunLogoLbl;
230     private javax.swing.JTabbedPane JavaDoc tabbedPnl;
231     private javax.swing.JLabel JavaDoc titleLbl;
232     private javax.swing.JPanel JavaDoc titlePanel;
233     private javax.swing.JLabel JavaDoc titleSubLbl;
234     private javax.swing.JPanel JavaDoc titleSubPnl;
235     private javax.swing.JPanel JavaDoc toolbarPanel;
236     // End of variables declaration//GEN-END:variables
237

238     private static final String JavaDoc UI_RESOURCES_URL =
239         "/org/netbeans/modules/j2ee/blueprints/ui/resources"; // NOI18N
240
private static final String JavaDoc ICON_CATEGORY =
241         UI_RESOURCES_URL + "/category.gif"; // NOI18N
242
private static final String JavaDoc ICON_ARTICLE =
243         UI_RESOURCES_URL + "/article.gif"; // NOI18N
244
private static ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
245         "org/netbeans/modules/j2ee/blueprints/ui/Bundle"); // NOI18N
246
static final String JavaDoc CATALOG_RESOURCES_URL =
247         "/org/netbeans/modules/j2ee/blueprints/catalog/resources"; // NOI18N
248

249     public static final String JavaDoc TAB_CATEGORY = "categoryPnl"; // NOI18N
250
public static final String JavaDoc TAB_SOLUTION = "solutionPnl"; // NOI18N
251
public static final String JavaDoc TAB_DESIGN = "designPnl"; // NOI18N
252
public static final String JavaDoc TAB_EXAMPLE = "examplePnl"; // NOI18N
253
public static final String JavaDoc TAB_HOME = "homePnl"; // NOI18N
254
public final HashMap JavaDoc TABS = new HashMap JavaDoc();
255     
256     private SolutionsCatalog solutionsCatalog = SolutionsCatalog.getInstance();
257     private BrowseHistory history = new BrowseHistory();
258     private BrowseHistoryToken historyToken = new BrowseHistoryToken();
259     
260     // True if a change in the combo box should not trigger events.
261
private boolean navigating = false;
262     private int lastSelectedIndex = -1;
263
264     public Nbcategory getSelectedCategory() {
265         Object JavaDoc entry = entryCbx.getSelectedItem();
266         if(!(entry instanceof Nbcategory)) {
267             // Scan up the list until we hit a category
268
int index = entryCbx.getSelectedIndex();
269             do {
270                 index--;
271                 entry = entryCbx.getItemAt(index);
272             } while((index > 0) && !(entry instanceof Nbcategory));
273         }
274         return (Nbcategory)entry;
275     }
276     
277     public Nbsolution getSelectedArticle() {
278         Object JavaDoc entry = entryCbx.getSelectedItem();
279         return (entry instanceof Nbsolution) ? (Nbsolution)entry : null;
280     }
281     
282     public String JavaDoc getExampleId() {
283         String JavaDoc result = null;
284         Nbsolution solution = getSelectedArticle();
285         if(solution != null) {
286             result = solution.getExampleId();
287         }
288         return result;
289     }
290     
291     private void initTabs() {
292         TABS.put(TAB_CATEGORY, categoryPnl);
293         TABS.put(TAB_SOLUTION, solutionPnl);
294         TABS.put(TAB_DESIGN, designPnl);
295         TABS.put(TAB_EXAMPLE, examplePnl);
296         TABS.put(TAB_HOME, homePnl);
297         tabbedPnl.removeAll();
298     }
299     
300     private void initComboBox() {
301         // Set up combo boxes:
302
entryCbx.setRenderer(new EntryListCellRenderer());
303         entryCbx.setModel(new EntryComboBoxModel());
304         entryCbx.setSelectedIndex(0);
305         history.clear();
306         updateTabs();
307         //updateButtons();
308
historyToken = createBrowseHistoryToken();
309     }
310     
311     private void selectNewEntry() {
312         // Article and category will be set in the current history token
313
// but scroll position and tab may be out of date. Update them.
314
historyToken.setScrollPosition(getScrollPosition());
315         historyToken.setTab(getSelectedTabName());
316         history.pushBackStack(historyToken);
317                 
318         updateTabs();
319         //updateButtons();
320

321         // Create a new token that contains the new article and category.
322
historyToken = createBrowseHistoryToken();
323     }
324
325     private void goForward() {
326         if(!history.isForwardStackEmpty()) {
327             navigateTo(history.forward(createBrowseHistoryToken()));
328             //updateButtons();
329
}
330     }
331     
332     private void goBack() {
333         if(!history.isBackStackEmpty()) {
334             navigateTo(history.back(createBrowseHistoryToken()));
335             //updateButtons();
336
}
337     }
338     
339     private BrowseHistoryToken createBrowseHistoryToken() {
340         String JavaDoc category = getSelectedCategory().getId();
341         Nbsolution solution = getSelectedArticle();
342         String JavaDoc article = (solution == null) ? null : solution.getId();
343         String JavaDoc tab = getSelectedTabName();
344         int scrollPosition = getScrollPosition();
345         return new BrowseHistoryToken(category, article, tab, scrollPosition);
346     }
347     
348     private String JavaDoc getSelectedTabName() {
349         Component JavaDoc selectedTab = tabbedPnl.getSelectedComponent();
350         String JavaDoc result = null;
351         Set JavaDoc entries = TABS.entrySet();
352         Iterator JavaDoc iter = entries.iterator();
353         while(iter.hasNext()) {
354             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)iter.next();
355             if(entry.getValue() == selectedTab) {
356                 result = (String JavaDoc)entry.getKey();
357             }
358         }
359         return result;
360     }
361     
362     private int getScrollPosition() {
363         int result = 0;
364         Component JavaDoc selectedTab = tabbedPnl.getSelectedComponent();
365         if(selectedTab != null) {
366             result = ((BluePrintsTabPanel)selectedTab).getScrollPosition();
367         }
368         return result;
369     }
370     
371     private void scrollTo(int position) {
372         Component JavaDoc selectedTab = tabbedPnl.getSelectedComponent();
373         if(selectedTab != null) {
374             ((BluePrintsTabPanel)selectedTab).setScrollPosition(position);
375         }
376     }
377     
378     private void navigateTo(BrowseHistoryToken token) {
379         if(token != null) {
380             String JavaDoc category = token.getCategory();
381             String JavaDoc article = token.getArticle();
382             navigateTo(category, article);
383             updateTabs();
384             String JavaDoc tab = token.getTab();
385             selectTab(tab);
386             int scrollPosition = token.getScrollPosition();
387             scrollTo(scrollPosition);
388             historyToken = createBrowseHistoryToken();
389         }
390     }
391     
392     private void navigateTo(String JavaDoc category, String JavaDoc article) {
393         navigating = true; // prevent duplicate events
394
if(category != null) {
395             boolean foundCategory = false;
396             int count = entryCbx.getItemCount();
397             for(int i = 0; i < count; i++) {
398                 Object JavaDoc entry = entryCbx.getItemAt(i);
399                 if(entry instanceof Nbcategory) {
400                     Nbcategory c = (Nbcategory)entry;
401                     if(c.getId().equals(category)) {
402                         foundCategory = true;
403                         if(article == null) {
404                             // Select just this category
405
entryCbx.setSelectedIndex(i);
406                             break;
407                         }
408                     }
409                     else {
410                         if(foundCategory) {
411                             // We found the category but not the article.
412
break;
413                         }
414                     }
415                 }
416                 else {
417                     if(foundCategory) {
418                         Nbsolution s = (Nbsolution)entryCbx.getItemAt(i);
419                         if(s.getId().equals(article)) {
420                             // Select this article
421
entryCbx.setSelectedIndex(i);
422                             break;
423                         }
424                     }
425                 }
426             }
427         }
428         navigating = false;
429     }
430     
431     /*private void updateButtons() {
432         backBtn.setEnabled(!history.isBackStackEmpty());
433         forwardBtn.setEnabled(!history.isForwardStackEmpty());
434     }*/

435     
436     private void showHome() {
437         tabbedPnl.removeAll();
438         tabbedPnl.addTab(bundle.getString(TAB_HOME),
439                 (Component JavaDoc)TABS.get(TAB_HOME));
440     }
441     
442     private void updateTabs() {
443         Nbcategory category = getSelectedCategory();
444         Nbsolution solution = getSelectedArticle();
445
446         // Ensure the category panel is visible when no solution is selected
447
// and the other panels are visible when an solution is selected.
448
if(solution == null) {
449             if(category.getId().equals("HOME")) { // NOI18N
450
showHome();
451             } else {
452                 tabbedPnl.removeAll();
453                 tabbedPnl.addTab(bundle.getString(TAB_CATEGORY),
454                         (Component JavaDoc)TABS.get(TAB_CATEGORY));
455             }
456         }
457         else {
458             tabbedPnl.removeAll();
459             tabbedPnl.addTab(bundle.getString(TAB_SOLUTION),
460                 (Component JavaDoc)TABS.get(TAB_SOLUTION));
461             tabbedPnl.addTab(bundle.getString(TAB_DESIGN),
462                 (Component JavaDoc)TABS.get(TAB_DESIGN));
463             tabbedPnl.addTab(bundle.getString(TAB_EXAMPLE),
464                 (Component JavaDoc)TABS.get(TAB_EXAMPLE));
465         }
466         
467         updateCategoryTab();
468         updateSolutionTab();
469         updateDesignTab();
470         updateExampleTab();
471         updateHomeTab();
472     }
473     
474     private void selectTab(String JavaDoc tab) {
475         tabbedPnl.setSelectedComponent((Component JavaDoc)TABS.get(tab));
476     }
477     
478     private void updateCategoryTab() {
479         ((BluePrintsTabPanel)categoryPnl).updateTab();
480     }
481     
482     private void updateSolutionTab() {
483         ((BluePrintsTabPanel)solutionPnl).updateTab();
484     }
485     
486     private void updateHomeTab() {
487         ((BluePrintsTabPanel)homePnl).updateTab();
488     }
489     
490     private void updateDesignTab() {
491         Nbcategory category = getSelectedCategory();
492         Nbsolution solution = getSelectedArticle();
493         if(solution != null) {
494             Nbwriteup writeup = solution.getNbwriteup();
495             if(writeup.getDesigndocPath() == null || (writeup.getDesigndocPath().trim().equals(""))) { //NOI18N
496
tabbedPnl.remove(designPnl);
497             }
498         }
499         ((BluePrintsTabPanel)designPnl).updateTab();
500     }
501     
502     public void updateExampleTab() {
503         Nbcategory category = getSelectedCategory();
504         Nbsolution solution = getSelectedArticle();
505         if(solution != null) {
506             String JavaDoc exampleIds = solution.getExampleId();
507             if(exampleIds.trim().equals("")) { //NOI18N
508
tabbedPnl.remove(examplePnl);
509             }
510         }
511         ((BluePrintsTabPanel)examplePnl).updateTab();
512     }
513     
514     /**
515      * Backing model for the entry drop-down.
516      * Gets its data from nbcatalog.xml.
517      */

518     private class EntryComboBoxModel
519         extends DefaultComboBoxModel JavaDoc
520     {
521
522         private ArrayList JavaDoc entries = new ArrayList JavaDoc();
523         private boolean firstTime = true;
524         
525         public EntryComboBoxModel() {
526             //add HOME page
527
Nbcategory homeCategory = new Nbcategory();
528             homeCategory.setId("HOME"); // NOI18N
529
homeCategory.setDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("homeCatDesc"));
530             homeCategory.setCategoryName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("homeCatName"));
531             entries.add(homeCategory);
532             
533             //Populate Current Version Solutions
534
Nbcatalog nbcatalog = solutionsCatalog.getCatalogXml();
535             populateEntries(nbcatalog);
536         }
537         
538         public int getSize() {
539             return entries.size();
540         }
541         
542         public Object JavaDoc getElementAt(int index) {
543             return entries.get(index);
544         }
545         
546         private void populateEntries(Nbcatalog nbcatalog){
547             Nbcategory[] cats = nbcatalog.getNbcategory();
548             for(int categoryNum = 0; categoryNum < cats.length; categoryNum++) {
549                 Nbcategory category = cats[categoryNum];
550                 if(category.getShowSpec().equals("true") && firstTime){
551                     Nbcategory enclCat = new Nbcategory();
552                     String JavaDoc specname = category.getSpec();
553                     enclCat.setId(specname);
554                     enclCat.setDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/BundleBpcatalog").getString(getCatKeyName(specname)));
555                     enclCat.setCategoryName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/BundleBpcatalog").getString(getCatKeyDesc(specname)));
556                     entries.add(enclCat);
557                     firstTime = false;
558                 }
559                 entries.add(category);
560                 
561                 Nbsolution[] solutions = category.getNbsolution();
562                 for(int solutionNum=0; solutionNum < solutions.length; solutionNum++){
563                     entries.add(solutions[solutionNum]);
564                 }
565             }
566         }
567         
568     }
569     
570     /**
571      * Cell renderer for the entry drop-down
572      *
573      * Adds an icon and changes the text of the cell to match the name of
574      * the category or article.
575      */

576     private static class EntryListCellRenderer
577         extends DefaultListCellRenderer JavaDoc
578     {
579         private ImageIcon JavaDoc categoryIcon;
580         private ImageIcon JavaDoc articleIcon;
581
582         public EntryListCellRenderer() {
583             this.categoryIcon = new ImageIcon JavaDoc(getClass().getResource(
584                 ICON_CATEGORY));
585             this.articleIcon = new ImageIcon JavaDoc(getClass().getResource(
586                 ICON_ARTICLE));
587         }
588
589         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list,
590             Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus)
591         {
592             Component JavaDoc result = super.getListCellRendererComponent(list, value,
593                 index, isSelected, cellHasFocus);
594             JLabel JavaDoc label = (JLabel JavaDoc)result;
595             ResourceBundle JavaDoc bundleBpcatalog = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/BundleBpcatalog");
596             String JavaDoc catName=null;
597             String JavaDoc fullName=null;
598             if(value instanceof Nbcategory) {
599                 Nbcategory category = (Nbcategory)value;
600                 label.setIcon(categoryIcon);
601                 
602                 try {
603                     // construct key : "category/CATEGORY-ID/category-name"
604
catName = bundleBpcatalog.getString(getCatKeyName(category.getId()));
605                 } catch (Exception JavaDoc e) {
606                     catName = category.getCategoryName().trim();
607                 }
608                 label.setText(catName);
609             }
610             else if(value instanceof Nbsolution) {
611                 Nbsolution solution = (Nbsolution)value;
612                 label.setIcon(articleIcon);
613                 // construct key : "solution/SOLUTION-ID/full-name"
614
String JavaDoc solKey = "solution/" + solution.getId().trim() + "/full-name";
615                 try {
616                     fullName = bundleBpcatalog.getString(solKey);
617                 } catch (Exception JavaDoc e) {
618                     fullName = solution.getFullName().trim();
619                 }
620                 label.setText(fullName);
621                 // Tab the articles so they look like they're in the category
622
label.setBorder(new EmptyBorder JavaDoc(0, 19, 0, 0));
623             }
624             return result;
625         }
626     }
627     
628     private static String JavaDoc getCatKeyName(String JavaDoc catName){
629         String JavaDoc nameKey = "category/" + catName.trim() + "/category-name"; //NOI18N
630
return nameKey;
631     }
632     
633     private static String JavaDoc getCatKeyDesc(String JavaDoc catDesc){
634         String JavaDoc descKey = "category/" + catDesc.trim() + "/description"; //NOI18N
635
return descKey;
636     }
637     
638 }
639
640
Popular Tags