package de.ntec.dehn.cd2; import static de.ntec.dehn.cd2.Const.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import de.ntec.dehn.util.TWUtils; import thinwire.ui.AlignX; import thinwire.ui.Application; import thinwire.ui.Button; import thinwire.ui.Component; import thinwire.ui.Container; import thinwire.ui.Frame; import thinwire.ui.GridBox; import thinwire.ui.Label; import thinwire.ui.MessageBox; import thinwire.ui.TextField; import thinwire.ui.GridBox.Column; import thinwire.ui.GridBox.Row; import thinwire.ui.event.ActionEvent; import thinwire.ui.event.ActionListener; import thinwire.ui.event.KeyPressEvent; import thinwire.ui.event.KeyPressListener; import thinwire.ui.event.PropertyChangeEvent; import thinwire.ui.event.PropertyChangeListener; import thinwire.ui.style.Color; import thinwire.ui.Panel; import thinwire.ui.ScrollType; public class WareToMarkt { // ----------------- Constants ------------------------------------ private static final String TITLE= "Crossdocking 2 - Verteilung"; private static final String WARE_TO_MARKETS = "Verteilung"; private static final Log fLog= LogFactory.getLog(WareToMarkt.class); // ----------------- Fields --------------------------------------- private final DehnDao fDao; int fTotal= 0; int fDistributed= 0; private Map fArticleMap= new HashMap(); private CheckDigitDialog fCheckDigitDialog= new CheckDigitDialog(); // ----------------- Initializer and Constructors ------------------ public WareToMarkt(final DehnDao dao) { fDao = dao; fLog.info("WareToMarkt created"); } // ----------------- Methods -------------------------------------- public void start(String terminal) { final Frame frame= Application.current().getFrame(); frame.setTitle(TITLE); frame.setScroll(ScrollType.AS_NEEDED); final Panel pnOrder= new Panel(); pnOrder.setBounds(0,0,frame.getWidth(),TF_HEIGHT*5); List childrenPnOrder= pnOrder.getChildren(); Label lbNVETitle= new Label(NVE); lbNVETitle.setBounds(MARGIN,MARGIN,LABEL_WIDTH,LABEL_HEIGHT); childrenPnOrder.add(lbNVETitle); final TextField tfNve= new TextField(); TWUtils.putUnder(tfNve,lbNVETitle,SPACING/2,TF_WIDTH*2,TF_HEIGHT); tfNve.setEditMask(MASK_NVE); childrenPnOrder.add(tfNve); final Button btOrder= TWUtils.getGoButton(); TWUtils.putToRight(btOrder,tfNve,SPACING); childrenPnOrder.add(btOrder); final GridBox gbCollectiveOrder= new GridBox(); TWUtils.putToRight(gbCollectiveOrder,btOrder,SPACING,TF_WIDTH+TF_WIDTH/3,TF_HEIGHT*4); gbCollectiveOrder.setVisibleHeader(false); final Column colCollectiveOrder= new Column(); gbCollectiveOrder.getColumns().add(colCollectiveOrder); gbCollectiveOrder.setEnabled(false); gbCollectiveOrder.getStyle().getBackground().setColor( pnOrder.getStyle().getBackground().getColor()); childrenPnOrder.add(gbCollectiveOrder); Label lbCollectiveOrderTitle= new Label(COLLECTIVE_ORDER_ID); lbCollectiveOrderTitle.setBounds(gbCollectiveOrder.getX(),lbNVETitle.getY(), LABEL_WIDTH,LABEL_HEIGHT); childrenPnOrder.add(lbCollectiveOrderTitle); final Panel pnArticle= new Panel(); btOrder.addActionListener(Button.ACTION_CLICK,new ActionListener(){ public void actionPerformed(ActionEvent ev) { if ("".equals(tfNve.getText())) { MessageBox.confirm(SHORT_OR_EMPTY_NVE); return; } Object[][] collectiveOrders= fDao.getCollectiveOrderByNve(tfNve.getText()); if (collectiveOrders.length==0) { MessageBox.confirm(NO_COLLECTIVE_ORDER_ASSOSIATED_WITH_NVE); return; } for (Object[] order: collectiveOrders) { gbCollectiveOrder.getRows().add(new Row(order)); } fArticleMap=fDao.getArticleMap(tfNve.getText()); flipFlop(pnArticle,pnOrder); } }); tfNve.addKeyPressListener(KEY_ENTER,new KeyPressListener(){ public void keyPress(KeyPressEvent ev) { btOrder.fireAction(Button.ACTION_CLICK); } }); pnOrder.setHeight(TWUtils.getNextY(gbCollectiveOrder,MARGIN)); frame.getChildren().add(pnOrder); final List childrenPnArticle = pnArticle.getChildren(); pnArticle.setBounds(0,0,frame.getWidth(),TF_HEIGHT*5); TWUtils.putUnder(pnArticle,pnOrder,SPACING,TF_HEIGHT*5); frame.getChildren().add(pnArticle); final Panel pnWare= new Panel(); final List childrenPnWare = pnWare.getChildren(); pnWare.setEnabled(false); final Label lbEanTitle= new Label(EAN); lbEanTitle.setBounds(MARGIN,MARGIN,LABEL_WIDTH,LABEL_HEIGHT); childrenPnArticle.add(lbEanTitle); final Label lbArticleNoTitle= new Label(ARTICLE_NUMBER); TWUtils.putToRight(lbArticleNoTitle,lbEanTitle,SPACING*2+SMALL_BUTTON_SIZE,LABEL_WIDTH); childrenPnArticle.add(lbArticleNoTitle); final TextField tfEan= new TextField(); TWUtils.putUnder(tfEan,lbEanTitle,SPACING/2,TF_WIDTH,TF_HEIGHT); tfEan.setEditMask(MASK_EAN); childrenPnArticle.add(tfEan); final Button btArticleNo= TWUtils.getGoButton(); TWUtils.putToRight(btArticleNo,tfEan,SPACING); childrenPnArticle.add(btArticleNo); final Label lbArticleNo= new Label(); TWUtils.putToRight(lbArticleNo,btArticleNo,SPACING,LABEL_WIDTH); lbArticleNo.getStyle().getBackground().setColor(Color.LIGHTYELLOW); childrenPnArticle.add(lbArticleNo); pnArticle.setHeight(TWUtils.getNextY(btArticleNo,MARGIN)); TWUtils.putUnder(pnWare,pnArticle,SPACING,TF_HEIGHT*15); frame.getChildren().add(pnWare); final Label lbWareToMarkets=new Label(WARE_TO_MARKETS); lbWareToMarkets.setBounds(MARGIN,MARGIN,LABEL_WIDTH,LABEL_HEIGHT); childrenPnWare.add(lbWareToMarkets); final Label lbTotalTitle= new Label(Const.TOTAL); TWUtils.putToRight(lbTotalTitle,lbWareToMarkets,LABEL_WIDTH,LABEL_WIDTH); childrenPnWare.add(lbTotalTitle); final Label lbTotal= new Label(); TWUtils.putToRight(lbTotal,lbTotalTitle,SPACING/2,LABEL_WIDTH); lbTotal.getStyle().getBackground().setColor(Color.LIGHTYELLOW); childrenPnWare.add(lbTotal); final Label lbDistributedTitle= new Label(Const.DISTRIBUTED); TWUtils.putToRight(lbDistributedTitle,lbTotal,SPACING,LABEL_WIDTH); childrenPnWare.add(lbDistributedTitle); final Label lbDistributed= new Label(); TWUtils.putToRight(lbDistributed,lbDistributedTitle,SPACING,LABEL_WIDTH); lbTotal.getStyle().getBackground().setColor(Color.LIGHTYELLOW); childrenPnWare.add(lbDistributed); final GridBox gbWareToMarkets= new GridBox(); gbWareToMarkets.setVisibleHeader(true); btArticleNo.addActionListener(Button.ACTION_CLICK, new ActionListener() { public void actionPerformed(ActionEvent ev) { if ("".equals(tfEan.getText())) { MessageBox.confirm(Const.ARTICLE_NOT_SPECIFIED); return; } String articleNo= fDao.getArticleByEan(tfEan.getText()); if (articleNo==null) { MessageBox.confirm(Const.UNKNOWN_EAN); return; } lbArticleNo.setText(articleNo); Object[][] marktsForArticle= fDao.getMarktsForArticle(tfNve.getText(),articleNo); if (marktsForArticle==null) { MessageBox.confirm(Const.ARTICLE_NOT_IN_ORDER); return; } fTotal= 0; fDistributed= 0; for (Object[] objects : marktsForArticle) { gbWareToMarkets.getRows().add(new Row(objects)); // It is supposed that last column is check digit, so delivered value is next to last fDistributed+=(Integer)objects[objects.length-2]; fTotal= fDistributed; } lbTotal.setText(String.valueOf(fTotal)); lbDistributed.setText(String.valueOf(fDistributed)); flipFlop(pnWare,pnArticle); fLog.trace("btArticleNo action"); } }); tfEan.addKeyPressListener(KEY_ENTER,new KeyPressListener(){ public void keyPress(KeyPressEvent ev) { btArticleNo.fireAction(Button.ACTION_CLICK); } }); final Column colMarket= new Column(); colMarket.setName(MARKET); gbWareToMarkets.getColumns().add(colMarket); final Column colPallete= new Column(); colPallete.setName(NVE); colPallete.setWidth(150); gbWareToMarkets.getColumns().add(colPallete); final Column colArea= new Column(); colArea.setName(Const.AREA); gbWareToMarkets.getColumns().add(colArea); final Column colOrderedQty= new Column(); colOrderedQty.setName(ORDERED_QUANTITY); colOrderedQty.setAlignX(AlignX.RIGHT); gbWareToMarkets.getColumns().add(colOrderedQty); final Column colAssignedQty= new Column(); colAssignedQty.setName(ASSIGNED_QUANTITY); colAssignedQty.setAlignX(AlignX.RIGHT); gbWareToMarkets.getColumns().add(colAssignedQty); final Column colChkDigit= new Column(); colChkDigit.setName(CHECK_DIGIT); colChkDigit.setVisible(false); final Column colProcessed= new Column(); colProcessed.setName("processed"); colProcessed.setVisible(false); gbWareToMarkets.getColumns().add(colProcessed); TWUtils.putUnder(gbWareToMarkets,lbWareToMarkets,SPACING,TF_WIDTH*7,TF_HEIGHT*7); childrenPnWare.add(gbWareToMarkets); final Label lbMarktTitle= new Label(MARKET); TWUtils.putUnder(lbMarktTitle,gbWareToMarkets,SPACING,LABEL_WIDTH,LABEL_HEIGHT); childrenPnWare.add(lbMarktTitle); final Label lbAssignedQty= new Label(ASSIGNED_QUANTITY); TWUtils.putToRight(lbAssignedQty,lbMarktTitle,SPACING,LABEL_WIDTH); childrenPnWare.add(lbAssignedQty); final Label lbMarkt= new Label(); TWUtils.putUnder(lbMarkt,lbMarktTitle,SPACING/2,TF_HEIGHT); lbMarkt.getStyle().getBackground().setColor(Color.LIGHTYELLOW); childrenPnWare.add(lbMarkt); final TextField tfAssignedQty= new TextField(); TWUtils.putUnder(tfAssignedQty,lbAssignedQty,SPACING/2,TF_WIDTH,TF_HEIGHT); tfAssignedQty.setEditMask(MASK_QTY); tfAssignedQty.setAlignX(AlignX.RIGHT); childrenPnWare.add(tfAssignedQty); gbWareToMarkets.addPropertyChangeListener(Row.PROPERTY_ROW_SELECTED, new PropertyChangeListener(){ public void propertyChange(PropertyChangeEvent ev) { Row row= (Row)ev.getSource(); lbMarkt.setText(row.get(colMarket.getIndex()).toString()); Object o= row.get(colAssignedQty.getIndex()); if (o==null) tfAssignedQty.setText("0"); else tfAssignedQty.setText(o.toString()); } }); final Button btAssignedQty= TWUtils.getGoButton(); TWUtils.putToRight(btAssignedQty,tfAssignedQty,SPACING); childrenPnWare.add(btAssignedQty); btAssignedQty.addActionListener(Button.ACTION_CLICK, new ActionListener(){ public void actionPerformed(ActionEvent ev) { if ("".equals(tfAssignedQty.getText())) { MessageBox.confirm(QUANTITY_NOT_SPECIFIED); return; } int ind= gbWareToMarkets.getSelectedRow().getIndex(); int newVal=Integer.parseInt(tfAssignedQty.getText()); if (newVal>(Integer)colOrderedQty.get(ind)) { MessageBox.confirm(OVERDELIVERY_IS_PROHIBITED); return; } int distributedNewVal= fDistributed+newVal- (colAssignedQty.get(ind)==null ? 0 : (Integer)colAssignedQty.get(ind)); if (distributedNewVal>fTotal) { MessageBox.confirm(Const.NOT_ENOUGH_GOODS); return; } fch fDistributed=distributedNewVal; lbDistributed.setText(String.valueOf(fDistributed)); colAssignedQty.set(ind,newVal); colProcessed.set(ind,"Y"); markNextUnprocessed(); } private void markNextUnprocessed() { GridBox.Row row= gbWareToMarkets.getSelectedRow(); int ind= row==null ? 0 : row.getIndex(); for (int i= ind; i c1, Container c2) { for(Component component : c1.getChildren()) { component.setEnabled(true); } c1.setEnabled(true); for(Component component : c2.getChildren()) { component.setEnabled(false); } c2.setEnabled(false); } }