1 6 7 package org.netbeans.modules.xml.catalogsupport.ui.customizer; 8 9 import java.io.IOException ; 10 import java.net.URI ; 11 import java.net.URISyntaxException ; 12 import java.util.ArrayList ; 13 import java.util.Collections ; 14 import java.util.List ; 15 import javax.swing.event.ChangeEvent ; 16 import javax.swing.event.ListSelectionEvent ; 17 import javax.swing.event.TableColumnModelEvent ; 18 import javax.swing.event.TableColumnModelListener ; 19 import javax.swing.table.DefaultTableModel ; 20 21 import org.openide.util.HelpCtx; 22 import org.netbeans.api.project.Project; 23 24 import org.netbeans.modules.xml.retriever.catalog.CatalogEntry; 25 import org.netbeans.modules.xml.retriever.catalog.CatalogWriteModel; 26 import org.netbeans.modules.xml.retriever.catalog.CatalogWriteModelFactory; 27 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 28 29 33 public class CustomizerXMLCatalog extends javax.swing.JPanel implements HelpCtx.Provider { 34 35 private Project project; 36 private CatalogWriteModel cwm; 37 private List <CatalogEntry> cEntries = Collections.emptyList(); 38 private List <CatalogEntry> deletedEntries; 39 40 public CustomizerXMLCatalog(Project project) { 41 this.project = project; 42 initComponents(); 43 initialize(); 44 } 45 46 private void initialize() { 47 try { 48 cwm = CatalogWriteModelFactory.getInstance().getCatalogWriteModelForProject(project.getProjectDirectory()); 49 cEntries = new ArrayList <CatalogEntry>(cwm.getCatalogEntries()); 50 DefaultTableModel model = (DefaultTableModel )catalogTable.getModel(); 51 for(CatalogEntry cEntry:cEntries) { 52 model.addRow(new String []{cEntry.getSource(),cEntry.getTarget()}); 53 } 54 catalogTable.getColumnModel().addColumnModelListener(new TableColumnModelListener () { 55 public void columnAdded(TableColumnModelEvent e) { 56 } 57 public void columnMarginChanged(ChangeEvent e) { 58 } 59 public void columnMoved(TableColumnModelEvent e) { 60 } 61 public void columnRemoved(TableColumnModelEvent e) { 62 } 63 public void columnSelectionChanged(ListSelectionEvent e) { 64 if(catalogTable.getSelectedColumnCount()==0) { 65 removeButton.setEnabled(false); 66 } else { 67 removeButton.setEnabled(true); 68 } 69 } 70 }); 71 } catch (CatalogModelException ex) { 72 } 74 } 75 76 81 private void initComponents() { 83 topLabel = new javax.swing.JLabel (); 84 jScrollPane1 = new javax.swing.JScrollPane (); 85 catalogTable = new javax.swing.JTable (); 86 removeButton = new javax.swing.JButton (); 87 cacheLabel = new javax.swing.JLabel (); 88 cacheTextField = new javax.swing.JTextField (); 89 clearCacheButton = new javax.swing.JButton (); 90 91 topLabel.setLabelFor(catalogTable); 92 org.openide.awt.Mnemonics.setLocalizedText(topLabel, org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "LBL_CustomizerXMLCatalog_CatalogEntries")); 93 topLabel.setToolTipText(org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "HINT_CustomizerXMLCatalog_CatalogEntries")); 94 95 catalogTable.setModel(new DefaultTableModel ( 96 new String [][]{}, 97 new String []{org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "LBL_CustomizerXMLCatalog_ReferenceKey"), 98 org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "LBL_CustomizerXMLCatalog_ReferencedLocation"), 99 } 100 )); 101 jScrollPane1.setViewportView(catalogTable); 102 103 org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "LBL_CustomizerXMLCatalog_RemoveButton")); 104 removeButton.setToolTipText(org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "HINT_CustomizerXMLCatalog_RemoveButton")); 105 removeButton.setEnabled(false); 106 removeButton.addActionListener(new java.awt.event.ActionListener () { 107 public void actionPerformed(java.awt.event.ActionEvent evt) { 108 deleteEntry(evt); 109 } 110 }); 111 112 cacheLabel.setLabelFor(cacheTextField); 113 org.openide.awt.Mnemonics.setLocalizedText(cacheLabel, org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "LBL_CustomizerXMLCatalog_CacheLabel")); 114 cacheLabel.setToolTipText(org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "HINT_CustomizerXMLCatalog_CacheLabel")); 115 116 cacheTextField.setEditable(false); 117 cacheTextField.setText("nbproject/private/retrieved"); 118 cacheTextField.setBorder(null); 119 120 org.openide.awt.Mnemonics.setLocalizedText(clearCacheButton, org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "LBL_CustomizerXMLCatalog_ClearCacheButton")); 121 clearCacheButton.setToolTipText(org.openide.util.NbBundle.getMessage(CustomizerXMLCatalog.class, "HINT_CustomizerXMLCatalog_ClearCacheButton")); 122 clearCacheButton.addActionListener(new java.awt.event.ActionListener () { 123 public void actionPerformed(java.awt.event.ActionEvent evt) { 124 clearCacheDirectory(evt); 125 } 126 }); 127 128 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 129 this.setLayout(layout); 130 layout.setHorizontalGroup( 131 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 132 .add(layout.createSequentialGroup() 133 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 134 .add(layout.createSequentialGroup() 135 .addContainerGap() 136 .add(topLabel)) 137 .add(layout.createSequentialGroup() 138 .add(11, 11, 11) 139 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 140 .add(layout.createSequentialGroup() 141 .add(cacheLabel) 142 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 143 .add(cacheTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)) 144 .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)) 145 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 146 .add(removeButton)) 147 .add(layout.createSequentialGroup() 148 .addContainerGap() 149 .add(clearCacheButton))) 150 .addContainerGap()) 151 ); 152 layout.setVerticalGroup( 153 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 154 .add(layout.createSequentialGroup() 155 .addContainerGap() 156 .add(topLabel) 157 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 158 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 159 .add(removeButton) 160 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)) 161 .add(11, 11, 11) 162 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 163 .add(cacheLabel) 164 .add(cacheTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 165 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 166 .add(clearCacheButton) 167 .addContainerGap()) 168 ); 169 } 171 175 private void deleteEntry(java.awt.event.ActionEvent evt) { DefaultTableModel model = (DefaultTableModel )catalogTable.getModel(); 177 int[] rowSelection = catalogTable.getSelectedRows(); 178 if(deletedEntries == null) { 179 deletedEntries = new ArrayList <CatalogEntry>(rowSelection.length); 180 } 181 for(int i = rowSelection.length-1; i>=0; i--) { 182 int idx = rowSelection[i]; 183 model.removeRow(idx); 184 deletedEntries.add(cEntries.remove(idx)); 185 } 186 catalogTable.clearSelection(); 187 } 189 193 private void clearCacheDirectory(java.awt.event.ActionEvent evt) { 195 } 197 200 public void storeProjectData() { 201 if(deletedEntries!=null && cwm !=null) { 202 for(CatalogEntry deletedEntry:deletedEntries) { 203 try { 204 URI uri = new URI (deletedEntry.getSource()); 205 cwm.removeURI(uri); 206 } catch (URISyntaxException ex) { } catch (IOException ex) { } 209 } 210 } 211 } 212 213 public HelpCtx getHelpCtx() { 214 return new HelpCtx(CustomizerXMLCatalog.class); 215 } 216 217 218 private javax.swing.JLabel cacheLabel; 220 private javax.swing.JTextField cacheTextField; 221 private javax.swing.JTable catalogTable; 222 private javax.swing.JButton clearCacheButton; 223 private javax.swing.JScrollPane jScrollPane1; 224 private javax.swing.JButton removeButton; 225 private javax.swing.JLabel topLabel; 226 228 } 229 | Popular Tags |