KickJava   Java API By Example, From Geeks To Geeks.

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


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

146         //return null;
147
}
148     
149     public int addRow() {
150         return -1;
151     }
152     
153     
154     public void editRow(int row, Object JavaDoc[] values) {
155         ModuleExtensionsType moduleExtension = (ModuleExtensionsType)getChildren().get(row);
156         moduleExtension.setXmiId((String JavaDoc)values[0]);
157         moduleExtension.setHref((String JavaDoc)values[1]);
158         moduleExtension.setAltRoot((String JavaDoc)values[2]);
159         moduleExtension.setAltBindings((String JavaDoc)values[3]);
160         moduleExtension.setAltExtensions((String JavaDoc)values[4]);
161         moduleExtension.setType((String JavaDoc)values[5]);
162         fireTableRowsUpdated(row,row);
163     }
164     
165     public void removeRow(int row) {
166         ((WSAppExt)getParent()).removeModuleExtensions((ModuleExtensionsType)getChildren().get(row));
167         getChildren().remove(row);
168         fireTableRowsDeleted(row, row);
169         
170     }
171 }
Popular Tags