KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > metainfservices > ExportVisualPanel1


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 package org.netbeans.modules.apisupport.metainfservices;
20
21 import java.io.File JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import javax.swing.event.TableModelEvent JavaDoc;
27 import javax.swing.event.TableModelListener JavaDoc;
28 import javax.swing.table.DefaultTableModel JavaDoc;
29
30 public final class ExportVisualPanel1 extends JPanel JavaDoc
31 implements TableModelListener JavaDoc{
32     private List JavaDoc<String JavaDoc> files;
33
34     ExportWizardPanel1 panel;
35     /** Creates new form ExportVisualPanel1 */
36     public ExportVisualPanel1(ExportWizardPanel1 panel) {
37         this.panel = panel;
38         initComponents();
39
40         tableChanged(null);
41     }
42     
43     public String JavaDoc getName() {
44         return "Select Inteface to Export";
45     }
46
47     final void fillTable(Collection JavaDoc<String JavaDoc> interfaces) {
48         DefaultTableModel JavaDoc t = (DefaultTableModel JavaDoc)table.getModel();
49         if (t.getRowCount() > 0) {
50             return;
51         }
52
53         for (String JavaDoc s : interfaces) {
54             t.addRow(new Object JavaDoc[] { Boolean.FALSE, s });
55         }
56
57         t.addTableModelListener(this);
58     }
59
60     final List JavaDoc<String JavaDoc> generatedFiles() {
61         return files;
62     }
63
64
65     public void tableChanged(TableModelEvent JavaDoc e) {
66         StringBuffer JavaDoc modifiedFiles = new StringBuffer JavaDoc();
67         List JavaDoc<String JavaDoc> f = new ArrayList JavaDoc<String JavaDoc>();
68
69         boolean one = false;
70         DefaultTableModel JavaDoc t = (DefaultTableModel JavaDoc)table.getModel();
71         for (int i = 0; i < t.getRowCount(); i++) {
72             Boolean JavaDoc b = (Boolean JavaDoc)t.getValueAt(i, 0);
73             if (Boolean.TRUE.equals(b)) {
74                 one = true;
75                 modifiedFiles.append(panel.getTarget().getPath())
76                 .append(File.separatorChar)
77                 .append("META-INF")
78                 .append(File.separatorChar)
79                 .append("services")
80                 .append(File.separatorChar)
81                 .append(t.getValueAt(i, 1).toString())
82                 .append("\n");
83
84                 f.add("META-INF/services/" + t.getValueAt(i, 1).toString());
85             }
86         }
87         panel.setValid(one);
88
89         generated.setText(modifiedFiles.toString());
90
91         files = f;
92     }
93
94     /** This method is called from within the constructor to
95      * initialize the form.
96      * WARNING: Do NOT modify this code. The content of this method is
97      * always regenerated by the Form Editor.
98      */

99     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
100
private void initComponents() {
101
102         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
103         table = new javax.swing.JTable JavaDoc();
104         description = new javax.swing.JTextArea JavaDoc();
105         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
106         generated = new javax.swing.JTextArea JavaDoc();
107         generatedLabel = new javax.swing.JLabel JavaDoc();
108
109         jScrollPane2.setFocusCycleRoot(true);
110
111         table.setModel(new javax.swing.table.DefaultTableModel JavaDoc(
112             new Object JavaDoc [][] {
113
114             },
115             new String JavaDoc [] {
116                 "Export this interface?", "Class Name"
117             }
118         ) {
119             Class JavaDoc[] types = new Class JavaDoc [] {
120                 java.lang.Boolean JavaDoc.class, java.lang.String JavaDoc.class
121             };
122             boolean[] canEdit = new boolean [] {
123                 true, false
124             };
125
126             public Class JavaDoc getColumnClass(int columnIndex) {
127                 return types [columnIndex];
128             }
129
130             public boolean isCellEditable(int rowIndex, int columnIndex) {
131                 return canEdit [columnIndex];
132             }
133         });
134         jScrollPane2.setViewportView(table);
135
136         description.setColumns(20);
137         description.setEditable(false);
138         description.setRows(5);
139         description.setText("This wizard is about to generate a registration file that will allow other\nmodules to discover your class using Lookup.getDefault().lookup(SomeInterface.class).\nPlease select one or more interfaces that you which to export your class\nas.");
140         description.setEnabled(false);
141
142         generated.setColumns(20);
143         generated.setEditable(false);
144         generated.setRows(5);
145         generated.setEnabled(false);
146         jScrollPane1.setViewportView(generated);
147
148         org.openide.awt.Mnemonics.setLocalizedText(generatedLabel, "Generated Files:");
149
150         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
151         this.setLayout(layout);
152         layout.setHorizontalGroup(
153             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
154             .add(layout.createSequentialGroup()
155                 .addContainerGap()
156                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
157                     .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
158                     .add(org.jdesktop.layout.GroupLayout.TRAILING, description)
159                     .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
160                     .add(generatedLabel))
161                 .addContainerGap())
162         );
163         layout.setVerticalGroup(
164             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
165             .add(layout.createSequentialGroup()
166                 .addContainerGap()
167                 .add(description, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
168                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
169                 .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 202, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
170                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
171                 .add(generatedLabel)
172                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
173                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 103, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
174                 .addContainerGap())
175         );
176     }// </editor-fold>//GEN-END:initComponents
177

178     
179     // Variables declaration - do not modify//GEN-BEGIN:variables
180
private javax.swing.JTextArea JavaDoc description;
181     private javax.swing.JTextArea JavaDoc generated;
182     private javax.swing.JLabel JavaDoc generatedLabel;
183     private javax.swing.JScrollPane JavaDoc jScrollPane1;
184     private javax.swing.JScrollPane JavaDoc jScrollPane2;
185     private javax.swing.JTable JavaDoc table;
186     // End of variables declaration//GEN-END:variables
187

188
189
190
191 }
192
193
Popular Tags