KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > ui > ReferencesTableModel


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 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui;
20
21 // Netbeans
22
import java.util.List JavaDoc;
23 import org.netbeans.modules.j2ee.websphere6.dd.beans.DDXmiConstants;
24 import org.netbeans.modules.j2ee.websphere6.dd.beans.EjbBindingsType;
25 import org.netbeans.modules.j2ee.websphere6.dd.beans.EjbRefBindingsType;
26 import org.netbeans.modules.j2ee.websphere6.dd.beans.ResEnvRefBindingsType;
27 import org.netbeans.modules.j2ee.websphere6.dd.beans.ResRefBindingsType;
28 import org.netbeans.modules.j2ee.websphere6.dd.beans.CommonRef;
29 import org.openide.util.NbBundle;
30 import org.netbeans.modules.schema2beans.*;
31 import org.netbeans.modules.xml.multiview.*;
32
33 public class ReferencesTableModel extends org.netbeans.modules.j2ee.websphere6.dd.loaders.ui.InnerTableModel implements DDXmiConstants {
34     
35     private List JavaDoc children;
36     private BaseBean parent;
37     private String JavaDoc hrefType=WEB_APPLICATION;
38     private static final String JavaDoc[] columnNames = {
39         NbBundle.getMessage(ReferencesTableModel.class,"TTL_ReferenceType"),
40         NbBundle.getMessage(ReferencesTableModel.class,"TTL_ReferenceId"),
41         NbBundle.getMessage(ReferencesTableModel.class,"TTL_ReferenceJndiName"),
42         NbBundle.getMessage(ReferencesTableModel.class,"TTL_ReferenceHref")
43     };
44     
45     private static final int [] columnWidths= {200, 160, 180};
46     
47     public ReferencesTableModel(XmlMultiViewDataSynchronizer synchronizer) {
48         super(synchronizer,columnNames,columnWidths);
49     }
50     
51     
52     
53     protected String JavaDoc[] getColumnNames() {
54         return columnNames;
55     }
56     
57     protected BaseBean getParent() {
58         return parent;
59     }
60     
61     protected List JavaDoc getChildren() {
62         return children;
63     }
64     public void setHrefType(String JavaDoc value) {
65         hrefType=value;
66     }
67     public String JavaDoc getHrefType(String JavaDoc value) {
68         return hrefType;
69     }
70     public int getColumnCount() {
71         return getColumnNames().length;
72     }
73     
74     public int getRowCount() {
75         if (children != null) {
76             return (children.size());
77         } else {
78             return (0);
79         }
80     }
81     
82     
83     public String JavaDoc getColumnName(int column) {
84         return getColumnNames()[column];
85     }
86     
87     public boolean isCellEditable(int row, int column) {
88         return (false);
89     }
90     
91     public int getRowWithValue(int column, Object JavaDoc value) {
92         for(int row = 0; row < getRowCount(); row++) {
93             Object JavaDoc obj = getValueAt(row, column);
94             if (obj.equals(value)) {
95                 return (row);
96             }
97         }
98         
99         return (-1);
100     }
101     
102     
103     
104     public void setData(BaseBean parent,BaseBean[] children) {
105         this.parent = parent;
106         this.children = new java.util.ArrayList JavaDoc();
107         if (children==null) return;
108         for(int i=0;i<children.length;i++)
109             this.children.add(children[i]);
110         fireTableDataChanged();
111     }
112     
113     
114     public void setValueAt(Object JavaDoc value, int row, int column) {
115         CommonRef ref = (CommonRef)getChildren().get(row);
116         
117         if (column == 0) ;//ref.setXmiId((String)value);
118
else if (column == 1) ref.setXmiId((String JavaDoc)value);
119         else if(column==2) ref.setJndiName((String JavaDoc)value);
120         else if(column==3) ref.setHref((String JavaDoc)value);
121     }
122     
123     
124     public Object JavaDoc getValueAt(int row, int column) {
125         CommonRef ref = (CommonRef)getChildren().get(row);
126         if (column == 0) return ref.getType();
127         else if (column == 1) return ref.getXmiId();
128         else if(column == 2) return ref.getJndiName();
129         else if(column == 3) return ref.getHref();
130         return null;
131     }
132     
133     public BaseBean addRow(Object JavaDoc[] values) {
134         //try {
135
String JavaDoc type=(String JavaDoc)values[0];
136         CommonRef ref;
137         if(type.equals(BINDING_REFERENCE_TYPE_RESOURCE)) {
138             ref = new ResRefBindingsType(hrefType);
139         } else if(type.equals(BINDING_REFERENCE_TYPE_RESOURCE_ENV)) {
140             ref = new ResEnvRefBindingsType(hrefType);
141         } else if(type.equals(BINDING_REFERENCE_TYPE_EJB)) {
142             ref = new EjbRefBindingsType(hrefType);
143         } else {
144             return null;
145         }
146         ref.setXmiId((String JavaDoc)values[1]);
147         ref.setJndiName((String JavaDoc)values[2]);
148         ref.setHref((String JavaDoc)values[3]);
149         ((EjbBindingsType)getParent()).addReferenceBinding(ref);
150         getChildren().add(ref);
151         fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
152         return ref;
153         //} //catch (ClassNotFoundException ex) {}
154

155         //return null;
156
}
157     
158     public int addRow() {
159         return -1;
160     }
161     
162     
163     public void editRow(int row, Object JavaDoc[] values) {
164         CommonRef ref = (CommonRef)getChildren().get(row);
165         ref.setXmiId((String JavaDoc)values[1]);
166         ref.setJndiName((String JavaDoc)values[2]);
167         ref.setHref((String JavaDoc)values[3]);
168         fireTableRowsUpdated(row,row);
169     }
170     
171     public void removeRow(int row) {
172         ((EjbBindingsType)getParent()).removeReferenceBinding((CommonRef)getChildren().get(row));
173         getChildren().remove(row);
174         fireTableRowsDeleted(row, row);
175         
176     }
177 }
Popular Tags