001 package market.stdform; 002 003 import java.util.Comparator; 004 005 import market.CIOpenPurchaseOrders; 006 import market.Conversions; 007 import market.SMarket; 008 import market.swing.CmpOpoNumbers; 009 import sale.FormSheet; 010 import sale.FormSheetContentCreator; 011 import util.swing.AbstractTableEntryDescriptor; 012 import data.stdforms.SingleTableFormSheet; 013 014 /** 015 * This FormSheet displays an overview of the market's purchases that have not yet arrived. 016 */ 017 public class FSManagerOpenPurchaseOrderMain { 018 019 /** 020 * Creates a {@link SingleTableFormSheet}. The look of the table is defined by the 021 * {@link TEDManagerOpenPurchaseOrderMain}. 022 * 023 * @return the created SingleTableFormSheet. 024 */ 025 public static SingleTableFormSheet create() { 026 027 final SingleTableFormSheet stfs = SingleTableFormSheet.create( 028 "Erwartete Lieferungen", 029 SMarket.getOpenPurchaseOrder(), 030 null, //DataBasket 031 new TEDManagerOpenPurchaseOrderMain() //TED 032 ); 033 stfs.addContentCreator(new FormSheetContentCreator() { 034 private static final long serialVersionUID = -7266796442603125861L; 035 public void createFormSheetContent(final FormSheet fs) { 036 fs.removeAllButtons(); 037 fs.addButton("Details", ButtonIDs.BTN_DETAIL, null); 038 } 039 }); 040 return stfs; 041 } 042 } 043 044 /** 045 * The {@link util.swing.TableEntryDescriptor} used by {@link FSManagerOpenPurchaseOrderMain}. 046 */ 047 class TEDManagerOpenPurchaseOrderMain extends AbstractTableEntryDescriptor { 048 049 /** 050 * ID for serialization. 051 */ 052 private static final long serialVersionUID = 2975498437787636914L; 053 054 private Comparator<Object> sortValue = new CmpOpoNumbers(); 055 056 /** 057 * @return the number of the table's columns. 058 */ 059 public int getColumnCount() { 060 return 3; 061 } 062 063 /** 064 * @param nIndex the affected column. 065 * @return columns' names. 066 */ 067 public String getColumnName(int nIndex) { 068 return (new String[]{ "Bestelldatum", "Gesamtsumme", "Tage bis Ankunft"}) [nIndex]; 069 } 070 071 /** 072 * @param nIndex the affected column. 073 * @return columns' classes. They indicate how column's values should be aligned. 074 */ 075 public Class<?> getColumnClass (int nIndex) { 076 return Number.class; 077 } 078 079 /** 080 * @param oRecord the affected table record. 081 * @param nIndex the affected column. 082 * @return columns' values 083 */ 084 public Object getValueAt(Object oRecord, int nIndex) { 085 CIOpenPurchaseOrders opo = (CIOpenPurchaseOrders)oRecord; 086 switch (nIndex) { 087 case 0: return opo.getName(); 088 case 1: return Conversions.doubleToCurrency(opo.getOrdersValue().doubleValue(), " Euro"); 089 case 2: return opo.getValue(); 090 } 091 return null; 092 } 093 094 /** 095 * Determines if columns can be sorted by the user. 096 * 097 * @param nIndex the affected column. 098 * @return <ul><li>true: columns can be sorted</li> 099 * <li>false: columns cannot be sorted</li></ul> 100 */ 101 public boolean canSortByColumn(int nIndex) { 102 return true; 103 } 104 105 /** 106 * @param nIndex the affected column. 107 * @return the {@link Comparator} to be used when sorting the column. 108 */ 109 public Comparator<Object> getColumnOrder(int nIndex) { 110 switch(nIndex) { 111 case 0: return null; 112 case 1: return sortValue; 113 case 2: return null; 114 } 115 return null; 116 } 117 }