KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > ui > DjTableModel


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.ui;
31
32 import java.util.ArrayList JavaDoc;
33
34 import javax.swing.table.AbstractTableModel JavaDoc;
35 import javax.swing.table.TableCellEditor JavaDoc;
36 import javax.swing.table.TableCellRenderer JavaDoc;
37
38 import com.genimen.djeneric.language.Messages;
39 import com.genimen.djeneric.repository.DjExtent;
40 import com.genimen.djeneric.repository.exceptions.DjenericException;
41
42 public abstract class DjTableModel extends AbstractTableModel JavaDoc
43 {
44   protected DjModelColumn[] _columns = new DjModelColumn[0];
45   // dummy
46
protected DjExtent _extent = null;
47   private ArrayList JavaDoc _listeners = new ArrayList JavaDoc();
48   protected boolean _editable = true;
49   protected boolean _insertable = true;
50   protected boolean _deleteable = true;
51
52   public DjTableModel()
53   {
54   }
55
56   public void setEditable(boolean b)
57   {
58     _editable = b;
59   }
60
61   public boolean isEditable()
62   {
63     return _editable;
64   }
65
66   public void setInsertable(boolean b)
67   {
68     _insertable = b;
69   }
70
71   public boolean isInsertable()
72   {
73     return _insertable;
74   }
75
76   public void setDeleteable(boolean b)
77   {
78     _deleteable = b;
79   }
80
81   public boolean isDeleteable()
82   {
83     return _deleteable;
84   }
85
86   public void setExtent(DjExtent extent)
87   {
88     _extent = extent;
89   }
90
91   public DjExtent getExtent()
92   {
93     return _extent;
94   }
95
96   public int getColumnCount()
97   {
98     return _columns.length;
99   }
100
101   public String JavaDoc getColumnName(int column)
102   {
103     return _columns[column]._title;
104   }
105
106   public TableCellRenderer JavaDoc getColumnRenderer(int column)
107   {
108     return _columns[column].getCellRenderer();
109   }
110
111   public TableCellEditor JavaDoc getColumnEditor(int column)
112   {
113     return _columns[column]._editor;
114   }
115
116   public int getColumnWidth(int column)
117   {
118     return _columns[column]._dspWidth;
119   }
120
121   public boolean isCellEditable(int row, int column)
122   {
123     return _editable && _columns[column]._editable;
124   }
125
126   public abstract int insertRow(int atIdx) throws DjenericException;
127
128   public abstract boolean deleteRow(int atIdx) throws DjenericException;
129
130   public void addStatusListener(DjStatusListener lsnr)
131
132   {
133     if (!_listeners.contains(lsnr)) _listeners.add(lsnr);
134   }
135
136   public void removeStatusListener(DjStatusListener lsnr)
137   {
138     _listeners.remove(lsnr);
139   }
140
141   public void setStatusMessage(String JavaDoc msg, boolean informative)
142   {
143     for (int i = 0; i < _listeners.size(); i++)
144     {
145       ((DjStatusListener) (_listeners.get(i))).setStatusMessage(msg, informative);
146     }
147   }
148
149   public void notifyModified()
150   {
151     for (int i = 0; i < _listeners.size(); i++)
152     {
153       ((DjStatusListener) (_listeners.get(i))).notifyModified();
154     }
155   }
156
157   public void setStatusMessage(String JavaDoc msg)
158   {
159     setStatusMessage(msg, true);
160   }
161
162   public void setStatusMessage(Throwable JavaDoc t)
163   {
164     for (int i = 0; i < _listeners.size(); i++)
165     {
166       ((DjStatusListener) (_listeners.get(i))).setStatusMessage(t);
167     }
168   }
169
170   public int convert2Int(String JavaDoc str) throws DjenericException
171   {
172     int result = 0;
173     if (str.trim().length() > 0)
174     {
175       try
176       {
177         result = Integer.parseInt(str);
178       }
179       catch (Exception JavaDoc x)
180       {
181         throw new DjenericException(Messages.getString("DjTableModel.InvalidNumber", str));
182       }
183     }
184     return result;
185   }
186 }
Popular Tags