KickJava   Java API By Example, From Geeks To Geeks.

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


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 // Netbeans
23
import org.netbeans.modules.j2ee.dd.api.web.FilterMapping;
24 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
25 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
26 import org.openide.util.NbBundle;
27
28 public class FilterMappingsTableModel extends DDBeanTableModel
29 {
30     private static final String JavaDoc[] columnNames = {
31             NbBundle.getMessage(FilterMappingsTableModel.class,"TTL_FilterName"),
32             NbBundle.getMessage(FilterMappingsTableModel.class,"TTL_AppliesTo"),
33             NbBundle.getMessage(FilterMappingsTableModel.class,"TTL_DispatcherTypes")
34         };
35
36         protected String JavaDoc[] getColumnNames() {
37             return columnNames;
38         }
39         /*
40     public void setValueAt(Object value, int row, int column)
41     {
42         FilterMapping map = (FilterMapping)getChildren().get(row);
43         if (column == 0) map.setFilterName((String)value);
44         else map.setDispatcher((String[])value);
45     }
46         */

47
48     public Object JavaDoc getValueAt(int row, int column)
49     {
50         FilterMapping map = (FilterMapping)getChildren().get(row);
51
52         if (column == 0) return map.getFilterName();
53         else if (column==1) {
54                     String JavaDoc urlPattern = map.getUrlPattern();
55                     return (urlPattern==null?
56                             NbBundle.getMessage(FilterMappingsTableModel.class,"TXT_appliesToServlet",map.getServletName()):
57                             NbBundle.getMessage(FilterMappingsTableModel.class,"TXT_appliesToUrl",urlPattern));
58                 } else {
59                     try {
60                         return DDUtils.urlPatternList(map.getDispatcher());
61                     } catch (org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException ex) {
62                         return null;
63                     }
64                 }
65     }
66         
67     public CommonDDBean addRow(Object JavaDoc[] values)
68     {
69             try {
70                 FilterMapping map = (FilterMapping)((WebApp)getParent()).createBean("FilterMapping"); //NOI18N
71
map.setFilterName((String JavaDoc)values[0]);
72                 if (values[1]!=null) map.setUrlPattern((String JavaDoc)values[1]);;
73                 if (values[2]!=null) map.setServletName((String JavaDoc)values[2]);
74                 try {
75                     if (values[3]!=null) map.setDispatcher((String JavaDoc[])values[3]);
76                 } catch (org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException ex) {}
77                 ((WebApp)getParent()).addFilterMapping(map);
78                 getChildren().add(map);
79                 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
80                 return map;
81             } catch (ClassNotFoundException JavaDoc ex) {}
82             return null;
83     }
84
85
86     public void editRow(int row, Object JavaDoc[] values)
87     {
88                 FilterMapping map = (FilterMapping)getChildren().get(row);
89         map.setFilterName((String JavaDoc)values[0]);
90                 map.setUrlPattern((String JavaDoc)values[1]);
91                 map.setServletName((String JavaDoc)values[2]);
92                 try {
93                     map.setDispatcher((String JavaDoc[])values[3]);
94                 } catch (org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException ex) {}
95                 fireTableRowsUpdated(row,row);
96     }
97         
98     public void removeRow(int row)
99     {
100             ((WebApp)getParent()).removeFilterMapping((FilterMapping)getChildren().get(row));
101             getChildren().remove(row);
102             fireTableRowsDeleted(row, row);
103             
104     }
105 }
Popular Tags