KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.text.MessageFormat JavaDoc;
22 import java.util.LinkedList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.swing.DefaultListModel JavaDoc;
26 import javax.swing.ListSelectionModel JavaDoc;
27 import javax.swing.event.ListSelectionListener JavaDoc;
28
29 import org.openide.DialogDescriptor;
30 import org.openide.DialogDisplayer;
31 import org.openide.NotifyDescriptor;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34
35 import org.netbeans.modules.web.api.webmodule.WebModule;
36 import org.netbeans.modules.web.api.webmodule.WebFrameworkSupport;
37 import org.netbeans.modules.web.project.WebProject;
38 import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider;
39
40 public class CustomizerFrameworks extends javax.swing.JPanel JavaDoc implements HelpCtx.Provider, ListSelectionListener JavaDoc {
41     
42     private WebProject project;
43     private WebProjectProperties uiProperties;
44     private List JavaDoc usedFrameworks = new LinkedList JavaDoc();
45     private List JavaDoc newFrameworks = new LinkedList JavaDoc();
46     
47     /** Creates new form CustomizerFrameworks */
48     public CustomizerFrameworks(WebProjectProperties uiProperties) {
49         this.uiProperties = uiProperties;
50         initComponents();
51         
52         project = uiProperties.getProject();
53         initFrameworksList(project.getAPIWebModule());
54     }
55     
56     private void initFrameworksList(WebModule webModule) {
57         jListFrameworks.setModel(new DefaultListModel JavaDoc());
58         List JavaDoc frameworks = WebFrameworkSupport.getFrameworkProviders();
59         for (int i = 0; i < frameworks.size(); i++) {
60             WebFrameworkProvider framework = (WebFrameworkProvider) frameworks.get(i);
61             if (framework.isInWebModule(webModule)) {
62                 usedFrameworks.add(framework);
63                 ((DefaultListModel JavaDoc) jListFrameworks.getModel()).addElement(framework.getName());
64             }
65         }
66         jListFrameworks.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
67         jListFrameworks.addListSelectionListener(this);
68         if (usedFrameworks.size() > 0)
69             jListFrameworks.setSelectedIndex(0);
70         
71         if (frameworks.size() == jListFrameworks.getModel().getSize())
72             jButtonAdd.setEnabled(false);
73     }
74     
75     /** This method is called from within the constructor to
76      * initialize the form.
77      * WARNING: Do NOT modify this code. The content of this method is
78      * always regenerated by the Form Editor.
79      */

80     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
81
private void initComponents() {
82         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
83
84         jLabelFrameworks = new javax.swing.JLabel JavaDoc();
85         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
86         jListFrameworks = new javax.swing.JList JavaDoc();
87         jButtonAdd = new javax.swing.JButton JavaDoc();
88         jSeparator1 = new javax.swing.JSeparator JavaDoc();
89         jLabelConfig = new javax.swing.JLabel JavaDoc();
90         jPanelConfig = new javax.swing.JPanel JavaDoc();
91
92         setLayout(new java.awt.GridBagLayout JavaDoc());
93
94         jLabelFrameworks.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "LBL_CustomizerFrameworks_ListMnemonic").charAt(0));
95         jLabelFrameworks.setLabelFor(jListFrameworks);
96         jLabelFrameworks.setText(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "LBL_UsedFrameworks"));
97         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
98         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
99         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
100         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
101         add(jLabelFrameworks, gridBagConstraints);
102
103         jScrollPane1.setViewportView(jListFrameworks);
104         jListFrameworks.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "ACS_Frameworks_FrameworksList_A11YDesc"));
105
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.gridx = 0;
108         gridBagConstraints.gridy = 1;
109         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
110         gridBagConstraints.weightx = 1.0;
111         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 12);
112         add(jScrollPane1, gridBagConstraints);
113
114         jButtonAdd.setMnemonic(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "LBL_CustomizerFrameworks_AddButton_LabelMnemonic").charAt(0));
115         jButtonAdd.setText(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "LBL_AddFramework"));
116         jButtonAdd.setActionCommand("Add...");
117         jButtonAdd.addActionListener(new java.awt.event.ActionListener JavaDoc() {
118             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
119                 jButtonAddActionPerformed(evt);
120             }
121         });
122
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.gridx = 1;
125         gridBagConstraints.gridy = 1;
126         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
127         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
128         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
129         add(jButtonAdd, gridBagConstraints);
130         jButtonAdd.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "ACS_Frameworks_AddButton_A11YDesc"));
131
132         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
133         gridBagConstraints.gridx = 0;
134         gridBagConstraints.gridy = 2;
135         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
136         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
138         add(jSeparator1, gridBagConstraints);
139
140         jLabelConfig.setLabelFor(jPanelConfig);
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.gridx = 0;
143         gridBagConstraints.gridy = 3;
144         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
147         add(jLabelConfig, gridBagConstraints);
148
149         jPanelConfig.setLayout(new java.awt.GridBagLayout JavaDoc());
150
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridx = 0;
153         gridBagConstraints.gridy = 4;
154         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
155         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
156         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
157         gridBagConstraints.weighty = 1.0;
158         add(jPanelConfig, gridBagConstraints);
159
160     }// </editor-fold>//GEN-END:initComponents
161

162     private void jButtonAddActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonAddActionPerformed
163
AddFrameworkPanel panel = new AddFrameworkPanel(usedFrameworks);
164         javax.swing.JPanel JavaDoc inner = new javax.swing.JPanel JavaDoc();
165         inner.setLayout(new java.awt.GridBagLayout JavaDoc());
166         inner.getAccessibleContext().setAccessibleDescription(panel.getAccessibleContext().getAccessibleDescription());
167         inner.getAccessibleContext().setAccessibleName(panel.getAccessibleContext().getAccessibleName());
168         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
169         gridBagConstraints.gridx = 0;
170         gridBagConstraints.gridy = 0;
171         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
172         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
173         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
174         gridBagConstraints.weightx = 1.0;
175         gridBagConstraints.weighty = 1.0;
176         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
177         inner.add(panel, gridBagConstraints);
178  
179         DialogDescriptor desc = new DialogDescriptor(inner, NbBundle.getMessage(CustomizerFrameworks.class, "LBL_SelectWebExtension_DialogTitle")); //NOI18N
180
Object JavaDoc res = DialogDisplayer.getDefault().notify(desc);
181         if (res.equals(NotifyDescriptor.YES_OPTION)) {
182             newFrameworks.addAll(panel.getSelectedFrameworks());
183             if (newFrameworks != null) {
184                 uiProperties.setNewFrameworks(newFrameworks);
185                 for(int i = 0; i < newFrameworks.size(); i++) {
186                     WebFrameworkProvider framework = (WebFrameworkProvider) newFrameworks.get(i);
187             if (!((DefaultListModel JavaDoc) jListFrameworks.getModel()).contains(framework.getName()))
188             ((DefaultListModel JavaDoc) jListFrameworks.getModel()).addElement(framework.getName());
189             
190             if (usedFrameworks.size() == 0)
191             usedFrameworks.add(framework);
192             else
193             for (int j = 0; j < usedFrameworks.size(); j++)
194                 if (!((WebFrameworkProvider) usedFrameworks.get(j)).getName().equals(framework.getName())) {
195                 usedFrameworks.add(framework);
196                 break;
197                 }
198             
199                     jListFrameworks.setSelectedValue(framework.getName(), true);
200                 }
201             }
202         }
203         
204         if (WebFrameworkSupport.getFrameworkProviders().size() == jListFrameworks.getModel().getSize())
205             jButtonAdd.setEnabled(false);
206     }//GEN-LAST:event_jButtonAddActionPerformed
207

208     
209     // Variables declaration - do not modify//GEN-BEGIN:variables
210
private javax.swing.JButton JavaDoc jButtonAdd;
211     private javax.swing.JLabel JavaDoc jLabelConfig;
212     private javax.swing.JLabel JavaDoc jLabelFrameworks;
213     private javax.swing.JList JavaDoc jListFrameworks;
214     private javax.swing.JPanel JavaDoc jPanelConfig;
215     private javax.swing.JScrollPane JavaDoc jScrollPane1;
216     private javax.swing.JSeparator JavaDoc jSeparator1;
217     // End of variables declaration//GEN-END:variables
218

219     /** Help context where to find more about the paste type action.
220      * @return the help context for this action
221      */

222     public HelpCtx getHelpCtx() {
223         return new HelpCtx(CustomizerFrameworks.class);
224     }
225
226     public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc e) {
227         String JavaDoc frameworkName = (String JavaDoc) jListFrameworks.getSelectedValue();
228     int selectedIndex = jListFrameworks.getSelectedIndex();
229     if (selectedIndex != -1) {
230         WebFrameworkProvider framework = (WebFrameworkProvider) usedFrameworks.get(selectedIndex);
231         WebModule wm = WebModule.getWebModule(project.getProjectDirectory());
232         if (framework.getName().equals(frameworkName))
233         if (framework.getConfigurationPanel(wm) != null) {
234             String JavaDoc message = MessageFormat.format(NbBundle.getMessage(CustomizerFrameworks.class, "LBL_FrameworkConfiguration"), new Object JavaDoc[] {frameworkName}); //NOI18N
235
jLabelConfig.setText(message);
236             jPanelConfig.removeAll();
237
238             java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
239             gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
240             gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
241             gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
242             gridBagConstraints.weightx = 1.0;
243             gridBagConstraints.weighty = 1.0;
244
245             jPanelConfig.add(framework.getConfigurationPanel(wm).getComponent(), gridBagConstraints);
246             jPanelConfig.revalidate();
247         } else {
248             hideConfigPanel();
249         }
250     } else
251         hideConfigPanel();
252     }
253
254     private void hideConfigPanel() {
255     jLabelConfig.setText(""); //NOI18N
256
jPanelConfig.removeAll();
257     jPanelConfig.repaint();
258     jPanelConfig.revalidate();
259     }
260 }
261
Popular Tags