1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.service.subpanels; 21 22 import java.awt.Component ; 23 import javax.swing.table.DefaultTableModel ; 24 import javax.swing.table.TableCellEditor ; 25 import org.netbeans.modules.websvc.wsitconf.ui.security.listmodels.*; 26 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityPolicyModelHelper; 27 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 28 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 29 import org.openide.DialogDescriptor; 30 import org.openide.DialogDisplayer; 31 import org.openide.util.HelpCtx; 32 import org.openide.util.NbBundle; 33 34 import javax.swing.*; 35 import java.util.Vector ; 36 37 41 public class TargetsPanel extends javax.swing.JPanel { 42 43 private WSDLModel model; 44 private WSDLComponent comp; 45 46 private Vector <Vector > targetsModel; 47 private MessagePartsModel targetsTableDataModel; 48 private Vector columnNames = new Vector (); 49 50 private AddHeaderPanel addHeaderPanel; 51 52 boolean inSync = false; 53 54 57 public TargetsPanel(WSDLComponent c) { 58 super(); 59 this.model = c.getModel(); 60 this.comp = c; 61 initComponents(); 62 63 columnNames.add(NbBundle.getMessage(TargetsPanel.class, "LBL_Targets_MessagePart")); columnNames.add(NbBundle.getMessage(TargetsPanel.class, "LBL_Targets_Sign")); columnNames.add(NbBundle.getMessage(TargetsPanel.class, "LBL_Targets_Encrypt")); columnNames.add(NbBundle.getMessage(TargetsPanel.class, "LBL_Targets_Require")); 68 sync(); 69 } 70 71 private void sync() { 72 inSync = true; 73 74 targetsModel = SecurityPolicyModelHelper.getTargets(comp); 75 targetsTableDataModel = new MessagePartsModel(getTargetsModel(), columnNames); 76 jTable1.setModel(targetsTableDataModel); 77 jTable1.doLayout(); 78 jTable1.setDefaultEditor(MessageElement.class, new XPathTableCellEditor()); 79 jTable1.getColumnModel().getColumn(TargetElement.DATA).setCellEditor(new XPathTableCellEditor()); 80 81 enableDisable(); 82 83 inSync = false; 84 } 85 86 private AddHeaderPanel getAddHeaderPanel() { 87 if (this.addHeaderPanel == null) { 88 addHeaderPanel = new AddHeaderPanel(); 89 } 90 return addHeaderPanel; 91 } 92 93 private void saveTargetsModel() { 94 if (!inSync) { 95 SecurityPolicyModelHelper.setTargets(comp, getTargetsModel()); 96 jTable1.setModel(new MessagePartsModel(getTargetsModel(), columnNames)); 97 } 98 } 99 100 113 private void enableDisable() { 114 } 125 126 131 private void initComponents() { 133 addHeaderButton = new javax.swing.JButton (); 134 removeButton = new javax.swing.JButton (); 135 addPartButton = new javax.swing.JButton (); 136 addBodyButton = new javax.swing.JButton (); 137 jScrollPane2 = new javax.swing.JScrollPane (); 138 jTable1 = new javax.swing.JTable (); 139 140 addHeaderButton.setText(org.openide.util.NbBundle.getMessage(TargetsPanel.class, "LBL_AddHeader")); addHeaderButton.addActionListener(new java.awt.event.ActionListener () { 142 public void actionPerformed(java.awt.event.ActionEvent evt) { 143 addHeaderButtonActionPerformed(evt); 144 } 145 }); 146 147 removeButton.setText(org.openide.util.NbBundle.getMessage(TargetsPanel.class, "LBL_Remove")); removeButton.addActionListener(new java.awt.event.ActionListener () { 149 public void actionPerformed(java.awt.event.ActionEvent evt) { 150 removeButtonActionPerformed(evt); 151 } 152 }); 153 154 addPartButton.setText(org.openide.util.NbBundle.getMessage(TargetsPanel.class, "LBL_AddXPath")); addPartButton.addActionListener(new java.awt.event.ActionListener () { 156 public void actionPerformed(java.awt.event.ActionEvent evt) { 157 addPartButtonActionPerformed(evt); 158 } 159 }); 160 161 addBodyButton.setText(org.openide.util.NbBundle.getMessage(TargetsPanel.class, "LBL_AddBody")); addBodyButton.addActionListener(new java.awt.event.ActionListener () { 163 public void actionPerformed(java.awt.event.ActionEvent evt) { 164 addBodyButtonActionPerformed(evt); 165 } 166 }); 167 168 jTable1.setModel(new javax.swing.table.DefaultTableModel ( 169 new Object [][] { 170 {null, null, null, null}, 171 {null, null, null, null}, 172 {null, null, null, null}, 173 {null, null, null, null} 174 }, 175 new String [] { 176 "Title 1", "Title 2", "Title 3", "Title 4" 177 } 178 )); 179 jTable1.setShowVerticalLines(false); 180 jTable1.setVerifyInputWhenFocusTarget(false); 181 jScrollPane2.setViewportView(jTable1); 182 183 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 184 this.setLayout(layout); 185 layout.setHorizontalGroup( 186 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 187 .add(layout.createSequentialGroup() 188 .addContainerGap() 189 .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE) 190 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 191 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 192 .add(addBodyButton) 193 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) 194 .add(addPartButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 195 .add(removeButton)) 196 .add(addHeaderButton)) 197 .addContainerGap()) 198 ); 199 200 layout.linkSize(new java.awt.Component [] {addBodyButton, addHeaderButton, addPartButton, removeButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); 201 202 layout.setVerticalGroup( 203 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 204 .add(layout.createSequentialGroup() 205 .addContainerGap() 206 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 207 .add(layout.createSequentialGroup() 208 .add(addBodyButton) 209 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 210 .add(addHeaderButton) 211 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 212 .add(addPartButton) 213 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 214 .add(removeButton)) 215 .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)) 216 .addContainerGap()) 217 ); 218 } 220 private void addBodyButtonActionPerformed(java.awt.event.ActionEvent evt) { MessageBody body = new MessageBody(); 222 if (!(SecurityPolicyModelHelper.targetExists(getTargetsModel(), body) != null)) { 223 Vector row = new Vector (); 224 row.add(TargetElement.DATA, body); 225 row.add(TargetElement.SIGN, Boolean.TRUE); 226 row.add(TargetElement.ENCRYPT, Boolean.FALSE); 227 row.add(TargetElement.REQUIRE, Boolean.FALSE); 228 getTargetsModel().add(row); 229 saveTargetsModel(); 230 } 231 } 233 private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) { int[] rows = jTable1.getSelectedRows(); 235 for (int i=0; i<rows.length; i++) { 236 getTargetsModel().remove(rows[i]); 237 } 238 saveTargetsModel(); 239 } 241 private void addPartButtonActionPerformed(java.awt.event.ActionEvent evt) { MessageElement e = new MessageElement(NbBundle.getMessage(TargetsPanel.class, "TXT_EditHere")); Vector row = new Vector (); 244 row.add(TargetElement.DATA, e); 245 row.add(TargetElement.SIGN, Boolean.FALSE); 246 row.add(TargetElement.ENCRYPT, Boolean.FALSE); 247 row.add(TargetElement.REQUIRE, Boolean.TRUE); 248 getTargetsModel().add(row); 249 jTable1.updateUI(); 250 } 252 private void addHeaderButtonActionPerformed(java.awt.event.ActionEvent evt) { AddHeaderPanel addHeaderPanel = getAddHeaderPanel(); 254 DialogDescriptor dd = new DialogDescriptor( 255 addHeaderPanel, 256 NbBundle.getMessage(TargetsPanel.class, "LBL_SignEncryptChooser_AddHeaderTitle"), true, 258 DialogDescriptor.OK_CANCEL_OPTION, 259 DialogDescriptor.CANCEL_OPTION, 260 DialogDescriptor.DEFAULT_ALIGN, 261 new HelpCtx(TargetsPanel.class), 262 null); 263 if (DialogDisplayer.getDefault().notify(dd).equals(DialogDescriptor.OK_OPTION)) { 264 if (addHeaderPanel != null) { 265 if (addHeaderPanel.isAllHeaders()) { 266 for (String s : MessageHeader.ALL_HEADERS) { 267 MessageHeader h = new MessageHeader(s); 268 if (!(SecurityPolicyModelHelper.targetExists(getTargetsModel(), h) != null)) { 269 Vector row = new Vector (); 270 row.add(TargetElement.DATA, h); 271 row.add(TargetElement.SIGN, Boolean.TRUE); 272 row.add(TargetElement.ENCRYPT, Boolean.FALSE); 273 row.add(TargetElement.REQUIRE, Boolean.FALSE); 274 getTargetsModel().add(row); 275 } 276 } 277 } else { 278 String header = addHeaderPanel.getHeader(); 279 MessageHeader h = new MessageHeader(header); 280 if (!(SecurityPolicyModelHelper.targetExists(getTargetsModel(), h) != null)) { 281 Vector row = new Vector (); 282 row.add(TargetElement.DATA, h); 283 row.add(TargetElement.SIGN, Boolean.TRUE); 284 row.add(TargetElement.ENCRYPT, Boolean.FALSE); 285 row.add(TargetElement.REQUIRE, Boolean.FALSE); 286 getTargetsModel().add(row); 287 } 288 } 289 saveTargetsModel(); 290 } 291 } 292 } 294 public class XPathTableCellEditor extends AbstractCellEditor implements TableCellEditor { 295 JTextField component = new JTextField(); 297 298 public Component getTableCellEditorComponent(JTable table, Object value, 300 boolean isSelected, int rowIndex, int vColIndex) { 301 302 if (isSelected) { 303 305 component.setText(((MessageElement)value).getElement()); 307 308 return component; 310 311 } 312 return null; 313 } 314 315 public Object getCellEditorValue() { 318 return new MessageElement(component.getText()); 320 } 321 322 } 323 324 private class MessagePartsModel extends DefaultTableModel { 325 326 public MessagePartsModel (Vector <Vector > data, Vector columnNames) { 327 super (data, columnNames); } 329 330 @Override 331 public boolean isCellEditable(int row, int column) { 332 Vector rowVector = getTargetsModel().get(row); 333 if (column == 0) { return (rowVector.get(TargetElement.DATA) instanceof MessageElement); 335 } 336 if ((column == 1) || (column ==2)) { 337 return true; 338 } 339 if (column == 3) { 340 return (rowVector.get(TargetElement.DATA) instanceof MessageElement); 341 } 342 return false; 343 } 344 345 @Override 346 public Class getColumnClass(int columnIndex) { 347 if (columnIndex == 0) { 348 return TargetElement.class; 349 } 350 return Boolean .class; 351 } 352 } 353 354 public Vector <Vector > getTargetsModel() { 355 return targetsModel; 356 } 357 358 private javax.swing.JButton addBodyButton; 360 private javax.swing.JButton addHeaderButton; 361 private javax.swing.JButton addPartButton; 362 private javax.swing.JScrollPane jScrollPane2; 363 private javax.swing.JTable jTable1; 364 private javax.swing.JButton removeButton; 365 367 } 368 369 | Popular Tags |