Пример #1
0
  private ChangeObject getHintObject(Container container) {
    ChangeObject result = new ChangeObject();
    result.setChangeType(ChangeType.CONTAINER);
    if (container == null) {
      return result;
    }

    ProductContainerData productContainerData = new ProductContainerData();
    productContainerData.setProductContainer(container);
    result.setSelectedData(productContainerData);
    return result;
  }
Пример #2
0
  public AddItemBatchView(GUI parent, DialogBox dialog, ProductContainerData target) {
    super(parent, dialog);

    construct();
    container = (Container) target.getTag();
    _controller = new AddItemBatchController(this, target);
  }
Пример #3
0
  /** Updates all of the items in the view to match the model. */
  public void updateItems(boolean restoreSelected) {
    /*
     * Item Table The table is sorted by Entry Date (ascending). The Expiration Date column
     * contains the Item s expiration date, or empty if this is unspecified. The Storage
     * Unit column contains the name of the Storage Unit that contains the Item. The
     * Product Group column contains the name of the Product Group that contains the Item,
     * or empty if the Item is not in a Product Group.
     */

    ProductData selectedProduct = view.getSelectedProduct();
    ArrayList<ItemData> itemsToDisplay = new ArrayList<ItemData>();
    ItemData selectedItem = view.getSelectedItem();

    if (selectedProduct != null) {
      Product product = (Product) selectedProduct.getTag();
      ProductContainerData pcData = view.getSelectedProductContainer();
      if (pcData == null)
        throw new NullPointerException("Selected product container should not be null");
      ProductContainer container = (ProductContainer) pcData.getTag();

      Collection<Item> items;

      if (container == null) { // Root container is selected
        items = product.getItems();
      } else {
        items = container.getItemsForProduct(product);
      }
      if (items != null) {
        for (Item item : items) {
          ItemData id = DataWrapper.wrap(item);
          itemsToDisplay.add(id);
        }
      }
    }

    Collections.sort(
        itemsToDisplay,
        new Comparator<ItemData>() {
          @Override
          public int compare(ItemData arg0, ItemData arg1) {
            return arg0.getEntryDate().compareTo(arg1.getEntryDate());
          }
        });

    view.setItems(itemsToDisplay.toArray(new ItemData[itemsToDisplay.size()]));
    if (restoreSelected && selectedItem != null) view.selectItem(selectedItem);
  }
Пример #4
0
  /** Updates all of the products in the view to match the model. */
  public void updateProducts(boolean restoreSelected) {
    /*
     * Product Table The table is sorted by Description (ascending). The Count column
     * displays the number of Items of that Product contained in the selected node.
     * Specifically, if the root Storage Units node is selected, Count is the total number
     * of Items of that Product in the entire system . If a Product Container (Storage Unit
     * or Product Group) node is selected, Count is the number of Items of that Product
     * contained in the selected Product Container.
     */

    // MERGED from InventoryController
    // Load Products in selected ProductContainer
    List<ProductData> productDataList = new ArrayList<ProductData>();
    ProductContainerData selectedContainer = view.getSelectedProductContainer();
    ProductData selectedProduct = view.getSelectedProduct();

    if (selectedContainer != null) {
      ProductContainer selected = (ProductContainer) selectedContainer.getTag();
      if (selected != null) {
        for (Product p : selected.getProducts()) {
          if (selected.getItemsForProduct(p) != null) {
            int count = selected.getItemsForProduct(p).size();
            productDataList.add(DataWrapper.wrap(p, count));
          } else {
            productDataList.add(DataWrapper.wrap(p, 0));
          }
        }
        // Update contextView
        ProductContainer currentContainer = (ProductContainer) selectedContainer.getTag();
        if (currentContainer instanceof StorageUnit) {
          view.setContextUnit(selectedContainer.getName());
          view.setContextGroup("");
          view.setContextSupply("");
        } else if (currentContainer instanceof ProductGroup) {
          ProductGroup group = (ProductGroup) currentContainer;
          StorageUnit root = view.getProductContainerManager().getRootStorageUnitForChild(group);
          view.setContextUnit(root.getName());
          view.setContextGroup(group.getName());
          view.setContextSupply(group.getThreeMonthSupply().toString());
        }
      } else {
        // Root "Storage units" node is selected; display all Products in system
        ProductManager manager = view.getProductManager();
        ProductContainerManager pcManager = view.getProductContainerManager();
        for (Product p : manager.getProducts()) {
          int count = 0;
          for (StorageUnit su : pcManager.getStorageUnits()) {
            if (su.getItemsForProduct(p) != null) count += su.getItemsForProduct(p).size();
          }
          productDataList.add(DataWrapper.wrap(p, count));
        }
        view.setContextUnit("All");
      }
    }

    Collections.sort(
        productDataList,
        new Comparator<ProductData>() {
          @Override
          public int compare(ProductData o1, ProductData o2) {
            return o1.getDescription().compareTo(o2.getDescription());
          }
        });

    view.setProducts(productDataList.toArray(new ProductData[productDataList.size()]));
    if (restoreSelected && selectedProduct != null) {
      view.selectProduct(selectedProduct);
    }
    updateItems(restoreSelected);
  }