1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.common.InitParam; 23 import org.netbeans.modules.j2ee.dd.api.web.Servlet; 24 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject; 25 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel; 26 import org.netbeans.modules.xml.multiview.ui.EditDialog; 27 import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel; 28 import org.openide.util.NbBundle; 29 30 35 public class InitParamsPanel extends DefaultTablePanel { 36 private InitParamTableModel model; 37 private Servlet servlet; 38 private DDDataObject dObj; 39 40 41 public InitParamsPanel(final DDDataObject dObj, final InitParamTableModel model) { 42 super(model); 43 this.model=model; 44 this.dObj=dObj; 45 removeButton.addActionListener(new java.awt.event.ActionListener () { 46 public void actionPerformed(java.awt.event.ActionEvent evt) { 47 48 int row = getTable().getSelectedRow(); 49 dObj.modelUpdatedFromUI(); 50 dObj.setChangedFromUI(true); 51 model.removeRow(row); 52 dObj.setChangedFromUI(false); 53 } 54 }); 55 editButton.addActionListener(new TableActionListener(false)); 56 addButton.addActionListener(new TableActionListener(true)); 57 } 58 59 void setModel(Servlet servlet, InitParam[] params) { 60 model.setData(servlet,params); 61 this.servlet=servlet; 62 } 63 64 private class TableActionListener implements java.awt.event.ActionListener { 65 private boolean add; 66 TableActionListener(boolean add) { 67 this.add=add; 68 } 69 public void actionPerformed(java.awt.event.ActionEvent evt) { 70 final int row = (add?-1:getTable().getSelectedRow()); 71 String [] labels = new String []{ 72 NbBundle.getMessage(InitParamsPanel.class,"LBL_initParamName"), 73 NbBundle.getMessage(InitParamsPanel.class,"LBL_initParamValue"), 74 NbBundle.getMessage(InitParamsPanel.class,"LBL_description") 75 }; 76 char[] mnem = new char[] { 77 NbBundle.getMessage(InitParamsPanel.class,"LBL_initParamName_mnem").charAt(0), 78 NbBundle.getMessage(InitParamsPanel.class,"LBL_initParamValue_mnem").charAt(0), 79 NbBundle.getMessage(InitParamsPanel.class,"LBL_description_mnem").charAt(0) 80 }; 81 SimpleDialogPanel.DialogDescriptor descriptor = new SimpleDialogPanel.DialogDescriptor(labels); 82 if (!add) { 83 String [] initValues = new String [] { 84 (String )model.getValueAt(row,0), 85 (String )model.getValueAt(row,1), 86 (String )model.getValueAt(row,2) 87 }; 88 descriptor.setInitValues(initValues); 89 } 90 descriptor.setMnemonics(mnem); 91 descriptor.setTextField(new boolean[]{true,true,false}); 92 final SimpleDialogPanel dialogPanel = new SimpleDialogPanel(descriptor); 93 94 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(InitParamsPanel.class,"TTL_InitParam"),add) { 95 protected String validate() { 96 String [] values = dialogPanel.getValues(); 97 String name = values[0]; 98 String value = values[1]; 99 if (name.length()==0) { 100 return NbBundle.getMessage(InitParamsPanel.class,"TXT_EmptyInitParamName"); 101 } else { 102 InitParam[] params = servlet.getInitParam(); 103 boolean exists=false; 104 for (int i=0;i<params.length;i++) { 105 if (row!=i && name.equals(params[i].getParamName())) { 106 exists=true; 107 break; 108 } 109 } 110 if (exists) { 111 return NbBundle.getMessage(InitParamsPanel.class,"TXT_InitParamNameExists",name); 112 } 113 } 114 if (value.length()==0) { 115 return NbBundle.getMessage(InitParamsPanel.class,"TXT_EmptyInitParamValue"); 116 } 117 return null; 118 } 119 }; 120 121 if (add) dialog.setValid(false); javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 123 dialogPanel.getTextComponents()[0].getDocument().addDocumentListener(docListener); 124 dialogPanel.getTextComponents()[1].getDocument().addDocumentListener(docListener); 125 126 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 127 d.setVisible(true); 128 dialogPanel.getTextComponents()[0].getDocument().removeDocumentListener(docListener); 129 dialogPanel.getTextComponents()[1].getDocument().removeDocumentListener(docListener); 130 131 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 132 dObj.modelUpdatedFromUI(); 133 dObj.setChangedFromUI(true); 134 String [] values = dialogPanel.getValues(); 135 String name = values[0]; 136 String value = values[1]; 137 String description = values[2]; 138 if (add) model.addRow(new String []{name,value,description}); 139 else model.editRow(row,new String []{name,value,description}); 140 dObj.setChangedFromUI(false); 141 } 142 } 143 } 144 } 145 | Popular Tags |