1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.web.ErrorPage; 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 ErrorPagesTablePanel extends DefaultTablePanel { 36 private ErrorPagesTableModel model; 37 private WebApp webApp; 38 private DDDataObject dObj; 39 40 41 public ErrorPagesTablePanel(final DDDataObject dObj, final ErrorPagesTableModel model) { 42 super(model); 43 this.model=model; 44 this.dObj=dObj; 45 webApp = dObj.getWebApp(); 46 removeButton.addActionListener(new java.awt.event.ActionListener () { 47 public void actionPerformed(java.awt.event.ActionEvent evt) { 48 dObj.modelUpdatedFromUI(); 49 dObj.setChangedFromUI(true); 50 int row = getTable().getSelectedRow(); 51 model.removeRow(row); 52 dObj.setChangedFromUI(false); 53 } 54 }); 55 addButton.addActionListener(new TableActionListener(true)); 56 editButton.addActionListener(new TableActionListener(false)); 57 } 58 59 void setModel(WebApp webApp, ErrorPage[] pages) { 60 model.setData(webApp,pages); 61 this.webApp=webApp; 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 70 public void actionPerformed(java.awt.event.ActionEvent evt) { 71 final int row = (add?-1:getTable().getSelectedRow()); 72 String [] labels = new String []{ 73 NbBundle.getMessage(ErrorPagesTablePanel.class,"LBL_errorPage"), 74 NbBundle.getMessage(ErrorPagesTablePanel.class,"LBL_errorCode"), 75 NbBundle.getMessage(ErrorPagesTablePanel.class,"LBL_exceptionType") 76 }; 77 78 char[] mnem = new char[] { 79 NbBundle.getMessage(ErrorPagesTablePanel.class,"LBL_errorPage_mnem").charAt(0), 80 NbBundle.getMessage(ErrorPagesTablePanel.class,"LBL_errorCode_mnem").charAt(0), 81 NbBundle.getMessage(ErrorPagesTablePanel.class,"LBL_exceptionType_mnem").charAt(0) 82 }; 83 SimpleDialogPanel.DialogDescriptor descriptor = new SimpleDialogPanel.DialogDescriptor(labels); 84 if (!add) { 85 Integer val = (Integer )model.getValueAt(row,1); 86 String [] initValues = new String [] { 87 (String )model.getValueAt(row,0), 88 val==null?"":((Integer )val).toString(), 89 (String )model.getValueAt(row,2) 90 }; 91 descriptor.setInitValues(initValues); 92 } 93 descriptor.setButtons(new boolean[]{true,false,false}); 94 descriptor.setMnemonics(mnem); 95 final SimpleDialogPanel dialogPanel = new SimpleDialogPanel(descriptor); 96 dialogPanel.getTextComponents()[0].setEditable(false); 97 dialogPanel.getCustomizerButtons()[0].addActionListener(new java.awt.event.ActionListener () { 98 public void actionPerformed(java.awt.event.ActionEvent evt) { 99 try { 100 org.netbeans.api.project.SourceGroup[] groups = DDUtils.getDocBaseGroups(dObj); 101 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 102 if (fo!=null) { 103 String res = DDUtils.getResourcePath(groups,fo,'/',true); 104 dialogPanel.getTextComponents()[0].setText("/"+res); 105 } 106 } catch (java.io.IOException ex) {} 107 } 108 }); 109 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(ErrorPagesTablePanel.class,"TTL_ErrorPage"),add) { 110 protected String validate() { 111 String [] values = dialogPanel.getValues(); 112 String page = values[0].trim(); 113 String code = values[1].trim(); 114 String exc = values[2].trim(); 115 if (page.length()==0) { 116 return NbBundle.getMessage(ErrorPagesTablePanel.class,"TXT_EmptyErrorPageLocation"); 117 } 118 if (code.length()==0 && exc.length()==0) { 119 return NbBundle.getMessage(ErrorPagesTablePanel.class,"TXT_EP_BothMissing"); 120 } else if (code.length()>0 && exc.length()>0) { 121 return NbBundle.getMessage(ErrorPagesTablePanel.class,"TXT_EP_BothSpecified"); 122 } else if (code.length()>0) { 123 Integer c = null; 124 try { 125 c = new Integer (code); 126 } catch (NumberFormatException ex) {} 127 if (c==null) { 128 return NbBundle.getMessage(ErrorPagesTablePanel.class,"TXT_EP_wrongNumber",code); 129 } else { 130 ErrorPage[] pages = webApp.getErrorPage(); 131 boolean exists=false; 132 for (int i=0;i<pages.length;i++) { 133 if (row!=i && c.equals(pages[i].getErrorCode())) { 134 exists=true; 135 break; 136 } 137 } 138 if (exists) { 139 return NbBundle.getMessage(ErrorPagesTablePanel.class,"TXT_ErrorCodeExists",c); 140 } 141 } 142 } else { 143 ErrorPage[] pages = webApp.getErrorPage(); 144 boolean exists=false; 145 for (int i=0;i<pages.length;i++) { 146 if (row!=i && exc.equals(pages[i].getExceptionType())) { 147 exists=true; 148 break; 149 } 150 } 151 if (exists) { 152 return NbBundle.getMessage(ErrorPagesTablePanel.class,"TXT_ExcTypeExists",exc); 153 } 154 } 155 return null; 156 } 157 }; 158 if (add) dialog.setValid(false); 160 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 161 dialogPanel.getTextComponents()[0].getDocument().addDocumentListener(docListener); 162 dialogPanel.getTextComponents()[1].getDocument().addDocumentListener(docListener); 163 dialogPanel.getTextComponents()[2].getDocument().addDocumentListener(docListener); 164 165 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 166 d.setVisible(true); 167 dialogPanel.getTextComponents()[0].getDocument().removeDocumentListener(docListener); 168 dialogPanel.getTextComponents()[1].getDocument().removeDocumentListener(docListener); 169 dialogPanel.getTextComponents()[2].getDocument().removeDocumentListener(docListener); 170 171 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 172 dObj.modelUpdatedFromUI(); 173 dObj.setChangedFromUI(true); 174 String [] values = dialogPanel.getValues(); 175 String page = values[0].trim(); 176 String code = values[1].trim(); 177 String exc = values[2].trim(); 178 if (add) 179 model.addRow(new Object []{page,(code.length()==0?null:new Integer (code)),(exc.length()==0?null:exc)}); 180 else 181 model.editRow(row,new Object []{page,(code.length()==0?null:new Integer (code)),(exc.length()==0?null:exc)}); 182 dObj.setChangedFromUI(false); 183 } 184 } 185 } 186 } 187 | Popular Tags |