KickJava   Java API By Example, From Geeks To Geeks.

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


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

132         //return null;
133
}
134     
135     public int addRow() {
136         return -1;
137     }
138     
139     
140     public void editRow(int row, Object JavaDoc[] values) {
141         PageType page = (PageType)getChildren().get(row);
142         page.setXmiId((String JavaDoc)values[0]);
143         page.setName((String JavaDoc)values[1]);
144         page.setUri((String JavaDoc)values[2]);
145         fireTableRowsUpdated(row,row);
146     }
147     
148     public void removeRow(int row) {
149         ((MarkupLanguagesType)getParent()).removePages((PageType)getChildren().get(row));
150         getChildren().remove(row);
151         fireTableRowsDeleted(row, row);
152         
153     }
154 }
Popular Tags