/** 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); }