001 package users.stdforms; 002 003 import sale.*; 004 import util.swing.*; 005 import util.swing.AbstractTableModel; 006 import users.User; 007 import users.UserManager; 008 import users.swing.JUserTable; 009 010 import java.util.Comparator; 011 import javax.swing.*; 012 import javax.swing.table.*; 013 014 /** 015 * A FormSheet displaying the contents of a {@link UserManager}. 016 * 017 * @author Thomas Medack 018 * @author Andreas Bartho 019 * @version 3.0 13/06/2001 020 * @since v3.0 021 */ 022 public class UserTableFormSheet extends FormSheet { 023 024 /** 025 * ID for serialization. 026 */ 027 private static final long serialVersionUID = -3562437116191352316L; 028 029 /** 030 * Reference to the currently selected index. 031 * 032 * @serial 033 */ 034 private int[] m_anSelection = new int[] { 035 -1}; 036 037 /** 038 * The {@link TableModel} of the table displayed. 039 */ 040 private transient util.swing.AbstractTableModel m_atmModel; 041 042 /** 043 * The {@link TableColumnModel} of the table displayed. 044 */ 045 private transient TableColumnModel m_tcmModel; 046 047 /** 048 * The displayed {@link JTable}. 049 */ 050 private transient JTable m_jtTable; 051 052 /** 053 * The {@link ListSelectionModel} of the table displayed. 054 */ 055 private transient ListSelectionModel m_lsmModel; 056 057 /** 058 * The UserManager from which the table is created. 059 */ 060 private UserManager m_umMan; 061 062 /** 063 * The {@link Gate} at which the FormSheet is being displayed. 064 * 065 * @serial 066 */ 067 private UIGate m_uigGate; 068 069 private transient JComponent m_jcComp; 070 071 /** 072 * Create a new UserTableFormSheet. The "{@link FormSheet#waitResponse}" property will default 073 * to true. 074 * 075 * @param sCaption the FormSheet's caption. 076 * @param um the UserManager which will be displayed 077 * @param c a JComponent which can be optionally displayed with the JUserTable. The 078 * JComponent of the FormSheet will be a JPanel. The JPanels contains a JSplitPane. 079 * The first JComponent of the JPanel is the JUserTable and the second is this JComponent. 080 * If it is null, only the JUserTable will be displayed. 081 * @param uigGate the Gate at which the FormSheet is displayed. 082 * @param cmp a comparator defining the order in which to display the individual users. If <code>null</code> 083 * the Userrecords will be ordered by their names. 084 * @param ted a TableEntryDescriptor that can split the UserManager's entries into a table's cells. 085 * Must not be <code>null</code>. 086 */ 087 public UserTableFormSheet(String sCaption, UserManager um, JComponent c, UIGate uigGate, 088 final Comparator<User> cmp, final TableEntryDescriptor ted) { 089 090 super(sCaption, (JComponent)null, true); 091 setGate(uigGate); 092 093 m_umMan = um; 094 m_jcComp = c; 095 096 addContentCreator(new FormSheetContentCreator() { 097 private static final long serialVersionUID = -2022512596984999513L; 098 099 protected void createFormSheetContent(FormSheet fs) { 100 JUserTable jut = new JUserTable(m_umMan, cmp, ted); 101 102 if (m_jcComp == null) { 103 fs.setComponent(new JScrollPane(jut)); 104 } else { 105 JSplitPane p = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(jut), m_jcComp); 106 p.setDividerSize(4); 107 p.setDividerLocation(200); 108 109 fs.setComponent(p); 110 } 111 112 ((UserTableFormSheet)fs).m_atmModel = (util.swing.AbstractTableModel)jut.getModel(); (( 113 UserTableFormSheet)fs).m_lsmModel = jut.getSelectionModel(); ((UserTableFormSheet)fs). 114 m_tcmModel = jut.getColumnModel(); 115 116 jut.setSelectionObserver(((UserTableFormSheet)fs).m_anSelection); 117 m_jtTable = jut; 118 } 119 }); 120 } 121 122 /** 123 * Gets the table. 124 * 125 * @override Never 126 */ 127 public JTable getTable() { 128 return m_jtTable; 129 } 130 131 /** 132 * Changes the {@link TableModel} of a table. 133 * @param tm the new TableModel 134 */ 135 public void setTableModel(AbstractTableModel tm) { 136 m_atmModel.fireTableDataChanged(); //unselect a possibly selected record 137 if (tm instanceof TableSorter) { 138 m_atmModel = tm; 139 } else { 140 m_atmModel = new TableSorter(tm); 141 } 142 m_jtTable.setModel(m_atmModel); 143 144 ((JAbstractTable)m_jtTable).initialize(); 145 } 146 147 /** 148 * Get the table's source. 149 * 150 * @override Never 151 * @return the UserManager from which the table was built. The class of the returned UserManager 152 * is <code>Object</code> to keep consistency with {@link data.stdforms.SingleTableFormSheet}. 153 */ 154 public Object getTableSource() { 155 return m_umMan; 156 } 157 158 /** 159 * Set the gate at which to display the FormSheet. This will also move the FormSheet to that gate, i.e. make 160 * the FormSheet the FormSheet of the given gate. 161 * 162 * @param uigGate the new Gate. 163 * 164 * @override Never 165 * 166 * @see UIGate#setFormSheet 167 */ 168 public void setGate(UIGate uigGate) { 169 if (m_uigGate != null) { 170 m_uigGate.setFormSheet(null); 171 } 172 173 m_uigGate = uigGate; 174 175 if (m_uigGate != null) { 176 m_uigGate.setFormSheet(this); 177 } 178 } 179 180 /** 181 * Get the Gate this FormSheet is currently being displayed at. 182 * 183 * @override Never 184 */ 185 public UIGate getGate() { 186 return m_uigGate; 187 } 188 189 /** 190 * Get the record currently selected. 191 * 192 * <p>The actual class of the record depends on the concrete type of 193 * TableModel used. See the TableModel's <code>getRecord()</code> method for 194 * details. 195 */ 196 public User getSelectedRecord() { 197 return (User)m_atmModel.getRecord(m_anSelection[0]); 198 } 199 200 /** 201 * Get the ListSelectionModel of the JUserTable which is displayed. 202 */ 203 public ListSelectionModel getSelectionModel() { 204 return m_lsmModel; 205 } 206 207 /** 208 * Get the TableColumnModel of the JUserTable which is displayed. 209 */ 210 public TableColumnModel getColumnModel() { 211 return m_tcmModel; 212 } 213 }