KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > webapp > CacheMappingTableModel


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  * CacheMappingTableModel.java
21  *
22  * Created on January 12, 2004, 6:51 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.ResourceBundle JavaDoc;
30
31 import javax.swing.table.AbstractTableModel JavaDoc;
32 import javax.swing.event.EventListenerList JavaDoc;
33
34 import org.netbeans.modules.j2ee.sun.dd.api.web.CacheMapping;
35 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
36
37 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory;
38
39
40 /**
41  *
42  * @author Peter Williams
43  */

44 public class CacheMappingTableModel extends AbstractTableModel JavaDoc {
45     
46     private static final ResourceBundle JavaDoc webappBundle = ResourceBundle.getBundle(
47         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); // NOI18N
48

49     private static final String JavaDoc [] columnNames = {
50         webappBundle.getString("LBL_CacheTarget"), // NOI18N
51
webappBundle.getString("LBL_TargetValue"), // NOI18N
52
webappBundle.getString("LBL_CacheReference"), // NOI18N
53
webappBundle.getString("LBL_ReferenceValue"), // NOI18N
54
};
55     
56     private static final String JavaDoc [] cacheTargetType = {
57         webappBundle.getString("LBL_ServletName"), // NOI18N
58
webappBundle.getString("LBL_URLPattern"), // NOI18N
59
};
60     
61     private static final String JavaDoc [] cacheReferenceType = {
62         webappBundle.getString("LBL_CacheHelperReference"), // NOI18N
63
webappBundle.getString("LBL_CachePolicyDefinition"), // NOI18N
64
};
65
66     /** List of listeners */
67     protected EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
68
69     /** List of CacheMapping objects */
70     private List JavaDoc rows;
71     
72     /** Application Server version for selected data */
73     private ASDDVersion appServerVersion;
74
75     public CacheMappingTableModel() {
76         rows = new ArrayList JavaDoc();
77     }
78
79     /* --------------------------------------------------------------------
80      * Data manipulation
81      */

82     public int addRow() {
83         rows.add(StorageBeanFactory.getStorageBeanFactory(appServerVersion).createCacheMapping_NoDefaults());
84         int newIndex = rows.size()-1;
85         fireTableRowsInserted(newIndex, newIndex);
86         return newIndex;
87     }
88
89     public CacheMapping removeRow(int rowIndex) {
90         CacheMapping removedMapping = null;
91         
92         if(rowIndex >= 0 && rowIndex < rows.size()) {
93             removedMapping = (CacheMapping) rows.remove(rowIndex);
94             fireTableRowsDeleted(rowIndex, rowIndex);
95         }
96         
97         return removedMapping;
98     }
99     
100     public void setData(List JavaDoc data, ASDDVersion asVersion) {
101         appServerVersion = asVersion;
102         
103         if(data != null && data.size() > 0) {
104             rows = new ArrayList JavaDoc(data);
105         } else {
106             rows = new ArrayList JavaDoc();
107         }
108     }
109     
110     public List JavaDoc getData() {
111         return rows;
112     }
113
114     /* --------------------------------------------------------------------
115      * Implementation of TableModel interface
116      */

117 // public Class getColumnClass(int columnIndex) {
118
// return String.class;
119
// }
120

121     public String JavaDoc getColumnName(int columnIndex) {
122         assert(columnIndex >= 0 && columnIndex < 4);
123         return columnNames[columnIndex];
124     }
125
126     public int getColumnCount() {
127         return 4;
128     }
129
130     public int getRowCount() {
131 // return (rows != null) ? rows.size() : 0;
132
return rows.size();
133     }
134
135     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
136         Object JavaDoc result = null;
137
138 // if(rows != null && rowIndex >= 0 && rowIndex < rows.size() && columnIndex >= 0 && columnIndex < 4) {
139
if(rowIndex >= 0 && rowIndex < rows.size() && columnIndex >= 0 && columnIndex < 4) {
140             CacheMapping mapping = (CacheMapping) rows.get(rowIndex);
141             if(columnIndex < 2) {
142                 // cache target
143
String JavaDoc servletName = mapping.getServletName();
144                 String JavaDoc urlPattern = mapping.getUrlPattern();
145                 if(columnIndex == 0) {
146                     result = (servletName != null) ? cacheTargetType[0] : cacheTargetType[1];
147                 } else {
148                     result = (servletName != null) ? servletName : urlPattern;
149                 }
150             } else {
151                 // cache reference
152
String JavaDoc helperRef = mapping.getCacheHelperRef();
153                 if(columnIndex == 2) {
154                     result = (helperRef != null) ? cacheReferenceType[0] : cacheReferenceType[1];
155                 } else {
156                     result = (helperRef != null) ? helperRef : webappBundle.getString("LBL_PolicyLabel"); // NOI18N
157
}
158             }
159         }
160
161         return result;
162     }
163 }
164
Popular Tags