Пример #1
0
 private void addStoreVisitButtonActionPerformed(java.awt.event.ActionEvent evt) {
   // call the controller
   ShoppingListController erc = new ShoppingListController();
   Calendar calendar = Calendar.getInstance();
   calendar.setTime((Date) storeVisitStartTimeSpinner.getValue());
   Time startTime = new Time(calendar.getTime().getTime());
   calendar.setTime((Date) storeVisitEndTimeSpinner.getValue());
   Time endTime = new Time(calendar.getTime().getTime());
   error =
       erc.createStoreVisit(
           storeVisitNameTextField.getText(),
           (java.sql.Date) storeVisitDatePicker.getModel().getValue(),
           startTime,
           endTime);
   // update visuals
   refreshData();
 }
Пример #2
0
  private void refreshData() {
    ShoppingListManager rm = ShoppingListManager.getInstance();
    // error
    errorMessage.setText(error);
    if (error == null || error.length() == 0) {
      // item list
      items = new HashMap<Integer, Item>();
      itemList.removeAllItems();
      Iterator<Item> iIt = rm.getItems().iterator();
      Integer index = 0;
      while (iIt.hasNext()) {
        Item i = iIt.next();
        items.put(index, i);
        itemList.addItem(i.getName());
        index++;
      }
      selectedItem = -1;
      itemList.setSelectedIndex(selectedItem);
      // store visit list
      storeVisits = new HashMap<Integer, StoreVisit>();
      storeVisitList.removeAllItems();
      Iterator<StoreVisit> svIt = rm.getStoreVisits().iterator();
      index = 0;
      while (svIt.hasNext()) {
        StoreVisit sv = svIt.next();
        storeVisits.put(index, sv);
        storeVisitList.addItem(sv.getName());
        index++;
      }
      selectedStoreVisit = -1;
      storeVisitList.setSelectedIndex(selectedStoreVisit);
      // item
      itemNameTextField.setText("");
      // store visit
      storeVisitNameTextField.setText("");
      storeVisitDatePicker.getModel().setValue(null);
      storeVisitStartTimeSpinner.setValue(new Date());
      storeVisitEndTimeSpinner.setValue(new Date());
    }

    // this is needed because the size of the window changes depending on whether an error message
    // is shown or not
    pack();
  }