KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > customizer > CustomizerJarContent


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.earproject.ui.customizer;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26 import javax.swing.DefaultListModel JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28 import javax.swing.JTable JavaDoc;
29 import javax.swing.ListSelectionModel JavaDoc;
30 import javax.swing.event.ListSelectionEvent JavaDoc;
31 import javax.swing.event.ListSelectionListener JavaDoc;
32 import javax.swing.table.TableColumn JavaDoc;
33 import org.openide.DialogDescriptor;
34 import org.openide.DialogDisplayer;
35 import org.openide.util.HelpCtx;
36 import org.openide.util.NbBundle;
37
38 /**
39  * Customizer for Enterprise Application packaging.
40  */

41 public class CustomizerJarContent extends JPanel JavaDoc implements ArchiveCustomizerPanel, ListSelectionListener JavaDoc, HelpCtx.Provider {
42     
43     private Dialog JavaDoc dialog;
44     private final AddFilter filterDlg = new AddFilter();
45     private final DefaultListModel JavaDoc dlm = new DefaultListModel JavaDoc();
46     private final EarProjectProperties earProperties;
47     private final VisualPropertySupport vps;
48     private final VisualArchiveIncludesSupport vws;
49     private final ActionListener JavaDoc actionListener;
50     
51     public CustomizerJarContent(EarProjectProperties earProperties) {
52         initComponents();
53         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_A11YDesc"));
54         
55         this.earProperties = earProperties;
56         vps = new VisualPropertySupport(earProperties);
57         vws = new VisualArchiveIncludesSupport( earProperties.getProject(),
58                 (String JavaDoc) earProperties.get(EarProjectProperties.J2EE_PLATFORM),
59                 jTableAddContent,
60                 jButtonAddJar,
61                 jButtonAddLib,
62                 jButtonAddProject,
63                 jButtonRemove);
64         
65         jListExContent.setModel(dlm);
66         
67         // XXX correct these when the sematics are well defined
68
//jButtonAddLib.setEnabled(false);
69

70         actionListener = new ActionListener JavaDoc() {
71             public void actionPerformed(ActionEvent JavaDoc event) {
72                 if (event.getSource() == DialogDescriptor.OK_OPTION) {
73                     dlm.addElement(filterDlg.getExpression());
74                     setExcludeProperty();
75                     closeDialog();
76                 }
77             }
78         };
79         
80         jListExContent.getSelectionModel().addListSelectionListener(this);
81         initTableVisualProperties(jTableAddContent);
82     }
83     
84     private void initTableVisualProperties(JTable JavaDoc table) {
85         //table.setGridColor(jTableCpC.getBackground());
86
table.setRowHeight(jTableAddContent.getRowHeight() + 4);
87         table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
88         table.setIntercellSpacing(new java.awt.Dimension JavaDoc(0, 0));
89         // set the color of the table's JViewport
90
table.getParent().setBackground(table.getBackground());
91    
92         //#88174 - Need horizontal scrollbar for library names
93
//ugly but I didn't find a better way how to do it
94
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
95         TableColumn JavaDoc column = table.getColumnModel().getColumn(0);
96         column.setMinWidth(230);
97         column.setWidth(230);
98         column.setMinWidth(75);
99         column = table.getColumnModel().getColumn(1);
100         column.setMinWidth(126);
101         column.setWidth(126);
102         column.setMinWidth(28);
103     }
104     
105     public void initValues() {
106         vps.register(jTextFieldFileName, EarProjectProperties.JAR_NAME);
107         vps.register(jCheckBoxCommpress, EarProjectProperties.JAR_COMPRESS);
108         vps.register(vws, EarProjectProperties.JAR_CONTENT_ADDITIONAL);
109         
110         dlm.removeAllElements();
111         String JavaDoc exclude = (String JavaDoc) earProperties.get(EarProjectProperties.BUILD_CLASSES_EXCLUDES);
112         if (exclude != null) {
113             StringTokenizer JavaDoc excludeTokenizer = new StringTokenizer JavaDoc(exclude, ","); //NOI18N
114
while (excludeTokenizer.hasMoreElements()) {
115                 dlm.addElement(excludeTokenizer.nextToken());
116             }
117         } else {
118             dlm.addElement("**/*.java"); //NOI18N
119
}
120         
121         // Set the initial state of the buttons
122
valueChanged(null);
123     }
124     
125     /** This method is called from within the constructor to
126      * initialize the form.
127      * WARNING: Do NOT modify this code. The content of this method is
128      * always regenerated by the Form Editor.
129      */

130     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
131
private void initComponents() {
132         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
133
134         jPanel1 = new javax.swing.JPanel JavaDoc();
135         jLabelFileName = new javax.swing.JLabel JavaDoc();
136         jTextFieldFileName = new javax.swing.JTextField JavaDoc();
137         jCheckBoxCommpress = new javax.swing.JCheckBox JavaDoc();
138         jLabelExContent = new javax.swing.JLabel JavaDoc();
139         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
140         jListExContent = new javax.swing.JList JavaDoc();
141         jButtonAddFilter = new javax.swing.JButton JavaDoc();
142         jButtonRemoveFilter = new javax.swing.JButton JavaDoc();
143         jLabelAddContent = new javax.swing.JLabel JavaDoc();
144         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
145         jTableAddContent = new javax.swing.JTable JavaDoc();
146         jButtonAddJar = new javax.swing.JButton JavaDoc();
147         jButtonAddLib = new javax.swing.JButton JavaDoc();
148         jButtonAddProject = new javax.swing.JButton JavaDoc();
149         jButtonRemove = new javax.swing.JButton JavaDoc();
150
151         setLayout(new java.awt.GridBagLayout JavaDoc());
152
153         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
154
155         jLabelFileName.setLabelFor(jTextFieldFileName);
156         org.openide.awt.Mnemonics.setLocalizedText(jLabelFileName, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_FileName_JLabel"));
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 11);
160         jPanel1.add(jLabelFileName, gridBagConstraints);
161
162         jTextFieldFileName.setEditable(false);
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
165         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166         gridBagConstraints.weightx = 1.0;
167         jPanel1.add(jTextFieldFileName, gridBagConstraints);
168         jTextFieldFileName.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_FileName_A11YDesc"));
169
170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
172         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
173         gridBagConstraints.weightx = 1.0;
174         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
175         add(jPanel1, gridBagConstraints);
176
177         org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxCommpress, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_Commpres_JCheckBox"));
178         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
179         gridBagConstraints.gridx = 0;
180         gridBagConstraints.gridy = 1;
181         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
182         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
183         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
184         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
185         add(jCheckBoxCommpress, gridBagConstraints);
186         jCheckBoxCommpress.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_Commpres_A11YDesc"));
187
188         jLabelExContent.setLabelFor(jListExContent);
189         org.openide.awt.Mnemonics.setLocalizedText(jLabelExContent, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_Content_JLabel"));
190         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
191         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
192         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
194         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 2, 0);
195         add(jLabelExContent, gridBagConstraints);
196
197         jScrollPane1.setViewportView(jListExContent);
198         jListExContent.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_Content_A11YDesc"));
199
200         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
201         gridBagConstraints.gridheight = 2;
202         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
203         gridBagConstraints.weighty = 1.0;
204         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 11);
205         add(jScrollPane1, gridBagConstraints);
206
207         org.openide.awt.Mnemonics.setLocalizedText(jButtonAddFilter, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_AddFilter_JButton"));
208         jButtonAddFilter.addActionListener(new java.awt.event.ActionListener JavaDoc() {
209             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
210                 jButtonAddFilterActionPerformed(evt);
211             }
212         });
213
214         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
215         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
216         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
217         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
218         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
219         add(jButtonAddFilter, gridBagConstraints);
220         jButtonAddFilter.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_AddFilter_A11YDesc"));
221
222         org.openide.awt.Mnemonics.setLocalizedText(jButtonRemoveFilter, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_RemoveFilter_JButton"));
223         jButtonRemoveFilter.addActionListener(new java.awt.event.ActionListener JavaDoc() {
224             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
225                 jButtonRemoveFilterActionPerformed(evt);
226             }
227         });
228
229         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
230         gridBagConstraints.gridx = 1;
231         gridBagConstraints.gridy = 4;
232         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
233         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
234         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
235         add(jButtonRemoveFilter, gridBagConstraints);
236         jButtonRemoveFilter.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_Remove_A11YDesc"));
237
238         jLabelAddContent.setLabelFor(jTableAddContent);
239         org.openide.awt.Mnemonics.setLocalizedText(jLabelAddContent, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_AddContent_JLabel"));
240         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
241         gridBagConstraints.gridx = 0;
242         gridBagConstraints.gridy = 5;
243         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
244         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
245         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 0, 2, 0);
246         add(jLabelAddContent, gridBagConstraints);
247
248         jTableAddContent.setModel(new javax.swing.table.DefaultTableModel JavaDoc(
249             new Object JavaDoc [][] {
250
251             },
252             new String JavaDoc [] {
253
254             }
255         ));
256         jScrollPane2.setViewportView(jTableAddContent);
257         jTableAddContent.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "LBL_AACH_ProjectJarFiles_JLabel"));
258
259         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
260         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
261         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
262         gridBagConstraints.weightx = 1.0;
263         gridBagConstraints.weighty = 1.0;
264         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
265         add(jScrollPane2, gridBagConstraints);
266
267         org.openide.awt.Mnemonics.setLocalizedText(jButtonAddJar, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_AddJar_JButton"));
268         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
269         gridBagConstraints.gridx = 1;
270         gridBagConstraints.gridy = 6;
271         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
272         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
273         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
274         add(jButtonAddJar, gridBagConstraints);
275         jButtonAddJar.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_AddJar_A11YDesc"));
276
277         org.openide.awt.Mnemonics.setLocalizedText(jButtonAddLib, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_AddLib_JButton"));
278         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
279         gridBagConstraints.gridx = 1;
280         gridBagConstraints.gridy = 7;
281         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
282         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
283         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
284         add(jButtonAddLib, gridBagConstraints);
285         jButtonAddLib.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_AddLib_A11YDesc"));
286
287         org.openide.awt.Mnemonics.setLocalizedText(jButtonAddProject, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_AddProject_JButton"));
288         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
289         gridBagConstraints.gridx = 1;
290         gridBagConstraints.gridy = 8;
291         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
292         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
293         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
294         add(jButtonAddProject, gridBagConstraints);
295         jButtonAddProject.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_AddProject_A11YDesc"));
296
297         org.openide.awt.Mnemonics.setLocalizedText(jButtonRemove, NbBundle.getMessage(CustomizerJarContent.class, "LBL_CustomizeEAR_Remove_JButton"));
298         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
299         gridBagConstraints.gridx = 1;
300         gridBagConstraints.gridy = 9;
301         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
302         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
303         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
304         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
305         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
306         add(jButtonRemove, gridBagConstraints);
307         jButtonRemove.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerJarContent.class, "ACS_CustomizeEAR_AdditionalRemove_A11YDesc"));
308
309     }
310     // </editor-fold>//GEN-END:initComponents
311

312     private void jButtonRemoveFilterActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonRemoveFilterActionPerformed
313
Object JavaDoc[] items = jListExContent.getSelectedValues();
314         for (int i = 0; i < items.length; i++) {
315             dlm.removeElement(items[i]);
316         }
317         setExcludeProperty();
318     }//GEN-LAST:event_jButtonRemoveFilterActionPerformed
319

320     private void jButtonAddFilterActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonAddFilterActionPerformed
321
DialogDescriptor descriptor = new DialogDescriptor(filterDlg, NbBundle.getMessage(CustomizerJarContent.class, "LBL_AddFilter_Title"), true, actionListener); //NOI18N
322
Object JavaDoc [] closingOptions = {DialogDescriptor.CANCEL_OPTION};
323         descriptor.setClosingOptions(closingOptions);
324         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
325         dialog.setVisible(true);
326     }//GEN-LAST:event_jButtonAddFilterActionPerformed
327

328     // Variables declaration - do not modify//GEN-BEGIN:variables
329
private javax.swing.JButton JavaDoc jButtonAddFilter;
330     private javax.swing.JButton JavaDoc jButtonAddJar;
331     private javax.swing.JButton JavaDoc jButtonAddLib;
332     private javax.swing.JButton JavaDoc jButtonAddProject;
333     private javax.swing.JButton JavaDoc jButtonRemove;
334     private javax.swing.JButton JavaDoc jButtonRemoveFilter;
335     private javax.swing.JCheckBox JavaDoc jCheckBoxCommpress;
336     private javax.swing.JLabel JavaDoc jLabelAddContent;
337     private javax.swing.JLabel JavaDoc jLabelExContent;
338     private javax.swing.JLabel JavaDoc jLabelFileName;
339     private javax.swing.JList JavaDoc jListExContent;
340     private javax.swing.JPanel JavaDoc jPanel1;
341     private javax.swing.JScrollPane JavaDoc jScrollPane1;
342     private javax.swing.JScrollPane JavaDoc jScrollPane2;
343     private javax.swing.JTable JavaDoc jTableAddContent;
344     private javax.swing.JTextField JavaDoc jTextFieldFileName;
345     // End of variables declaration//GEN-END:variables
346

347     private void closeDialog() {
348         if (dialog != null) {
349             dialog.dispose();
350         }
351     }
352     
353     public void valueChanged(ListSelectionEvent JavaDoc e) {
354         jButtonRemoveFilter.setEnabled(!(jListExContent.isSelectionEmpty()));
355     }
356     
357     private void setExcludeProperty() {
358         String JavaDoc exclude = dlm.toString();
359         exclude = exclude.replaceAll(" ", ""); //NOI18N
360
exclude = exclude.substring(1, exclude.length() -1);
361         earProperties.put(EarProjectProperties.BUILD_CLASSES_EXCLUDES, exclude);
362     }
363     
364     /** Help context where to find more about the paste type action.
365      * @return the help context for this action
366      */

367     public HelpCtx getHelpCtx() {
368         return new HelpCtx(CustomizerJarContent.class);
369     }
370     
371 }
372
Popular Tags