Esempio n. 1
0
  /**
   * Append given <code>itemPacked</code> to existing packed items
   *
   * @param key
   * @param itemPacked
   */
  public void appendPackedItem(final int key, final AbstractPackingItem itemPacked) {
    List<AbstractPackingItem> existingPackedItems = get(key);
    if (existingPackedItems == null) {
      existingPackedItems = new ArrayList<AbstractPackingItem>();
      put(key, existingPackedItems);
    } else {
      for (final AbstractPackingItem item : existingPackedItems) {
        // add new item into the list only if is a real new item
        // NOTE: should be only one item with same grouping key
        if (item.getGroupingKey() == itemPacked.getGroupingKey()) {
          item.addSchedules(itemPacked);
          return;
        }
      }
    }

    //
    // No matching existing packed item where our item could be added was found
    // => add it here as a new item
    existingPackedItems.add(itemPacked);
  }
Esempio n. 2
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);
  }