KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.StringTokenizer JavaDoc;
23 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
24 import org.netbeans.modules.j2ee.dd.api.web.SecurityConstraint;
25 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
26 import org.netbeans.modules.j2ee.dd.api.web.WebResourceCollection;
27 import org.openide.util.NbBundle;
28
29 /**
30  * WebResourceCollectionTableModel.java
31  *
32  * Table model for WebResourceCollectionTablePanel.
33  *
34  * @author ptliu
35  */

36 public class WebResourceCollectionTableModel extends DDBeanTableModel {
37     private WebApp webApp;
38     
39     private static final String JavaDoc[] columnNames = {
40         NbBundle.getMessage(SecurityRoleTableModel.class, "TTL_WebResourceCollectionName"),
41         NbBundle.getMessage(SecurityRoleTableModel.class, "TTL_WebResourceCollectionUrlPattern"),
42         NbBundle.getMessage(SecurityRoleTableModel.class, "TTL_WebResourceCollectionHttpMethod"),
43         NbBundle.getMessage(SecurityRoleTableModel.class, "TTL_WebResourceCollectionDescription")
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
55     public void setValueAt(Object JavaDoc value, int row, int column) {
56         WebResourceCollection col = getWebResourceCollection(row);
57         
58         if (column == 0) {
59             col.setWebResourceName((String JavaDoc) value);
60         } else if (column == 1) {
61             col.setUrlPattern((String JavaDoc[]) value);
62         } else if (column == 2) {
63             col.setHttpMethod((String JavaDoc[]) value);
64         } else if (column == 3) {
65             col.setDescription((String JavaDoc) value);
66         }
67     }
68  
69     public Object JavaDoc getValueAt(int row, int column) {
70         WebResourceCollection col = getWebResourceCollection(row);
71         
72         if (column == 0) {
73             return col.getWebResourceName();
74         } else if (column == 1) {
75             return getCommaSeparatedString(col.getUrlPattern());
76         } else if (column == 2) {
77             return getCommaSeparatedString(col.getHttpMethod());
78         } else if (column == 3) {
79             return col.getDefaultDescription();
80         }
81         
82         return null;
83     }
84     
85     static String JavaDoc getCommaSeparatedString(String JavaDoc[] values) {
86         String JavaDoc result = ""; //NOI18N
87

88         for (int i = 0; i < values.length; i++) {
89             if (i > 0) {
90                 result += ", "; //NOI18N
91
}
92             
93             result += values[i];
94         }
95  
96         return result;
97     }
98     
99     public CommonDDBean addRow(Object JavaDoc[] values) {
100         try {
101             SecurityConstraint constraint = (SecurityConstraint) getParent();
102             WebResourceCollection col = (WebResourceCollection) webApp.createBean("WebResourceCollection"); //NOI18N
103
col.setWebResourceName((String JavaDoc) values[0]);
104             col.setUrlPattern((String JavaDoc[]) values[1]);
105             col.setHttpMethod((String JavaDoc[]) values[2]);
106             col.setDescription((String JavaDoc) values[3]);
107             
108             int row = constraint.sizeWebResourceCollection();
109             constraint.addWebResourceCollection(col);
110             getChildren().add(row, col);
111             fireTableRowsInserted(row, row);
112             
113             return col;
114         } catch (ClassNotFoundException JavaDoc ex) {
115         }
116         
117         return null;
118     }
119     
120   
121     public void editRow(int row, Object JavaDoc[] values) {
122         WebResourceCollection col = getWebResourceCollection(row);
123         col.setWebResourceName((String JavaDoc) values[0]);
124         col.setUrlPattern((String JavaDoc[]) values[1]);
125         col.setHttpMethod((String JavaDoc[]) values[2]);
126         col.setDescription((String JavaDoc) values[3]);
127     
128         fireTableRowsUpdated(row,row);
129     }
130     
131     public void removeRow(int row) {
132         SecurityConstraint constraint = (SecurityConstraint) getParent();
133         WebResourceCollection col = getWebResourceCollection(row);
134         constraint.removeWebResourceCollection(col);
135         
136         getChildren().remove(row);
137         fireTableRowsDeleted(row, row);
138     }
139     
140     WebResourceCollection getWebResourceCollection(int row) {
141         return (WebResourceCollection) getChildren().get(row);
142     }
143 }
144
Popular Tags