01: package com.salmonllc.examples.example15;
02:
03: //The Salmon Open Framework for Internet Applications (SOFIA)
04: //Copyright (C) 1999 - 2002, Salmon LLC
05: //
06: //This program is free software; you can redistribute it and/or
07: //modify it under the terms of the GNU General Public License version 2
08: //as published by the Free Software Foundation;
09: //
10: //This program is distributed in the hope that it will be useful,
11: //but WITHOUT ANY WARRANTY; without even the implied warranty of
12: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: //GNU General Public License for more details.
14: //
15: //You should have received a copy of the GNU General Public License
16: //along with this program; if not, write to the Free Software
17: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: //
19: //For more information please visit http://www.salmonllc.com
20:
21: import com.salmonllc.sql.*;
22: import com.salmonllc.swing.STable;
23:
24: import javax.swing.*;
25: import javax.swing.table.TableColumn;
26: import java.awt.*;
27:
28: /**
29: * A quick panel that throws up a table for the search results
30: */
31: public class ListPanel extends JPanel {
32:
33: public ListPanel(DataStoreProxy ds, Icon errorIcon, int width) {
34: setLayout(new GridLayout(1, 1));
35: STable tab = new STable();
36: tab.setDataStore(ds);
37: tab.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
38: try {
39: int w = (int) (width * .6);
40:
41: //add a computed column for the first name and last name
42: TableColumn col = tab.addDisplayColumn(
43: "listField.contact.name",
44: "contact.first_name + ' ' + contact.last_name",
45: "Contact Name");
46: col.setPreferredWidth(w);
47:
48: //add validations to the first column in the table for all the columns. This way if there is an error in any of them the error icon will show.
49: for (int i = 0; i < ds.getColumnCount(); i++)
50: tab.addColumnValidations(col, ds.getColumnName(i),
51: errorIcon);
52:
53: //add a phone number column
54: tab.addDisplayColumn("listField.contact.main_phone",
55: "contact.main_phone", "Phone Number");
56: } catch (DataStoreException e) {
57: e.printStackTrace();
58: }
59: add(new JScrollPane(tab));
60: }
61:
62: }
|