KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** ResRefTableModel - table model for resource references
23  *
24  * Created on April 11, 2005
25  * @author mkuchtiak
26  */

27 import org.netbeans.modules.j2ee.dd.api.common.ResourceRef;
28 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
29 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
30 import org.openide.util.NbBundle;
31
32 public class ResRefTableModel extends DDBeanTableModel
33 {
34     private static final String JavaDoc[] columnNames = {
35             NbBundle.getMessage(ResRefTableModel.class,"TTL_ResRefName"),
36             NbBundle.getMessage(ResRefTableModel.class,"TTL_ResType"),
37             NbBundle.getMessage(ResRefTableModel.class,"TTL_ResAuth"),
38             NbBundle.getMessage(ResRefTableModel.class,"TTL_ResSharingScope"),
39             NbBundle.getMessage(ResRefTableModel.class,"TTL_Description")
40         };
41
42         protected String JavaDoc[] getColumnNames() {
43             return columnNames;
44         }
45
46     public void setValueAt(Object JavaDoc value, int row, int column)
47     {
48         ResourceRef param = getResourceRef(row);
49
50         if (column == 0) param.setResRefName((String JavaDoc)value);
51         else if (column == 1) param.setResType((String JavaDoc)value);
52         else if (column == 2) param.setResAuth((String JavaDoc)value);
53                 else if (column == 3) param.setResSharingScope((String JavaDoc)value);
54         else param.setDescription((String JavaDoc)value);
55     }
56
57
58     public Object JavaDoc getValueAt(int row, int column)
59     {
60         ResourceRef param = getResourceRef(row);
61
62         if (column == 0) return param.getResRefName();
63         else if (column == 1) return param.getResType();
64         else if (column == 2) return param.getResAuth();
65                 else if (column == 3) {
66                     String JavaDoc scope = param.getResSharingScope();
67                     return ("Unshareable".equals(scope)?scope:"Shareable"); //NOI18N
68
}
69         else {
70                     String JavaDoc desc = param.getDefaultDescription();
71                     return desc==null?null:desc.trim();
72                 }
73     }
74         
75     public CommonDDBean addRow(Object JavaDoc[] values)
76     {
77             try {
78                 WebApp webApp = (WebApp)getParent();
79                 ResourceRef param=(ResourceRef)webApp.createBean("ResourceRef"); //NOI18N
80
param.setResRefName((String JavaDoc)values[0]);
81                 param.setResType((String JavaDoc)values[1]);
82                 param.setResAuth((String JavaDoc)values[2]);
83                 param.setResSharingScope((String JavaDoc)values[3]);
84                 String JavaDoc desc = (String JavaDoc)values[4];
85                 param.setDescription(desc.length()>0?desc:null);
86                 webApp.addResourceRef(param);
87                 getChildren().add(param);
88                 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
89                 return param;
90             } catch (ClassNotFoundException JavaDoc ex) {}
91             return null;
92     }
93
94     public void editRow(int row, Object JavaDoc[] values)
95     {
96                 ResourceRef param = getResourceRef(row);
97                 param.setResRefName((String JavaDoc)values[0]);
98                 param.setResType((String JavaDoc)values[1]);
99                 param.setResAuth((String JavaDoc)values[2]);
100                 String JavaDoc scope = (String JavaDoc)values[3];
101                 String JavaDoc oldScope = param.getResSharingScope();
102                 if (oldScope==null && "Unshareable".equals(scope)) param.setResSharingScope(scope); //NOI18N
103
else if (!oldScope.equals(scope)) param.setResSharingScope(scope);
104                 String JavaDoc desc = (String JavaDoc)values[4];
105                 param.setDescription(desc.length()>0?desc:null);
106                 fireTableRowsUpdated(row,row);
107     }
108         
109     public void removeRow(int row)
110     {
111             WebApp webApp = (WebApp)getParent();
112             webApp.removeResourceRef(getResourceRef(row));
113             getChildren().remove(row);
114             fireTableRowsDeleted(row, row);
115             
116     }
117         
118         ResourceRef getResourceRef(int row) {
119             return (ResourceRef)getChildren().get(row);
120         }
121 }
Popular Tags