001 package market.stdform; 002 003 import java.awt.GridBagConstraints; 004 import java.awt.GridBagLayout; 005 import java.util.Comparator; 006 007 import javax.swing.Box; 008 import javax.swing.BoxLayout; 009 import javax.swing.JComponent; 010 import javax.swing.JPanel; 011 import javax.swing.JScrollPane; 012 import javax.swing.JTextArea; 013 import javax.swing.event.TableModelEvent; 014 import javax.swing.event.TableModelListener; 015 016 import market.CIArticle; 017 import market.Conversions; 018 import market.SICustomer; 019 import market.swing.CmpNumbers; 020 import market.swing.ComponentFactory; 021 import sale.FormSheet; 022 import sale.FormSheetContentCreator; 023 import util.swing.AbstractTableEntryDescriptor; 024 import util.swing.TableEntryDescriptor; 025 import data.CountingStock; 026 import data.stdforms.SingleTableFormSheet; 027 import data.swing.CountingStockTableModel; 028 029 /** 030 * This FormSheet shows the order of the customer that has to be deduct in a table, 031 * it also shows a message-field containing information about removed articles that aren`t avaible yet. 032 */ 033 public class FSSellerOrderTable { 034 035 /** 036 * @return the order-table. 037 * 038 * @param shoppingBasket the shopping-basket of the customer that has to be deduct. 039 * @param sic the SICustomer in the till-queue related to the customer. 040 */ 041 public static SingleTableFormSheet getOrderTable(CountingStock shoppingBasket, final SICustomer sic){ 042 043 final SingleTableFormSheet stfs = SingleTableFormSheet.create( 044 "Kundenauftrag", 045 shoppingBasket, 046 null, 047 getTED()); 048 049 stfs.addContentCreator(new FormSheetContentCreator(){ 050 private static final long serialVersionUID = -4851008955900433637L; 051 protected void createFormSheetContent(FormSheet fs) { 052 JPanel jp_main = new JPanel(); 053 JPanel jp_upper = new JPanel(); 054 JComponent jp_table = new JPanel(); 055 JPanel jp_message = new JPanel(); 056 JScrollPane jsc = new JScrollPane(); 057 final JTextArea jta = new JTextArea(10, 200); 058 String missingA = sic.getMissingArticles(); 059 if(missingA.length()>1) jta.setText(getMessage(missingA)); 060 GridBagConstraints c = new GridBagConstraints(); 061 GridBagLayout gridbag = new GridBagLayout(); 062 063 stfs.getTable().getModel().addTableModelListener(new TableModelListener(){ 064 public void tableChanged(TableModelEvent e) { 065 String s = sic.getMissingArticles(); 066 if(s.length()>1) jta.setText(getMessage(s)); 067 } 068 }); 069 070 jp_table = fs.getComponent(); 071 jp_upper.setLayout(gridbag); 072 c.gridx = 0; 073 c.weightx = 1; 074 c.weighty = 1; 075 c.gridy = 0; 076 c.fill = GridBagConstraints.BOTH; 077 gridbag.setConstraints(jp_table, c); 078 jp_upper.add(jp_table); 079 jp_message.setBorder(ComponentFactory.createInsetBorder("Benachrichtigung")); 080 jp_message.setLayout(new BoxLayout(jp_message, BoxLayout.X_AXIS)); 081 jp_message.add(jsc); 082 jsc.setViewportView(jta); 083 084 jp_main.setLayout(new BoxLayout(jp_main, BoxLayout.Y_AXIS)); 085 jp_main.add(jp_upper); 086 jp_main.add(Box.createVerticalStrut(10)); 087 jp_main.add(jp_message); 088 fs.setComponent(jp_main); 089 090 fs.removeAllButtons(); 091 fs.addButton("Abrechnen",ButtonIDs.BTN_ACCEPT , null); 092 fs.addButton("Zurück",ButtonIDs.BTN_BACK , null); 093 } 094 }); 095 return stfs; 096 } 097 098 /** 099 * @return the message to be shown if articles are missing. 100 * 101 * @param missingA String containing counts and articles that are missed 102 */ 103 private static String getMessage(String missingA){ 104 return new String("Aufgrund eines vorübergehenden Engpasses\n"+ 105 "mussten wir folgende Artikel aus ihrer Bestellung entfernen:"+missingA); 106 } 107 108 /** 109 * @return the TableEntryDescriptor of the table. 110 */ 111 private static TableEntryDescriptor getTED(){ 112 AbstractTableEntryDescriptor ted = new AbstractTableEntryDescriptor(){ 113 private static final long serialVersionUID = 8304801171873992253L; 114 115 public int getColumnCount() { 116 return 3; 117 } 118 119 public String getColumnName(int nIdx) { 120 return (new String[]{ "Artikel", "Preis", "Anzahl"}) [nIdx]; 121 } 122 123 public Class<?> getColumnClass(int nIdx) { 124 return (new Class[] {String.class, Number.class, Number.class}) [nIdx]; 125 } 126 127 public Object getValueAt(Object oRecord, int nIdx) { 128 CIArticle article = Conversions.recordToCIArticle(oRecord); 129 int count = ((CountingStockTableModel.Record)oRecord).getCount(); 130 switch (nIdx) { 131 case 0: 132 return article.getArticleName(); 133 case 1: 134 return Conversions.valueToCurrency( 135 CIArticle.getCatalogItemValue().getValue(article)); 136 case 2: 137 return new Integer(count).toString(); 138 } 139 return null; 140 } 141 142 public boolean canSortByColumn(int nIndex) { 143 return true; 144 } 145 146 public Comparator<Object> getColumnOrder(int nIndex) { 147 switch (nIndex) { 148 case 1: return new CmpNumbers(CmpNumbers.BID); 149 case 2: return new CmpNumbers(CmpNumbers.COUNT); 150 default: return null; 151 } 152 } 153 }; 154 return ted; 155 } 156 }