KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > ProductTableModel


1 package sellwin.gui;
2
3 import sellwin.domain.*;
4 import java.util.*;
5 import javax.swing.table.*;
6
7 // SellWin http://sourceforge.net/projects/sellwincrm
8
//Contact support@open-app.com for commercial help with SellWin
9
//This software is provided "AS IS", without a warranty of any kind.
10

11 /**
12  * This class represenst the product table model
13  * see the java spec for details on table models
14  * within the Swing API
15  */

16 public class ProductTableModel extends DefaultTableModel {
17     private ArrayList rows;
18     private ArrayList columnNames;
19
20     /**
21      * constructa product table model using
22      * an array of product data
23      * @param r the list of data to build the
24      * model around
25      */

26     public ProductTableModel(ArrayList r) {
27         setLang();
28         rows = r;
29     }
30
31     /**
32      * get the product list data
33      * @return the list of product this model uses
34      */

35     public final ArrayList getRows() {
36         return rows;
37     }
38
39     /**
40      * remote a row
41      * @param rowIndex row number to delete
42      */

43     public final void removeRowByIndex(int rowIndex) {
44         rows.remove(rowIndex);
45         fireTableRowsDeleted(rowIndex, rowIndex);
46     }
47
48     /**
49      * remote a row
50      */

51     public final void removeRowObject(Object JavaDoc rowObject) {
52         removeRowByIndex(rows.indexOf(rowObject));
53     }
54
55     /**
56      * set the rows to a list of objects
57      * @param r the new row data
58      */

59     public final void setRows(ArrayList r) {
60         rows = r;
61     }
62
63     /**
64      * see the spec
65      */

66     public final int getColumnCount() {
67         if (columnNames == null)
68             return 0;
69         else
70             return columnNames.size();
71     }
72
73     /**
74      * see the spec
75      */

76     public final int getRowCount() {
77         if (rows == null)
78             return 0;
79         else
80             return rows.size();
81     }
82
83     /**
84      * see the spec
85      */

86     public final String JavaDoc getColumnName(int col) {
87         if (columnNames != null && col < columnNames.size())
88             return (String JavaDoc) columnNames.get(col);
89         else
90             return super.getColumnName(col);
91     }
92
93     /**
94      * see the spec
95      */

96     public final Object JavaDoc getValueAt(int row, int col) {
97         ArrayList rows = getRows();
98
99         if (rows != null && row < rows.size()) {
100             CustomerInventory line = (CustomerInventory)rows.get(row);
101
102             if (line != null) {
103                 if (col == 0) {
104                     return line.getProduct().getName();
105                 }
106                 if (col == 1) {
107                     return line.getCount();
108                 }
109             }
110         }
111
112         return null;
113     }
114
115     /**
116      * set the screen language
117      */

118     public final void setLang() {
119         Whiteboard wb = MainWindow.getWhiteboard();
120         columnNames = new ArrayList();
121         columnNames.add(wb.getLang().getString("product"));
122         columnNames.add(wb.getLang().getString("count"));
123     }
124 }
125
Popular Tags