KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
30  * SecurityRoleRefTableModel.java
31  *
32  * Table model for the SecurityRoleRefTablePanel.
33  *
34  * @author ptliu
35  */

36 public class SecurityRoleRefTableModel extends DDBeanTableModel{
37      
38     private WebApp webApp;
39     
40     private static final String JavaDoc[] 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 JavaDoc[] getColumnNames() {
47         return columnNames;
48     }
49     
50     public void setWebApp(WebApp webApp) {
51         this.webApp = webApp;
52     }
53     
54     public void setValueAt(Object JavaDoc value, int row, int column) {
55         SecurityRoleRef roleRef = getSecurityRoleRef(row);
56         
57         if (column == 0) {
58             roleRef.setRoleName((String JavaDoc) value);
59         } else if (column == 1) {
60             roleRef.setRoleLink((String JavaDoc) value);
61         } else if (column == 2) {
62             roleRef.setDescription((String JavaDoc) value);
63         }
64     }
65     
66     
67     public Object JavaDoc 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 JavaDoc[] values) {
82         try {
83             SecurityRoleRef roleRef = (SecurityRoleRef) webApp.createBean("SecurityRoleRef"); //NOI18N
84
roleRef.setRoleName((String JavaDoc) values[0]);
85             roleRef.setRoleLink((String JavaDoc) values[1]);
86             roleRef.setDescription((String JavaDoc) 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 JavaDoc ex) {
96         }
97         
98         return null;
99     }
100     
101     public void editRow(int row, Object JavaDoc[] values) {
102         //try {
103
SecurityRoleRef roleRef = getSecurityRoleRef(row);
104         roleRef.setRoleName((String JavaDoc) values[0]);
105         roleRef.setRoleLink((String JavaDoc) values[1]);
106         roleRef.setDescription((String JavaDoc) 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