1 19 20 package org.netbeans.modules.j2ee.ddloaders.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.common.SecurityRole; 23 import org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor; 24 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 25 import org.netbeans.modules.j2ee.ddloaders.web.multiview.EjbRefsTablePanel; 26 import org.netbeans.modules.j2ee.ddloaders.web.multiview.SecurityRolePanel; 27 import org.netbeans.modules.j2ee.ddloaders.web.multiview.SecurityRoleTablePanel; 28 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer; 29 import org.netbeans.modules.xml.multiview.ui.EditDialog; 30 import org.openide.util.NbBundle; 31 32 37 public class EjbJarSecurityRolesTableModel extends InnerTableModel { 38 private static final String [] COLUMN_NAMES = {Utils.getBundleMessage("LBL_RoleName"), 39 Utils.getBundleMessage("LBL_Description")}; 40 41 private static final int[] COLUMN_WIDTHS = new int[]{170, 250}; 42 43 private AssemblyDescriptor assemblyDesc; 44 45 private EjbJar ejbJar; 46 47 public EjbJarSecurityRolesTableModel(XmlMultiViewDataSynchronizer synchronizer, 48 EjbJar ejbJar) { 49 super(synchronizer, COLUMN_NAMES, COLUMN_WIDTHS); 50 51 this.ejbJar = ejbJar; 52 this.assemblyDesc = ejbJar.getSingleAssemblyDescriptor(); 53 } 54 55 public void setValueAt(Object value, int rowIndex, int columnIndex) { 56 SecurityRole role = assemblyDesc.getSecurityRole(rowIndex); 57 58 switch (columnIndex) { 59 case 0: 60 role.setRoleName((String ) value); 61 break; 62 case 1: 63 role.setDescription((String ) value); 64 break; 65 } 66 67 modelUpdatedFromUI(); 68 fireTableCellUpdated(rowIndex, columnIndex); 69 } 70 71 public int getRowCount() { 72 if (assemblyDesc == null) return 0; 73 74 return assemblyDesc.getSecurityRole().length; 75 } 76 77 public Object getValueAt(int rowIndex, int columnIndex) { 78 SecurityRole role = assemblyDesc.getSecurityRole(rowIndex); 79 80 switch (columnIndex) { 81 case 0: 82 return role.getRoleName(); 83 case 1: 84 return role.getDefaultDescription(); 85 } 86 87 return null; 88 } 89 90 public int addRow() { 91 92 if (assemblyDesc == null) { 93 assemblyDesc = getAssemblyDesc(); 94 } 95 96 final SecurityRolePanel dialogPanel = new SecurityRolePanel(); 97 final String currentRoleName = null; 98 99 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(EjbRefsTablePanel.class,"TTL_SecurityRole"), true) { 100 protected String validate() { 101 String name = dialogPanel.getRoleName().trim(); 102 103 if (name.length()==0) { 104 return NbBundle.getMessage(SecurityRoleTablePanel.class,"TXT_EmptySecurityRoleName"); 105 } else { 106 SecurityRole[] roles = assemblyDesc.getSecurityRole(); 107 boolean exists=false; 108 109 for (int i = 0; i < roles.length; i++) { 110 if (name.equals(roles[i].getRoleName())){ 111 return NbBundle.getMessage(SecurityRoleTablePanel.class,"TXT_SecurityRoleNameExists",name); 112 } 113 } 114 } 115 116 return null; 117 } 118 }; 119 dialog.setValid(false); 120 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 121 dialogPanel.getRoleNameTF().getDocument().addDocumentListener(docListener); 122 dialogPanel.getDescriptionTA().getDocument().addDocumentListener(docListener); 123 124 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 125 d.setVisible(true); 126 127 dialogPanel.getRoleNameTF().getDocument().removeDocumentListener(docListener); 128 dialogPanel.getDescriptionTA().getDocument().removeDocumentListener(docListener); 129 130 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 131 SecurityRole role = assemblyDesc.newSecurityRole(); 132 role.setRoleName(dialogPanel.getRoleName()); 133 role.setDescription(dialogPanel.getDescription()); 134 assemblyDesc.addSecurityRole(role); 135 modelUpdatedFromUI(); 136 } 137 138 return getRowCount() - 1; 139 } 140 141 142 143 144 public void removeRow(final int row) { 145 SecurityRole role = assemblyDesc.getSecurityRole(row); 146 assemblyDesc.removeSecurityRole(role); 147 148 modelUpdatedFromUI(); 149 } 150 151 private AssemblyDescriptor getAssemblyDesc() { 152 AssemblyDescriptor assemblyDesc = ejbJar.getSingleAssemblyDescriptor(); 153 154 if (assemblyDesc == null) { 155 assemblyDesc = ejbJar.newAssemblyDescriptor(); 156 ejbJar.setAssemblyDescriptor(assemblyDesc); 157 } 158 159 return assemblyDesc; 160 } 161 } 162 | Popular Tags |