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