KickJava   Java API By Example, From Geeks To Geeks.

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


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.common.InitParam;
24 import org.netbeans.modules.j2ee.dd.api.web.Servlet;
25 import org.netbeans.modules.j2ee.dd.api.web.Filter;
26 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
27 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
28 import org.openide.util.NbBundle;
29
30 public class InitParamTableModel extends DDBeanTableModel
31 {
32     private static final String JavaDoc[] columnNames = {
33             NbBundle.getMessage(InitParamTableModel.class,"TTL_InitParamName"),
34             NbBundle.getMessage(InitParamTableModel.class,"TTL_InitParamValue"),
35             NbBundle.getMessage(InitParamTableModel.class,"TTL_Description")
36         };
37
38         protected String JavaDoc[] getColumnNames() {
39             return columnNames;
40         }
41
42     public void setValueAt(Object JavaDoc value, int row, int column)
43     {
44         InitParam param = (InitParam)getChildren().get(row);
45
46         if (column == 0) param.setParamName((String JavaDoc)value);
47         else if (column == 1) param.setParamValue((String JavaDoc)value);
48         else param.setDescription((String JavaDoc)value);
49     }
50
51
52     public Object JavaDoc getValueAt(int row, int column)
53     {
54         InitParam param = (InitParam)getChildren().get(row);
55
56         if (column == 0) return param.getParamName();
57         else if (column == 1) return param.getParamValue();
58         else {
59                     String JavaDoc desc = param.getDefaultDescription();
60                     return (desc==null?null:desc.trim());
61                 }
62     }
63         
64     public CommonDDBean addRow(Object JavaDoc[] values)
65     {
66             try {
67                 Object JavaDoc parent = getParent();
68                 InitParam param=null;
69                 if (parent instanceof Servlet)
70                     param = (InitParam)((Servlet)parent).createBean("InitParam"); //NOI18N
71
else if (parent instanceof Filter)
72                     param = (InitParam)((Filter)parent).createBean("InitParam"); //NOI18N
73
else
74                     param = (InitParam)((WebApp)parent).createBean("InitParam"); //NOI18N
75
param.setParamName((String JavaDoc)values[0]);
76                 param.setParamValue((String JavaDoc)values[1]);
77                 String JavaDoc desc = (String JavaDoc)values[2];
78                 if (desc.length()>0) param.setDescription(desc);
79                 if (parent instanceof Servlet)
80                     ((Servlet)parent).addInitParam(param);
81                 else if (parent instanceof Filter)
82                     ((Filter)parent).addInitParam(param);
83                 else
84                     ((WebApp)parent).addContextParam(param);
85                 getChildren().add(param);
86                 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
87                 return param;
88             } catch (ClassNotFoundException JavaDoc ex) {}
89             return null;
90     }
91
92
93     public void editRow(int row, Object JavaDoc[] values)
94     {
95                 InitParam param = (InitParam)getChildren().get(row);
96         param.setParamName((String JavaDoc)values[0]);
97                 param.setParamValue((String JavaDoc)values[1]);
98                 String JavaDoc desc=(String JavaDoc)values[2];
99                 if (desc.length()>0) param.setDescription(desc);
100                 fireTableRowsUpdated(row,row);
101     }
102         
103     public void removeRow(int row)
104     {
105             Object JavaDoc parent = getParent();
106             if (parent instanceof Servlet)
107                 ((Servlet)parent).removeInitParam((InitParam)getChildren().get(row));
108             else if (parent instanceof Filter)
109                 ((Filter)parent).removeInitParam((InitParam)getChildren().get(row));
110             else
111                 ((WebApp)parent).removeContextParam((InitParam)getChildren().get(row));
112             getChildren().remove(row);
113             fireTableRowsDeleted(row, row);
114             
115     }
116 }
Popular Tags