1 19 20 21 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 22 23 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 24 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef; 25 import org.netbeans.modules.j2ee.dd.api.common.EjbRef; 26 import org.netbeans.modules.j2ee.dd.api.common.SecurityRole; 27 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 28 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject; 29 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel; 30 import org.netbeans.modules.xml.multiview.ui.EditDialog; 31 import org.openide.util.NbBundle; 32 33 40 public class SecurityRoleTablePanel extends DefaultTablePanel { 41 private SecurityRoleTableModel model; 42 private WebApp webApp; 43 private DDDataObject dObj; 44 45 46 public SecurityRoleTablePanel(final DDDataObject dObj, final SecurityRoleTableModel model) { 47 super(model); 48 this.model=model; 49 this.dObj=dObj; 50 51 removeButton.addActionListener(new java.awt.event.ActionListener () { 52 public void actionPerformed(java.awt.event.ActionEvent evt) { 53 dObj.modelUpdatedFromUI(); 54 dObj.setChangedFromUI(true); 55 int row = getTable().getSelectedRow(); 56 model.removeRow(row); 57 dObj.setChangedFromUI(false); 58 } 59 }); 60 editButton.addActionListener(new TableActionListener(false)); 61 addButton.addActionListener(new TableActionListener(true)); 62 } 63 64 void setModel(WebApp webApp, SecurityRole[] roles) { 65 model.setData(webApp, roles); 66 this.webApp=webApp; 67 } 68 69 private class TableActionListener implements java.awt.event.ActionListener { 70 private boolean add; 71 72 TableActionListener(boolean add) { 73 this.add=add; 74 } 75 76 public void actionPerformed(java.awt.event.ActionEvent evt) { 77 final int row = (add?-1:getTable().getSelectedRow()); 78 final SecurityRolePanel dialogPanel = new SecurityRolePanel(); 79 final String currentRoleName = null; 80 SecurityRole role = null; 81 82 if (!add) { 83 role = model.getSecurityRole(row); 84 dialogPanel.setRoleName(role.getRoleName()); 85 dialogPanel.setDescription(role.getDefaultDescription()); 86 } 87 88 final SecurityRole currentRole = role; 89 90 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(EjbRefsTablePanel.class,"TTL_SecurityRole"),add) { 91 protected String validate() { 92 String name = dialogPanel.getRoleName().trim(); 93 94 if (name.length()==0) { 95 return NbBundle.getMessage(SecurityRoleTablePanel.class,"TXT_EmptySecurityRoleName"); 96 } else { 97 SecurityRole[] roles = webApp.getSecurityRole(); 98 boolean exists=false; 99 100 for (int i = 0; i < roles.length; i++) { 101 if (name.equals(roles[i].getRoleName()) && 102 roles[i] != currentRole) { 103 return NbBundle.getMessage(SecurityRoleTablePanel.class,"TXT_SecurityRoleNameExists",name); 104 } 105 } 106 } 107 108 return null; 109 } 110 }; 111 112 if (add) 113 dialog.setValid(false); 115 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 116 dialogPanel.getRoleNameTF().getDocument().addDocumentListener(docListener); 117 dialogPanel.getDescriptionTA().getDocument().addDocumentListener(docListener); 118 119 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 120 d.setVisible(true); 121 122 dialogPanel.getRoleNameTF().getDocument().removeDocumentListener(docListener); 123 dialogPanel.getDescriptionTA().getDocument().removeDocumentListener(docListener); 124 125 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 126 dObj.modelUpdatedFromUI(); 127 dObj.setChangedFromUI(true); 128 129 String roleName = dialogPanel.getRoleName(); 130 String description = dialogPanel.getDescription(); 131 132 if (add) 133 model.addRow(new String []{roleName, description}); 134 else 135 model.editRow(row, new String []{roleName, description}); 136 137 dObj.setChangedFromUI(false); 138 } 139 } 140 } 141 142 } 143 | Popular Tags |