KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > multiview > SecurityRoleTableModel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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.EjbLocalRef;
24 import org.netbeans.modules.j2ee.dd.api.common.EjbRef;
25 import org.netbeans.modules.j2ee.dd.api.common.SecurityRole;
26 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
27 import org.openide.util.NbBundle;
28
29 /**
30  * SecurityRoleTableModel.java
31  *
32  * Table model SecurityRoleTablePanel.
33  *
34  * @author ptliu
35  */

36 public class SecurityRoleTableModel extends DDBeanTableModel {
37     
38     private static final String JavaDoc[] columnNames = {
39         NbBundle.getMessage(SecurityRoleTableModel.class, "TTL_SecurityRoleName"),
40         NbBundle.getMessage(SecurityRoleTableModel.class, "TTL_SecurityRoleDescription")
41     };
42     
43     protected String JavaDoc[] getColumnNames() {
44         return columnNames;
45     }
46     
47     public void setValueAt(Object JavaDoc value, int row, int column) {
48         SecurityRole role = getSecurityRole(row);
49         
50         if (column == 0) {
51             role.setRoleName((String JavaDoc) value);
52         } else if (column == 1) {
53             role.setDescription((String JavaDoc) value);
54         }
55     }
56     
57     
58     public Object JavaDoc getValueAt(int row, int column) {
59         SecurityRole role = getSecurityRole(row);
60         
61         if (column == 0) {
62             return role.getRoleName();
63         } else if (column == 1) {
64             return role.getDefaultDescription();
65         }
66         
67         return null;
68     }
69     
70     public CommonDDBean addRow(Object JavaDoc[] values) {
71         try {
72             WebApp webApp = (WebApp)getParent();
73             SecurityRole role = (SecurityRole) webApp.createBean("SecurityRole"); //NOI18N
74
role.setRoleName((String JavaDoc) values[0]);
75             role.setDescription((String JavaDoc) values[1]);
76             
77             int row = webApp.sizeSecurityRole();
78             webApp.addSecurityRole(role);
79             getChildren().add(row, role);
80             fireTableRowsInserted(row, row);
81             
82             return role;
83         } catch (ClassNotFoundException JavaDoc ex) {
84         }
85         
86         return null;
87     }
88     
89     public void editRow(int row, Object JavaDoc[] values) {
90         //try {
91
SecurityRole role = getSecurityRole(row);
92         role.setRoleName((String JavaDoc) values[0]);
93         role.setDescription((String JavaDoc) values[1]);
94         
95         fireTableRowsUpdated(row,row);
96     }
97     
98     public void removeRow(int row) {
99         WebApp webApp = (WebApp)getParent();
100         SecurityRole role = getSecurityRole(row);
101         webApp.removeSecurityRole(role);
102         
103         getChildren().remove(row);
104         fireTableRowsDeleted(row, row);
105     }
106     
107     SecurityRole getSecurityRole(int row) {
108         return (SecurityRole) getChildren().get(row);
109     }
110 }
111
Popular Tags