1 19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui; 20 21 import org.netbeans.modules.j2ee.websphere6.dd.beans.*; 22 import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject; 23 24 import org.netbeans.modules.xml.multiview.ui.*; 25 import org.openide.util.NbBundle; 26 import javax.swing.JComboBox ; 27 33 public class ReferenceTablePanel extends DefaultTablePanel implements DDXmiConstants{ 34 private ReferencesTableModel model; 35 private EjbBindingsType ejbBinding; 36 private WSMultiViewDataObject dObj; 37 38 39 40 public ReferenceTablePanel(final WSMultiViewDataObject dObj, final ReferencesTableModel model) { 41 super(model); 42 this.model=model; 43 this.dObj=dObj; 44 45 46 removeButton.addActionListener(new java.awt.event.ActionListener () { 47 public void actionPerformed(java.awt.event.ActionEvent evt) { 48 dObj.setChangedFromUI(true); 49 int row = getTable().getSelectedRow(); 50 model.removeRow(row); 51 dObj.modelUpdatedFromUI(); 52 dObj.setChangedFromUI(false); 54 } 55 }); 56 editButton.addActionListener(new TableActionListener(false)); 57 addButton.addActionListener(new TableActionListener(true)); 58 } 59 60 void setModel(EjbBindingsType ejbBinding, CommonRef []params) { 61 this.ejbBinding=ejbBinding; 62 model.setData(ejbBinding,params); 63 } 64 65 66 private class TableActionListener implements java.awt.event.ActionListener { 67 private boolean add; 68 TableActionListener(boolean add) { 69 this.add=add; 70 } 71 public void actionPerformed(java.awt.event.ActionEvent evt) { 72 73 final int row = (add?-1:getTable().getSelectedRow()); 74 75 final ReferencePanel dialogPanel = new ReferencePanel(); 76 if(!add) { 77 String type=(String )model.getValueAt(row,0); 78 if(type.equals(BINDING_REFERENCE_TYPES[0])) { 79 dialogPanel.getTypeComboBox().setSelectedIndex(0); 80 }else if(type.equals(BINDING_REFERENCE_TYPES[1])) { 81 dialogPanel.getTypeComboBox().setSelectedIndex(1); 82 } else if(type.equals(BINDING_REFERENCE_TYPES[2])) { 83 dialogPanel.getTypeComboBox().setSelectedIndex(2); 84 } 85 dialogPanel.getIdField().setText((String )model.getValueAt(row,1)); 86 dialogPanel.getJndiNameField().setText((String )model.getValueAt(row,2)); 87 dialogPanel.getHrefField().setText((String )model.getValueAt(row,3)); 88 dialogPanel.getTypeComboBox().setEnabled(false); 89 } 90 91 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(ReferenceTablePanel.class,"TTL_PageParam"),add) { 92 protected String validate() { 93 String id = dialogPanel.getIdField().getText().trim(); 94 String jndiName = dialogPanel.getJndiNameField().getText().trim(); 95 String href = dialogPanel.getHrefField().getText().trim(); 96 if (id.length()==0) { 97 return NbBundle.getMessage(ReferenceTablePanel.class,"TXT_EmptyReferenceId"); 98 } else { 99 CommonRef[] params = ejbBinding.getReferences(); 100 boolean exists=false; 101 for (int i=0;i<params.length;i++) { 102 if (row!=i && id.equals(params[i].getXmiId())) { 103 exists=true; 104 break; 105 } 106 } 107 if (exists) { 108 return NbBundle.getMessage(ReferenceTablePanel.class,"TXT_ReferenceIdExists"); 109 } 110 } 111 112 if (jndiName.length()==0) { 113 return NbBundle.getMessage(ReferenceTablePanel.class,"TXT_EmptyReferenceJndiName"); 114 } 115 116 if (href.length()==0) { 117 return NbBundle.getMessage(ReferenceTablePanel.class,"TXT_EmptyReferenceHref"); 118 } 119 return null; 120 } 121 }; 122 123 if (add) dialog.setValid(false); javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 125 dialogPanel.getJndiNameField().getDocument().addDocumentListener(docListener); 126 dialogPanel.getIdField().getDocument().addDocumentListener(docListener); 127 dialogPanel.getHrefField().getDocument().addDocumentListener(docListener); 128 129 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 130 d.setVisible(true); 131 dialogPanel.getJndiNameField().getDocument().removeDocumentListener(docListener); 132 dialogPanel.getIdField().getDocument().removeDocumentListener(docListener); 133 dialogPanel.getHrefField().getDocument().removeDocumentListener(docListener); 134 135 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 136 137 dObj.setChangedFromUI(true); 138 String id = dialogPanel.getIdField().getText().trim(); 139 String jndiName = dialogPanel.getJndiNameField().getText().trim(); 140 String href = dialogPanel.getHrefField().getText().trim(); 141 String type=(String )dialogPanel.getTypeComboBox().getSelectedItem(); 142 143 if (add) { 144 model.addRow(new String []{type,id,jndiName,href}); 145 } else { 146 model.editRow(row,new String []{type,id,jndiName,href}); 147 } 148 dObj.modelUpdatedFromUI(); 149 dObj.setChangedFromUI(false); 151 } 152 } 153 } 154 } 155 | Popular Tags |