1 19 20 package org.netbeans.modules.web.wizards; 21 22 import java.awt.Dimension ; 23 import java.awt.GridBagConstraints ; 24 import java.awt.Insets ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 28 import javax.swing.JButton ; 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 import javax.swing.JScrollPane ; 32 import javax.swing.ListSelectionModel ; 33 import javax.swing.event.ListSelectionEvent ; 34 import javax.swing.event.ListSelectionListener ; 35 import javax.swing.event.TableModelEvent ; 36 import javax.swing.event.TableModelListener ; 37 38 import org.openide.util.NbBundle; 39 40 44 45 class MappingPanel extends JPanel implements ActionListener , 46 TableModelListener , 47 ListSelectionListener { 48 49 private final static String ADD = "add"; 50 private final static String EDIT = "edit"; 51 private final static String REMOVE = "remove"; 52 private final static String UP = "up"; 53 private final static String DOWN = "down"; 54 55 private JLabel jLtableheader; 57 private MappingTable table; 58 private JButton jBnew, jBedit, jBdelete, jBdown, jBup; 59 private JScrollPane scrollP; 60 private ServletData deployData; 61 private BaseWizardPanel parent; 62 63 private boolean edited = false; 64 65 private static final boolean debug = false; 66 67 private static final long serialVersionUID = 6540270797782597645L; 68 69 public MappingPanel(ServletData deployData, BaseWizardPanel parent) { 70 this.deployData = deployData; 71 this.parent = parent; 72 initComponents (); 73 } 74 75 private void initComponents () { 76 setLayout(new java.awt.GridBagLayout ()); 78 79 GridBagConstraints fullRowC = new GridBagConstraints (); 81 fullRowC.gridx = 0; 82 fullRowC.gridy = 0; 83 fullRowC.gridwidth = 2; 84 fullRowC.anchor = GridBagConstraints.WEST; 85 fullRowC.fill = GridBagConstraints.HORIZONTAL; 86 fullRowC.insets = new Insets (4, 0, 4, 60); 87 88 GridBagConstraints bC = new GridBagConstraints (); 90 bC.gridx = 1; 91 bC.gridy = 1; 92 bC.weightx = 0.1; 93 bC.fill = GridBagConstraints.HORIZONTAL; 94 bC.insets = new Insets (4, 20, 4, 60); 95 96 GridBagConstraints tablePanelC = new GridBagConstraints (); 98 tablePanelC.gridx = 0; 99 tablePanelC.gridy = 1; 100 tablePanelC.gridheight = 6; 101 tablePanelC.fill = GridBagConstraints.BOTH; 102 tablePanelC.weightx = 0.9; 103 tablePanelC.weighty = 1.0; 104 tablePanelC.anchor = GridBagConstraints.WEST; 105 tablePanelC.insets = new Insets (4, 0, 4, 0); 106 107 GridBagConstraints fillerC = new GridBagConstraints (); 109 fillerC.gridx = 1; 110 fillerC.gridy = GridBagConstraints.RELATIVE; 111 fillerC.fill = GridBagConstraints.BOTH; 112 fillerC.weighty = 1.0; 113 fillerC.insets = new Insets (4, 0, 4, 0); 114 115 jLtableheader = new JLabel (NbBundle.getMessage(MappingPanel.class, "LBL_filter_mappings")); 117 jLtableheader.setDisplayedMnemonic(NbBundle.getMessage (MappingPanel.class, "LBL_filter_mappings_mnemonic").charAt(0)); 118 jLtableheader.setLabelFor(table); 119 this.add(jLtableheader, fullRowC); 120 121 table = new MappingTable(deployData.getName(), 123 deployData.getFilterMappings()); 124 jLtableheader.setLabelFor(table); 125 table.getAccessibleContext().setAccessibleName(NbBundle.getMessage(MappingPanel.class, "ACSD_filter_mappings")); table.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(MappingPanel.class, "ACSD_filter_mappings_desc")); 128 table.getModel().addTableModelListener(this); 129 table.getSelectionModel().addListSelectionListener(this); 130 scrollP = new JScrollPane (table); 131 table.setPreferredScrollableViewportSize(new Dimension (300, 200)); 132 this.add(scrollP, tablePanelC); 133 134 jBnew = new JButton (); 135 jBnew.setText(NbBundle.getMessage(MappingPanel.class, 136 "LBL_newdots")); jBnew.setMnemonic(NbBundle.getMessage(MappingPanel.class, "LBL_new_mnemonic").charAt(0)); 138 jBnew.addActionListener(this); 139 jBnew.setActionCommand(ADD); 140 jBnew.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(MappingPanel.class, "ACSD_filter_mappings_new")); 141 this.add(jBnew, bC); 142 143 bC.gridy++; 144 jBedit = new JButton (); 145 jBedit.setText(NbBundle.getMessage(MappingPanel.class, 146 "LBL_edit")); jBedit.setMnemonic(NbBundle.getMessage(MappingPanel.class, "LBL_edit_mnemonic").charAt(0)); 148 jBedit.addActionListener(this); 149 jBedit.setActionCommand(EDIT); 150 jBedit.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(MappingPanel.class, "ACSD_filter_mappings_edit")); 151 this.add(jBedit, bC); 152 153 bC.gridy++; 154 jBdelete = new JButton (); 155 jBdelete.setText(NbBundle.getMessage(MappingPanel.class, 156 "LBL_delete")); jBdelete.setMnemonic(NbBundle.getMessage(MappingPanel.class, "LBL_delete_mnemonic").charAt(0)); 158 jBdelete.addActionListener(this); 159 jBdelete.setActionCommand(REMOVE); 160 jBdelete.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(MappingPanel.class, "ACSD_filter_mappings_delete")); 161 this.add(jBdelete, bC); 162 163 bC.gridy++; 164 jBup = new JButton (); 165 jBup.setText(NbBundle.getMessage(MappingPanel.class, 166 "LBL_move_up")); jBup.setMnemonic(NbBundle.getMessage(MappingPanel.class, "LBL_move_up_mnemonic").charAt(0)); 168 jBup.addActionListener(this); 169 jBup.setActionCommand(UP); 170 jBup.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(MappingPanel.class, "ACSD_filter_mappings_up")); 171 this.add(jBup, bC); 172 173 bC.gridy++; 174 jBdown = new JButton (); 175 jBdown.setText(NbBundle.getMessage(MappingPanel.class, 176 "LBL_move_down")); jBdown.setMnemonic(NbBundle.getMessage(MappingPanel.class, "LBL_move_down_mnemonic").charAt(0)); 178 jBdown.addActionListener(this); 179 jBdown.setActionCommand(DOWN); 180 jBdown.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(MappingPanel.class, "ACSD_filter_mappings_down")); 181 this.add(jBdown, bC); 182 183 bC.gridy++; 184 bC.fill=GridBagConstraints.BOTH; 185 JPanel filler = new JPanel (); 186 this.add(filler, bC); 187 188 this.add(new javax.swing.JPanel (),fillerC); 189 } 190 191 void setData() { 192 if(debug) log("::setData()"); 194 197 table.setFilterName(deployData.getName()); 198 199 if(!edited) { 200 201 if(!deployData.makeEntry()) { 202 this.setEnabled(false); 203 return; 204 } 205 206 table.setRowSelectionInterval(0,0); 207 edited = true; 208 } 209 210 } 212 213 public void actionPerformed(ActionEvent evt) { 214 215 if(debug) log("::actionPerformed()"); if(evt.getSource() instanceof JButton ) { 217 if(evt.getActionCommand() == ADD) { 218 FilterMappingData fmd = new FilterMappingData(deployData.getName()); 219 220 MappingEditor editor = 221 new MappingEditor(fmd, deployData.getServletNames()); 222 editor.showEditor(); 223 if(editor.isOK()) { 224 table.addRow(0, fmd); 225 if(debug) log(fmd.toString()); 226 } 227 } 228 229 else if (evt.getActionCommand() == EDIT) { 230 int index = table.getSelectedRow(); 231 FilterMappingData fmd, fmd2; 232 fmd = table.getRow(index); 233 fmd2 = (FilterMappingData)(fmd.clone()); 234 MappingEditor editor = 235 new MappingEditor(fmd2, deployData.getServletNames()); 236 editor.showEditor(); 237 if(editor.isOK()) { 238 table.setRow(index, fmd2); 239 if(debug) log(fmd2.toString()); 240 } 241 } 242 else if (evt.getActionCommand() == REMOVE) { 243 int index = table.getSelectedRow(); 244 table.removeRow(index); 245 table.clearSelection(); 246 } 247 else if (evt.getActionCommand() == UP) { 248 if(debug) log("\tMove up"); int index = table.getSelectedRow(); 250 table.moveRowUp(index); 251 table.setRowSelectionInterval(index-1, index-1); 252 253 } 254 else if (evt.getActionCommand() == DOWN) { 255 int index = table.getSelectedRow(); 256 table.moveRowDown(index); 257 table.setRowSelectionInterval(index+1, index+1); 258 } 259 } 260 edited = true; 261 deployData.setFilterMappings(table.getFilterMappings()); 262 scrollP.revalidate(); 263 parent.fireChangeEvent(); 264 } 265 266 public void tableChanged(TableModelEvent e) { 267 if(debug) log("::tableChanged()"); edited = true; 269 deployData.setFilterMappings(table.getFilterMappings()); 270 parent.fireChangeEvent(); 271 } 272 273 public void valueChanged(ListSelectionEvent e) { 274 if (e.getValueIsAdjusting()) return; 276 this.setEnabled(deployData.makeEntry()); 277 } 278 279 public void setEnabled(boolean enable) { 280 if(debug) log("::setEnabled()"); 282 jLtableheader.setEnabled(enable); 283 jBnew.setEnabled(enable); 284 285 if(!enable) { 286 jBedit.setEnabled(false); 287 jBdelete.setEnabled(false); 288 jBup.setEnabled(false); 289 jBdown.setEnabled(false); 290 return; 291 } 292 293 ListSelectionModel lsm = table.getSelectionModel(); 294 if (lsm.isSelectionEmpty()) { 295 jBdelete.setEnabled(false); 297 jBedit.setEnabled(false); 298 jBdown.setEnabled(false); 299 jBup.setEnabled(false); 300 } 301 else { 302 int selectedRow = lsm.getMinSelectionIndex(); 304 String str = (String )(table.getValueAt(selectedRow, 0)); 305 boolean canEdit = str.equals(deployData.getName()); 306 jBdelete.setEnabled(canEdit); 307 jBedit.setEnabled(canEdit); 308 int numRows = table.getRowCount(); 309 if(selectedRow > 0) 310 jBup.setEnabled(true); 311 else 312 jBup.setEnabled(false); 313 if(selectedRow < numRows-1) 314 jBdown.setEnabled(true); 315 else 316 jBdown.setEnabled(false); 317 } 318 } 319 320 321 private void log(String s) { 322 System.out.println("MappingPanel" + s); 323 } 324 } | Popular Tags |