1 19 package org.netbeans.modules.apisupport.metainfservices; 20 21 import java.io.File ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.List ; 25 import javax.swing.JPanel ; 26 import javax.swing.event.TableModelEvent ; 27 import javax.swing.event.TableModelListener ; 28 import javax.swing.table.DefaultTableModel ; 29 30 public final class ExportVisualPanel1 extends JPanel 31 implements TableModelListener { 32 private List <String > files; 33 34 ExportWizardPanel1 panel; 35 36 public ExportVisualPanel1(ExportWizardPanel1 panel) { 37 this.panel = panel; 38 initComponents(); 39 40 tableChanged(null); 41 } 42 43 public String getName() { 44 return "Select Inteface to Export"; 45 } 46 47 final void fillTable(Collection <String > interfaces) { 48 DefaultTableModel t = (DefaultTableModel )table.getModel(); 49 if (t.getRowCount() > 0) { 50 return; 51 } 52 53 for (String s : interfaces) { 54 t.addRow(new Object [] { Boolean.FALSE, s }); 55 } 56 57 t.addTableModelListener(this); 58 } 59 60 final List <String > generatedFiles() { 61 return files; 62 } 63 64 65 public void tableChanged(TableModelEvent e) { 66 StringBuffer modifiedFiles = new StringBuffer (); 67 List <String > f = new ArrayList <String >(); 68 69 boolean one = false; 70 DefaultTableModel t = (DefaultTableModel )table.getModel(); 71 for (int i = 0; i < t.getRowCount(); i++) { 72 Boolean b = (Boolean )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 99 private void initComponents() { 101 102 jScrollPane2 = new javax.swing.JScrollPane (); 103 table = new javax.swing.JTable (); 104 description = new javax.swing.JTextArea (); 105 jScrollPane1 = new javax.swing.JScrollPane (); 106 generated = new javax.swing.JTextArea (); 107 generatedLabel = new javax.swing.JLabel (); 108 109 jScrollPane2.setFocusCycleRoot(true); 110 111 table.setModel(new javax.swing.table.DefaultTableModel ( 112 new Object [][] { 113 114 }, 115 new String [] { 116 "Export this interface?", "Class Name" 117 } 118 ) { 119 Class [] types = new Class [] { 120 java.lang.Boolean .class, java.lang.String .class 121 }; 122 boolean[] canEdit = new boolean [] { 123 true, false 124 }; 125 126 public Class 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 } 178 179 private javax.swing.JTextArea description; 181 private javax.swing.JTextArea generated; 182 private javax.swing.JLabel generatedLabel; 183 private javax.swing.JScrollPane jScrollPane1; 184 private javax.swing.JScrollPane jScrollPane2; 185 private javax.swing.JTable table; 186 188 189 190 191 } 192 193 | Popular Tags |