Example #1
0
 /**
  * Sets the context view information when a ProductContainer is created or edited.
  *
  * @param currentContainer - selected container used to get information for the view
  */
 public void showContext(ProductContainer currentContainer) {
   if (currentContainer instanceof StorageUnit) {
     view.setContextGroup("");
     view.setContextSupply("");
     view.setContextUnit(currentContainer.getName());
   } else if (currentContainer instanceof ProductGroup) {
     ProductGroup group = (ProductGroup) currentContainer;
     StorageUnit root = view.getProductContainerManager().getRootStorageUnitForChild(group);
     if (root == null) return;
     view.setContextGroup(group.getName());
     view.setContextSupply(group.getThreeMonthSupply().toString());
     view.setContextUnit(root.getName());
   } else {
     view.setContextGroup("");
     view.setContextSupply("");
     view.setContextUnit("");
   }
 }
Example #2
0
 /** @param args */
 public static void main(String[] args) {
   Barcode.Test();
   Item.Test();
   Product.Test();
   StorageUnit.Test();
   ProductContainer.Test();
   ProductGroup.Test();
   ProductList.Test();
   ItemList.Test();
   ProductContainerList.Test();
   ItemFilter.Test();
   ProductFilter.Test();
   ItemManager.Test();
   ProductManager.Test();
   //		Size.Test();
   StorageUnitManager.Test();
   System.out.println("All tests passed.");
 }
Example #3
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);
  }