1 19 20 21 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 22 23 import org.netbeans.modules.j2ee.dd.api.common.SecurityRole; 24 import org.netbeans.modules.j2ee.dd.api.common.SecurityRoleRef; 25 import org.netbeans.modules.j2ee.dd.api.web.Servlet; 26 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 27 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject; 28 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel; 29 import org.netbeans.modules.xml.multiview.ui.EditDialog; 30 import org.openide.util.NbBundle; 31 32 39 public class SecurityRoleRefTablePanel extends DefaultTablePanel { 40 41 private SecurityRoleRefTableModel model; 42 private WebApp webApp; 43 private DDDataObject dObj; 44 private Servlet servlet; 45 46 47 public SecurityRoleRefTablePanel(final DDDataObject dObj, 48 final SecurityRoleRefTableModel model) { 49 super(model); 50 this.model=model; 51 this.dObj=dObj; 52 53 removeButton.addActionListener(new java.awt.event.ActionListener () { 54 public void actionPerformed(java.awt.event.ActionEvent evt) { 55 dObj.modelUpdatedFromUI(); 56 dObj.setChangedFromUI(true); 57 int row = getTable().getSelectedRow(); 58 model.removeRow(row); 59 dObj.setChangedFromUI(false); 60 } 61 }); 62 editButton.addActionListener(new TableActionListener(false)); 63 addButton.addActionListener(new TableActionListener(true)); 64 } 65 66 void setModel(WebApp webApp, Servlet servlet, SecurityRoleRef[] roleRefs) { 67 model.setData(servlet, roleRefs); 68 model.setWebApp(webApp); 69 this.webApp=webApp; 70 this.servlet = servlet; 71 } 72 73 private class TableActionListener implements java.awt.event.ActionListener { 74 private boolean add; 75 76 TableActionListener(boolean add) { 77 this.add=add; 78 } 79 80 public void actionPerformed(java.awt.event.ActionEvent evt) { 81 final int row = (add?-1:getTable().getSelectedRow()); 82 final SecurityRoleRefPanel dialogPanel = new SecurityRoleRefPanel( 83 webApp.getSecurityRole()); 84 85 if (!add) { 86 SecurityRoleRef roleRef = model.getSecurityRoleRef(row); 87 dialogPanel.setRoleRefName(roleRef.getRoleName()); 88 dialogPanel.setRoleRefLink(roleRef.getRoleLink()); 89 dialogPanel.setDescription(roleRef.getDefaultDescription()); 90 } 91 92 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(EjbRefsTablePanel.class,"TTL_SecurityRoleRef"),add) { 93 protected String validate() { 94 String name = dialogPanel.getRoleRefName().trim(); 95 SecurityRoleRef roleRef = null; 96 97 if (row != -1) 98 roleRef = model.getSecurityRoleRef(row); 99 100 if (name.length()==0) { 101 return NbBundle.getMessage(SecurityRoleRefTablePanel.class,"TXT_EmptySecurityRoleRefName"); 102 } else { 103 SecurityRoleRef[] roleRefs = servlet.getSecurityRoleRef(); 104 105 for (int i = 0; i < roleRefs.length; i++) { 106 if (roleRefs[i] != roleRef && name.equals(roleRefs[i].getRoleName())) { 107 return NbBundle.getMessage(SecurityRoleRefTablePanel.class,"TXT_SecurityRoleRefNameExists",name); 108 } 109 } 110 } 111 112 if (isEmpty(dialogPanel.getRoleRefLink())) { 113 return NbBundle.getMessage(SecurityRoleRefTablePanel.class,"TXT_EmptySecurityRoleRefLink"); 114 } 115 116 return null; 117 } 118 }; 119 120 if (add) 121 dialog.setValid(false); 123 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 124 dialogPanel.getRoleRefNameTF().getDocument().addDocumentListener(docListener); 125 dialogPanel.getDescriptionTA().getDocument().addDocumentListener(docListener); 126 127 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 128 d.setVisible(true); 129 130 dialogPanel.getRoleRefNameTF().getDocument().removeDocumentListener(docListener); 131 dialogPanel.getDescriptionTA().getDocument().removeDocumentListener(docListener); 132 133 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 134 dObj.modelUpdatedFromUI(); 135 dObj.setChangedFromUI(true); 136 137 String roleRefName = dialogPanel.getRoleRefName(); 138 String roleRefLink = dialogPanel.getRoleRefLink(); 139 String description = dialogPanel.getDescription(); 140 141 142 if (add) 143 model.addRow(new String []{roleRefName, roleRefLink, description}); 144 else 145 model.editRow(row, new String []{roleRefName, roleRefLink, description}); 146 147 dObj.setChangedFromUI(false); 148 } 149 } 150 } 151 152 156 private boolean isEmpty(String str){ 157 return null == str || "".equals(str.trim()); 158 } 159 160 161 166 private void initComponents() { 168 169 setLayout(new java.awt.GridBagLayout ()); 170 171 } 173 174 177 } 178 | Popular Tags |