Exemple #1
0
  @Override
  @SuppressWarnings("unchecked")
  public void createBoxes(final Object model) {
    final PackingDetailsMd packingDetailsModel = (PackingDetailsMd) model;

    final PackingItemsMap packItems = new PackingItemsMap();
    final Map<Integer, DefaultMutableTreeNode> boxes =
        new HashMap<Integer, DefaultMutableTreeNode>();
    final List<DefaultMutableTreeNode> availBoxes = new ArrayList<DefaultMutableTreeNode>();

    final Enumeration<DefaultMutableTreeNode> enu =
        packingDetailsModel.getPackingTreeModel().getUsedBins().children();
    int boxNo = 1;
    while (enu.hasMoreElements()) {
      DefaultMutableTreeNode currentChild = enu.nextElement();

      // get boxes
      Object userObj = currentChild.getUserObject();
      if (userObj instanceof UsedBin) {
        boxes.put(boxNo, currentChild);
      }

      // get packing items
      List<AbstractPackingItem> itemList = new ArrayList<AbstractPackingItem>();
      Enumeration<DefaultMutableTreeNode> enumProd = currentChild.children();
      while (enumProd.hasMoreElements()) {
        DefaultMutableTreeNode child = enumProd.nextElement();

        // create products per box
        Object obj = child.getUserObject();
        if (obj instanceof PackingItem) {
          final PackingItem item = (PackingItem) obj;
          itemList.add(item);
        }
      }
      packItems.put(boxNo, itemList);
      boxNo++;
    }
    // put unpacked products
    final Enumeration<DefaultMutableTreeNode> unpacked =
        packingDetailsModel.getPackingTreeModel().getUnPackedItems().children();
    List<AbstractPackingItem> itemList = new ArrayList<AbstractPackingItem>();
    while (unpacked.hasMoreElements()) {
      DefaultMutableTreeNode currentChild = unpacked.nextElement();
      Object obj = currentChild.getUserObject();
      if (obj instanceof PackingItem) {
        final AbstractPackingItem item = (AbstractPackingItem) obj;
        itemList.add(item);
      }
    }
    if (itemList != null && itemList.size() != 0) {
      packItems.put(0, itemList);
    }

    // get available boxes
    final Enumeration<DefaultMutableTreeNode> available =
        packingDetailsModel.getPackingTreeModel().getAvailableBins().children();
    while (available.hasMoreElements()) {
      DefaultMutableTreeNode currentChild = available.nextElement();

      Object userObj = currentChild.getUserObject();
      if (userObj instanceof AvailableBins) {
        availBoxes.add(currentChild);
      }
    }

    setPackingItems(packItems);
    setBoxes(boxes);
    setAvailableBoxes(availBoxes);
  }