001 package market.stdform;
002
003 import market.UCustomer;
004 import market.UMUserBase;
005 import sale.FormSheet;
006 import sale.FormSheetContentCreator;
007 import users.UserManagerFilter;
008 import users.stdforms.UserTableFormSheet;
009 import util.swing.AbstractTableEntryDescriptor;
010
011 /**
012 * This FormSheet displays all customers of the market in a table. Customers can be selected for a
013 * detailed view or for deletion.
014 */
015 public class FSManagerCustomerOverview extends UserTableFormSheet {
016
017 /**
018 * ID for serialization.
019 */
020 private static final long serialVersionUID = -5619460852506628072L;
021
022 /**
023 * Creates a {@link UserTableFormSheet}. The look of the table is
024 * defined by the {@link TEDManagerCustomerOverview}.
025 */
026 public FSManagerCustomerOverview() {
027 super("Kunden", new UserManagerFilter(UMUserBase.getGlobalBase().getCustomers()),
028 null, null, null, new TEDManagerCustomerOverview());
029 addContentCreator(new FormSheetContentCreator() {
030 private static final long serialVersionUID = -4534547435685302813L;
031 public void createFormSheetContent(final FormSheet fs) {
032 fs.removeAllButtons();
033 fs.addButton("Daten bearbeiten", ButtonIDs.BTN_EDIT, null);
034 fs.addButton("Geschäftsbeziehung beenden", ButtonIDs.BTN_DELETE, null);
035 }
036 });
037 }
038 }
039
040 /**
041 * The {@link util.swing.TableEntryDescriptor} used by {@link FSManagerCustomerOverview}.
042 */
043 class TEDManagerCustomerOverview extends AbstractTableEntryDescriptor {
044
045 /**
046 * ID for serialization.
047 */
048 private static final long serialVersionUID = -4781479875423197734L;
049
050 /**
051 * @return the number of the table's columns.
052 */
053 public int getColumnCount() {
054 return 2;
055 }
056
057 /**
058 * @param nIndex the affected column.
059 * @return columns' names.
060 */
061 public String getColumnName(int nIndex) {
062 return (new String[]{"Name", "Firma"}) [nIndex];
063 }
064
065 /**
066 * @param nIndex the affected column.
067 * @return columns' classes. They indicate how column's values should be aligned.
068 */
069 public Class<?> getColumnClass (int nIndex) {
070 return String.class;
071 }
072
073 /**
074 * @param oRecord the affected table record.
075 * @param nIndex the affected column.
076 * @return columns' values
077 */
078 public Object getValueAt(Object oRecord, int nIndex) {
079 UCustomer usr = (UCustomer)oRecord;
080 switch (nIndex) {
081 case 0:
082 return usr.getSurname() + ", " + usr.getFirstName();
083 case 1:
084 return usr.getCompany();
085 }
086 return null;
087 }
088
089
090 /**
091 * Determines if columns can be sorted by the user.
092 *
093 * @param nIndex the affected column.
094 * @return <ul><li>true: columns can be sorted</li>
095 * <li>false: columns cannot be sorted</li></ul>
096 */
097 public boolean canSortByColumn(int nIndex) {
098 return true;
099 }
100
101 }