KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > SecurityMappingTableModel


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  * GroupTableModel.java
21  *
22  * Created on April 14, 2006, 10:29 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.j2ee.sun.share.configbean.customizers;
29
30 import java.util.Collections JavaDoc;
31 import java.util.List JavaDoc;
32
33 import javax.swing.table.AbstractTableModel JavaDoc;
34
35
36 /**
37  *
38  * @author Peter Williams
39  */

40 public abstract class SecurityMappingTableModel extends AbstractTableModel JavaDoc {
41     
42     /** Number of columns in table.
43      */

44     private final int numColumns;
45     
46     /** List of some type of Object.
47      */

48     private final List JavaDoc itemList;
49     
50     protected SecurityMappingTableModel(List JavaDoc p, int columns) {
51         assert p != null;
52         
53         itemList = p;
54         numColumns = columns;
55     }
56
57     /** Model manipulation
58      */

59     protected int addElement(Object JavaDoc entry) {
60         itemList.add(entry);
61         int index = itemList.size();
62         fireTableRowsInserted(index, index);
63         return index;
64     }
65     
66     protected int replaceElement(Object JavaDoc oldEntry, Object JavaDoc newEntry) {
67         int index = itemList.indexOf(oldEntry);
68         if(index != -1) {
69             itemList.set(index, newEntry);
70             fireTableRowsUpdated(index, index);
71         }
72         return index;
73     }
74     
75     protected int removeElement(Object JavaDoc entry) {
76         int index = itemList.indexOf(entry);
77         if(index != -1) {
78             itemList.remove(index);
79 // fireTableRowsDeleted(index, index);
80
fireTableDataChanged();
81         }
82         return index;
83     }
84     
85     public void removeElementAt(int index) {
86         if(index >= 0 || index < itemList.size()) {
87             itemList.remove(index);
88 // fireTableRowsDeleted(index, index);
89
fireTableDataChanged();
90         }
91     }
92     
93     public void removeElements(int[] indices) {
94         // !PW FIXME this method has an unwritten requirement that the
95
// list of indices passed in is ordered in ascending numerical order.
96
if(indices.length > 0) {
97             for(int i = indices.length-1; i >= 0; i--) {
98                 if(indices[i] >= 0 || indices[i] < itemList.size()) {
99                     itemList.remove(indices[i]);
100                 }
101             }
102 // fireTableRowsUpdated(indices[0], indices[indices.length-1]);
103
fireTableDataChanged();
104         }
105     }
106     
107     protected boolean contains(Object JavaDoc entry) {
108         return itemList.contains(entry);
109     }
110     
111     protected Object JavaDoc getRowElement(int rowIndex) {
112         Object JavaDoc result = null;
113         if(rowIndex >= 0 && rowIndex < itemList.size()) {
114             result = itemList.get(rowIndex);
115         }
116         return result;
117     }
118     
119     /** TableModel interface methods
120      */

121     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
122         Object JavaDoc result = null;
123         if(rowIndex >= 0 && rowIndex < itemList.size() && columnIndex >= 0 && columnIndex < numColumns) {
124             result = getColumnValueFromRow(itemList.get(rowIndex), columnIndex);
125         }
126         return result;
127     }
128     
129     public int getRowCount() {
130         return itemList.size();
131     }
132
133     public int getColumnCount() {
134         return numColumns;
135     }
136
137     public abstract String JavaDoc getColumnName(int column);
138
139     /** SecurityMappingTableModel methods
140      */

141     /** This method is passed the entry for a given row and returns the value
142      * of the specified colum element within that row. Used by superclass to
143      * implement getValueAt(). columnIndex has already been range checked, but
144      * rowEntry could be null if this table allows null values.
145      */

146     protected abstract Object JavaDoc getColumnValueFromRow(Object JavaDoc rowEntry, int columnIndex);
147
148 }
149
Popular Tags