KickJava   Java API By Example, From Geeks To Geeks.

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


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.Listener;
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 ListenerTableModel extends DDBeanTableModel
29 {
30     private static final String JavaDoc[] columnNames = {
31             NbBundle.getMessage(ListenerTableModel.class,"TTL_ListenerClass"),
32             NbBundle.getMessage(ListenerTableModel.class,"TTL_Description")
33         };
34
35         protected String JavaDoc[] getColumnNames() {
36             return columnNames;
37         }
38
39     public void setValueAt(Object JavaDoc value, int row, int column)
40     {
41         Listener listener = (Listener)getChildren().get(row);
42
43         if (column == 0) listener.setListenerClass((String JavaDoc)value);
44         else listener.setDescription((String JavaDoc)value);
45     }
46
47
48     public Object JavaDoc getValueAt(int row, int column)
49     {
50         Listener listener = (Listener)getChildren().get(row);
51
52         if (column == 0) return listener.getListenerClass();
53         else {
54                     String JavaDoc desc = listener.getDefaultDescription();
55                     return (desc==null?null:desc.trim());
56                 }
57     }
58         
59     public CommonDDBean addRow(Object JavaDoc[] values)
60     {
61             try {
62                 Listener listener = (Listener)((WebApp)getParent()).createBean("Listener"); //NOI18N
63
listener.setListenerClass((String JavaDoc)values[0]);
64                 String JavaDoc desc = (String JavaDoc)values[1];
65                 if (desc.length()>0) listener.setDescription(desc);
66                 ((WebApp)getParent()).addListener(listener);
67                 getChildren().add(listener);
68                 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
69                 return listener;
70             } catch (ClassNotFoundException JavaDoc ex) {}
71             return null;
72     }
73
74
75     public void editRow(int row, Object JavaDoc[] values)
76     {
77                 Listener listener = (Listener)getChildren().get(row);
78         listener.setListenerClass((String JavaDoc)values[0]);
79                 String JavaDoc desc=(String JavaDoc)values[1];
80                 if (desc.length()>0) listener.setDescription(desc);
81                 fireTableRowsUpdated(row,row);
82     }
83         
84     public void removeRow(int row)
85     {
86             ((WebApp)getParent()).removeListener((Listener)getChildren().get(row));
87             getChildren().remove(row);
88             fireTableRowsDeleted(row, row);
89             
90     }
91 }
Popular Tags