package de.ntec.dehn.cd2; import static de.ntec.dehn.cd2.Const.*; import java.util.ArrayList; import java.util.List; 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; // ----------------- Initializer and Constructors ------------------ public WareToMarkt(final DehnDao dao) { fDao = dao; fLog.info("WareToMarkt created"); } // ----------------- Methods -------------------------------------- public void start(String terminal) { // TODO 1 Monitor Total and Distributed values (btQty, checkCompletness and so on) 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_HEIGHT,2*TF_WIDTH); tfNve.setEditMask(MASK_NVE); childrenPnOrder.add(tfNve); final TextField tfCollectiveOrder= new TextField(); TWUtils.putToRight(tfCollectiveOrder,tfNve,SPACING,TF_WIDTH,TF_HEIGHT); tfCollectiveOrder.setEditMask(MASK_COLLECTIVE_ORDER); childrenPnOrder.add(tfCollectiveOrder); Label lbCollectiveOrderTitle= new Label(COLLECTIVE_ORDER_ID); lbCollectiveOrderTitle.setBounds(tfCollectiveOrder.getX(),lbNVETitle.getY(), LABEL_WIDTH,LABEL_HEIGHT); childrenPnOrder.add(lbCollectiveOrderTitle); Button btOrder= TWUtils.getGoButton(); TWUtils.putToRight(btOrder,tfCollectiveOrder,SPACING); childrenPnOrder.add(btOrder); final Panel pnArticle= new Panel(); btOrder.addActionListener(Button.ACTION_CLICK,new ActionListener(){ public void actionPerformed(ActionEvent ev) { String collectiveOrder= tfCollectiveOrder.getText(); String collectiveOrderByNve= fDao.getCollectiveOrderByNve(tfNve.getText()); if (collectiveOrderByNve==null) collectiveOrderByNve= collectiveOrder; if ("".equals(collectiveOrder)) collectiveOrder= collectiveOrderByNve; if ("".equals(collectiveOrder)) { MessageBox.confirm(COLLECTIVE_ORDER_NOT_SPECIFIED); return; } if(!collectiveOrder.equals(collectiveOrderByNve)) { MessageBox.confirm(NVE_CONTRADICT_COLLECTIVE_ORDER); return; } tfCollectiveOrder.setText(collectiveOrder); flipFlop(pnArticle,pnOrder); } }); final List childrenPnArticle = pnArticle.getChildren(); 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,2*SPACING+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,lbTotal,SPACING,LABEL_WIDTH); lbTotal.getStyle().getBackground().setColor(Color.LIGHTYELLOW); childrenPnWare.add(lbTotal); 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(tfCollectiveOrder.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)); fDistributed+=(Integer)objects[objects.length-1]; 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 colRack= new Column(); colRack.setName(Const.RACK); gbWareToMarkets.getColumns().add(colRack); final Column colHori= new Column(); colHori.setName(Const.HORIZONTAL); colHori.setAlignX(AlignX.RIGHT); gbWareToMarkets.getColumns().add(colHori); final Column colVert= new Column(); colVert.setName(Const.VERTICAL); colVert.setAlignX(AlignX.RIGHT); gbWareToMarkets.getColumns().add(colVert); final Column colPlace= new Column(); colPlace.setName(Const.PLACE); colPlace.setAlignX(AlignX.RIGHT); gbWareToMarkets.getColumns().add(colPlace); 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 colProcessed= new Column(); colProcessed.setName("processed"); colProcessed.setVisible(false); gbWareToMarkets.getColumns().add(colProcessed); TWUtils.putUnder(gbWareToMarkets,lbWareToMarkets,SPACING,7*TF_WIDTH,7*TF_HEIGHT); 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); 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); // TODO 1 Ask for check digit (DNARCHECKSUM.COMPARE(RACK,HOR,VER,PROPOSED) 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; } 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); } }