예제 #1
0
  private void setState(EBorrowState state) {
    System.out.println("Setting state: " + state);

    this.state = state;
    ui.setState(state);

    switch (state) {
      case INITIALIZED:
        reader.setEnabled(true);
        scanner.setEnabled(false);
        break;

      case SCANNING_BOOKS:
        reader.setEnabled(false);
        scanner.setEnabled(true);
        this.bookList = new ArrayList<IBook>();
        this.loanList = new ArrayList<ILoan>();
        scanCount = borrower.getLoans().size();

        // clear currentBook display
        ui.displayScannedBookDetails("");
        // clear pending loan display
        ui.displayPendingLoan("");
        break;

      case CONFIRMING_LOANS:
        reader.setEnabled(false);
        scanner.setEnabled(false);
        // display pending loans
        ui.displayConfirmingLoan(buildLoanListDisplay(loanList));
        break;

      case COMPLETED:
        reader.setEnabled(false);
        scanner.setEnabled(false);
        for (ILoan loan : loanList) {
          loanDAO.commitLoan(loan);
        }
        printer.print(buildLoanListDisplay(loanList));
        close();
        break;

      case CANCELLED:
        reader.setEnabled(false);
        scanner.setEnabled(false);
        close();
        break;

      case BORROWING_RESTRICTED:
        reader.setEnabled(false);
        scanner.setEnabled(false);
        ui.displayErrorMessage(
            String.format("Member %d cannot borrow at this time.", borrower.getID()));
        System.out.format("Member %d cannot borrow at this time.", borrower.getID());
        break;

      default:
        throw new RuntimeException("Unknown state");
    }
  }
 @Override
 public void cancelled() {
   close();
 }