1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.common.ResourceEnvRef; 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 ResEnvRefsTablePanel extends DefaultTablePanel { 36 private ResEnvRefTableModel model; 37 private WebApp webApp; 38 private DDDataObject dObj; 39 40 41 public ResEnvRefsTablePanel(final DDDataObject dObj, final ResEnvRefTableModel 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, ResourceEnvRef[] 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 70 final int row = (add?-1:getTable().getSelectedRow()); 71 final ResEnvRefPanel dialogPanel = new ResEnvRefPanel(); 72 if (!add) { 73 ResourceEnvRef resRef = model.getResourceEnvRef(row); 74 dialogPanel.setResEnvRefName(resRef.getResourceEnvRefName()); 75 dialogPanel.setResEnvRefType(resRef.getResourceEnvRefType()); 76 dialogPanel.setDescription(resRef.getDefaultDescription()); 77 } 78 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(ResEnvRefsTablePanel.class,"TTL_ResourceEnvRef"),add) { 79 protected String validate() { 80 String name = dialogPanel.getResEnvRefName().trim(); 81 String type = dialogPanel.getResEnvRefType().trim(); 82 if (name.length()==0) { 83 return NbBundle.getMessage(ResEnvRefsTablePanel.class,"TXT_EmptyResRefName"); 84 } else { 85 ResourceEnvRef[] params = webApp.getResourceEnvRef(); 86 boolean exists=false; 87 for (int i=0;i<params.length;i++) { 88 if (row!=i && name.equals(params[i].getResourceEnvRefName())) { 89 exists=true; 90 break; 91 } 92 } 93 if (exists) { 94 return NbBundle.getMessage(ResEnvRefsTablePanel.class,"TXT_ResRefNameExists",name); 95 } 96 } 97 if (type.length()==0) { 98 return NbBundle.getMessage(ResEnvRefsTablePanel.class,"TXT_EmptyResTypeValue"); 99 } 100 return null; 101 } 102 }; 103 104 if (add) dialog.setValid(false); javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 106 dialogPanel.getNameTF().getDocument().addDocumentListener(docListener); 107 dialogPanel.getTypeTF().getDocument().addDocumentListener(docListener); 108 109 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 110 d.setVisible(true); 111 dialogPanel.getNameTF().getDocument().removeDocumentListener(docListener); 112 dialogPanel.getTypeTF().getDocument().removeDocumentListener(docListener); 113 114 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 115 dObj.modelUpdatedFromUI(); 116 dObj.setChangedFromUI(true); 117 String name = dialogPanel.getResEnvRefName().trim(); 118 String type = dialogPanel.getResEnvRefType().trim(); 119 String description = dialogPanel.getDescription(); 120 if (add) model.addRow(new String []{name,type,description}); 121 else model.editRow(row,new String []{name,type,description}); 122 dObj.setChangedFromUI(false); 123 } 124 } 125 } 126 } 127 | Popular Tags |