KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** MessageDestRefTableModel - table model for message desctination references
23  *
24  * Created on April 14, 2005
25  * @author mkuchtiak
26  */

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