KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > ui > customizer > AddFrameworkPanel


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.web.project.ui.customizer;
21
22 import java.awt.Component JavaDoc;
23 import java.util.LinkedList JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.DefaultListCellRenderer JavaDoc;
26 import javax.swing.DefaultListModel JavaDoc;
27 import javax.swing.JList JavaDoc;
28 import javax.swing.ListSelectionModel JavaDoc;
29
30 import org.netbeans.modules.web.api.webmodule.WebFrameworkSupport;
31 import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider;
32
33 /**
34  *
35  * @author Radko Najman
36  */

37 public class AddFrameworkPanel extends javax.swing.JPanel JavaDoc {
38
39     /** Creates new form AddFrameworkPanel */
40     public AddFrameworkPanel(List JavaDoc usedFrameworks) {
41     initComponents();
42         jListFrameworks.setCellRenderer(new FrameworksListCellRenderer());
43     createFrameworksList(usedFrameworks);
44         jListFrameworks.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
45     }
46     
47     private void createFrameworksList(List JavaDoc usedFrameworks) {
48         List JavaDoc frameworks = WebFrameworkSupport.getFrameworkProviders();
49     DefaultListModel JavaDoc model = new DefaultListModel JavaDoc();
50     jListFrameworks.setModel(model);
51         
52     for (int i = 0; i < frameworks.size(); i++) {
53         WebFrameworkProvider framework = (WebFrameworkProvider) frameworks.get(i);
54         if (usedFrameworks.size() == 0)
55         model.addElement(framework);
56         else
57         for (int j = 0; j < usedFrameworks.size(); j++)
58             if (!((WebFrameworkProvider) usedFrameworks.get(j)).getName().equals(framework.getName())) {
59             model.addElement(framework);
60             break;
61             }
62     }
63
64     
65     }
66
67     
68     /** This method is called from within the constructor to
69      * initialize the form.
70      * WARNING: Do NOT modify this code. The content of this method is
71      * always regenerated by the Form Editor.
72      */

73     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
74
private void initComponents() {
75         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
76         jListFrameworks = new javax.swing.JList JavaDoc();
77         jLabel1 = new javax.swing.JLabel JavaDoc();
78
79         getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/project/ui/customizer/Bundle").getString("ACSD_AddFramework"));
80         jScrollPane1.setViewportView(jListFrameworks);
81         jListFrameworks.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/project/ui/customizer/Bundle").getString("ACSN_ListFrameworks"));
82         jListFrameworks.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/project/ui/customizer/Bundle").getString("ACSD_ListFrameworks"));
83
84         jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/project/ui/customizer/Bundle").getString("LBL_Select_Framework"));
85
86         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
87         this.setLayout(layout);
88         layout.setHorizontalGroup(
89             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
90             .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
91             .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
92         );
93         layout.setVerticalGroup(
94             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
95             .add(layout.createSequentialGroup()
96                 .add(jLabel1)
97                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
98                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
99         );
100     }// </editor-fold>//GEN-END:initComponents
101

102     
103     // Variables declaration - do not modify//GEN-BEGIN:variables
104
public javax.swing.JLabel JavaDoc jLabel1;
105     public javax.swing.JList JavaDoc jListFrameworks;
106     public javax.swing.JScrollPane JavaDoc jScrollPane1;
107     // End of variables declaration//GEN-END:variables
108

109     public List JavaDoc getSelectedFrameworks() {
110     List JavaDoc selectedFrameworks = new LinkedList JavaDoc();
111     DefaultListModel JavaDoc model = (DefaultListModel JavaDoc) jListFrameworks.getModel();
112         int[] indexes = jListFrameworks.getSelectedIndices();
113         for (int i = 0; i < indexes.length; i++)
114         selectedFrameworks.add(model.get(indexes[i]));
115         
116         return selectedFrameworks;
117     }
118
119     public static class FrameworksListCellRenderer extends DefaultListCellRenderer JavaDoc {
120     
121         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
122             if (value instanceof WebFrameworkProvider) {
123                 WebFrameworkProvider item = (WebFrameworkProvider) value;
124                 return super.getListCellRendererComponent(list, item.getName(), index, isSelected, cellHasFocus);
125             } else
126         return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
127         }
128     }
129
130 }
131
Popular Tags