コード例 #1
0
  /**
   * Edits the container and all of the children containers.
   *
   * @pre parameters != null
   * @pre canEditContainer( newContainer ) == true
   * @post if( checkCanEdit(container) ) { edit(container); }
   * @param oldContainer The original container
   * @param newContainer The new container values
   * @throws IllegalArgumentException if oldContainer == null or newContainer == null or
   *     newContainer.canEdit == false
   */
  public void editContainer(Container oldContainer, Container newContainer)
      throws IllegalArgumentException {

    if (oldContainer == null || newContainer == null || !canEditContainer(newContainer)) {
      throw new IllegalArgumentException();
    }

    System.out.println(" ------ Editing container --------");
    System.out.println("Before: " + oldContainer + "\nAfter:" + newContainer + "");

    if (oldContainer instanceof ProductGroup) {
      Container parent = oldContainer.getContainer(); // added for bug fix
      parent.getProductGroups().remove((ProductGroup) oldContainer);
      oldContainer.setName(newContainer.getName());
      ((ProductGroup) oldContainer)
          .setThreeMonthSupply(((ProductGroup) newContainer).getThreeMonthSupply());
      parent.getProductGroups().add((ProductGroup) oldContainer);
    } else {
      storageUnits.remove(oldContainer);
      oldContainer.setName(newContainer.getName());
      storageUnits.add((StorageUnit) oldContainer); // added for bug fix
    }

    containerDAO.update(new ContainerDTO(oldContainer));
    ChangeObject hint = getHintObject(oldContainer);
    setChanged();
    notifyObservers(hint);
  }
コード例 #2
0
 public void load() {
   Collection<ContainerDTO> productContainers = containerDAO.readAll();
   TreeMap<Integer, Set<ProductGroup>> parentToChild = new TreeMap<Integer, Set<ProductGroup>>();
   for (ContainerDTO containerDTO : productContainers) {
     if (containerDTO.getContainerId() == -1) {
       StorageUnit storageUnit = new StorageUnit().storageUnitConverter(containerDTO);
       storageUnits.add(storageUnit);
       idToContainer.put(storageUnit.getId(), storageUnit);
     } else {
       addToMap(containerDTO, parentToChild);
     }
   }
   setProductGroups(parentToChild, null);
 }
コード例 #3
0
 /**
  * Initializes container and adds it to the parent. Also adds container to list of ProductGroup if
  * instance of ProductGroup, otherwise parent is null.
  *
  * @pre container != null
  * @param parent
  * @param container
  */
 private void addContainerToTree(Container parent, Container container) {
   assert container != null;
   container.setContainer(parent);
   // container.setId( uniqueId++ );
   if (container instanceof ProductGroup) {
     parent.addProductGroup((ProductGroup) container);
   } else {
     storageUnits.add((StorageUnit) container);
   }
   ContainerDTO containerDTO = new ContainerDTO(container);
   containerDAO.create(containerDTO);
   container.setId(containerDTO.getId());
   idToContainer.put(container.getId(), container);
   ChangeObject hint = getHintObject(container);
   setChanged();
   notifyObservers(hint);
 }
コード例 #4
0
  /**
   * Deletes the container and all of the children containers.
   *
   * @pre Container.items() == 0, recursively, see condition below ***(can't assert that items == 0,
   *     have to trust)***
   * @pre container.exists() == true
   * @post delete(container), recursively
   * @param container Current container to be deleted
   * @throws IllegalArgumentException if container.container == null && container instanceof
   *     ProductGroup
   */
  public void deleteContainer(Container container) throws IllegalArgumentException {

    Container parent = container.getContainer();
    if (container instanceof ProductGroup) {
      if (parent == null) {
        throw new IllegalArgumentException();
      }
      Set<ProductGroup> productGroupList = container.getContainer().getProductGroups();
      productGroupList.remove(container);
    } else {
      storageUnits.remove(container);
    }
    ChangeObject hint;
    if (parent == null || parent.getProductGroups().isEmpty()) {
      hint = getHintObject(parent);
    } else {
      hint = getHintObject(parent.getProductGroups().iterator().next());
    }

    containerDAO.delete(new ContainerDTO(container));
    idToContainer.remove(container.getId());
    setChanged();
    notifyObservers(hint);
  }