1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 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.openide.util.NbBundle; 28 29 36 public class SecurityRoleRefTableModel extends DDBeanTableModel{ 37 38 private WebApp webApp; 39 40 private static final String [] columnNames = { 41 NbBundle.getMessage(SecurityRoleRefTableModel.class, "TTL_SecurityRoleRefName"), 42 NbBundle.getMessage(SecurityRoleRefTableModel.class, "TTL_SecurityRoleRefLink"), 43 NbBundle.getMessage(SecurityRoleRefTableModel.class, "TTL_SecurityRoleRefDescription") 44 }; 45 46 protected String [] getColumnNames() { 47 return columnNames; 48 } 49 50 public void setWebApp(WebApp webApp) { 51 this.webApp = webApp; 52 } 53 54 public void setValueAt(Object value, int row, int column) { 55 SecurityRoleRef roleRef = getSecurityRoleRef(row); 56 57 if (column == 0) { 58 roleRef.setRoleName((String ) value); 59 } else if (column == 1) { 60 roleRef.setRoleLink((String ) value); 61 } else if (column == 2) { 62 roleRef.setDescription((String ) value); 63 } 64 } 65 66 67 public Object getValueAt(int row, int column) { 68 SecurityRoleRef roleRef = getSecurityRoleRef(row); 69 70 if (column == 0) { 71 return roleRef.getRoleName(); 72 } else if (column == 1) { 73 return roleRef.getRoleLink(); 74 } else if (column == 2) { 75 return roleRef.getDefaultDescription(); 76 } 77 78 return null; 79 } 80 81 public CommonDDBean addRow(Object [] values) { 82 try { 83 SecurityRoleRef roleRef = (SecurityRoleRef) webApp.createBean("SecurityRoleRef"); roleRef.setRoleName((String ) values[0]); 85 roleRef.setRoleLink((String ) values[1]); 86 roleRef.setDescription((String ) values[2]); 87 88 Servlet servlet = (Servlet) getParent(); 89 int row = servlet.sizeSecurityRoleRef(); 90 servlet.addSecurityRoleRef(roleRef); 91 getChildren().add(row, roleRef); 92 fireTableRowsInserted(row, row); 93 94 return roleRef; 95 } catch (ClassNotFoundException ex) { 96 } 97 98 return null; 99 } 100 101 public void editRow(int row, Object [] values) { 102 SecurityRoleRef roleRef = getSecurityRoleRef(row); 104 roleRef.setRoleName((String ) values[0]); 105 roleRef.setRoleLink((String ) values[1]); 106 roleRef.setDescription((String ) values[2]); 107 108 fireTableRowsUpdated(row,row); 109 } 110 111 public void removeRow(int row) { 112 Servlet servlet = (Servlet) getParent(); 113 SecurityRoleRef role = getSecurityRoleRef(row); 114 servlet.removeSecurityRoleRef(role); 115 116 getChildren().remove(row); 117 fireTableRowsDeleted(row, row); 118 } 119 120 SecurityRoleRef getSecurityRoleRef(int row) { 121 return (SecurityRoleRef) getChildren().get(row); 122 } 123 } 124 | Popular Tags |