Пример #1
0
  /** Is called when a purchase has completed. */
  private EventHandler<ActionEvent> sendOrder() {
    return e -> {
      viewDisplay.show(viewDisplay.getView(receiptPane));

      ShoppingCartHandler handler = ShoppingCartHandler.getInstance();
      List<ShoppingItem> items = handler.getCartItems();

      items.forEach(item -> db.getShoppingCart().addItem(item));

      db.placeOrder();
      handler.clearCart();
      db.shutDown();

      // ---------------//
      List<Order> orders = IMatDataHandler.getInstance().getOrders();

      Collections.sort(
          orders,
          (o1, o2) -> {
            return (int) (o2.getDate().getTime() - o1.getDate().getTime());
          });

      float totalPrice = 0;
      for (ShoppingItem item : orders.get(0).getItems()) {
        totalPrice += item.getTotal();
      }

      RecipeController.getInstance().setTitleText(InformationStorage.getFirstName());
      RecipeController.getInstance().setPriceText(totalPrice);
      RecipeController.getInstance().setDeliveryTimeText(InformationStorage.getDelivery());
      RecipeController.getInstance().setPaymentText(InformationStorage.getPaymentType());
    };
  }
Пример #2
0
  private void setCredentialBinds() {
    ContentView view = viewDisplay.getView(credentialsPane);

    BindingGroup group = btnToCredentials.getBindingGroup();
    group.addBinding(CART_NONEMPTY.and(not(RECEIPT_VIEW_ACTIVE)));
    group
        .getState()
        .addListener(
            (obs, o, n) -> {
              ContentView storeView = viewDisplay.getView(storePane);
              ContentView receiptView = viewDisplay.getView(storePane);
              ContentView currentView = viewDisplay.getCurrentView().getValue();

              if (not(CART_NONEMPTY).get()
                  && !currentView.equals(storeView)
                  && !currentView.equals(receiptView)) viewDisplay.show(storeView);

              btnToCredentials.setDisable(true);
            });

    view.getBindingGroup().setAll(group.getBinds());
  }
Пример #3
0
  public void initialize(URL url, ResourceBundle bundle) {
    prevButton.disable();
    nextButton.disable();

    me = this;

    popupShadePane.setMouseTransparent(true);

    // Necessary to disable the last arrow
    btnToReceipt.setUserData("lastButton");

    // Give the popup-system required panes
    ModalPopup.initialize(popupPane, wrapperStackPane, popupShadePane);

    // Start viewDisplay-system
    viewDisplay = new ViewDisplay(contentPane);
    NavigationButton.setViewDisplay(viewDisplay);

    // Create the views,
    ContentView storeView = new ContentView(storePane);
    ContentView credentialsView = new ContentView(credentialsPane);
    ContentView purchaseView = new ContentView(purchasePane);
    ContentView receiptView = new ContentView(receiptPane);
    ContentView dummyView = new ContentView(dummyPane);

    // and add the views to the viewDisplay
    viewDisplay.addView(storeView);
    viewDisplay.addView(credentialsView);
    viewDisplay.addView(purchaseView);
    viewDisplay.addView(receiptView);
    viewDisplay.addView(dummyView);

    // Define necessary bindings
    PURCHASE_VIEW_ACTIVE = activeViewBinding(purchaseView);
    RECEIPT_VIEW_ACTIVE = activeViewBinding(receiptView);

    // Setup bindings that determine how you can move between views
    // setStoreBinds();
    setCredentialBinds();
    setPurchaseBinds();
    setReceiptBinds();

    // Set next & previous relationships
    storeView.setNext(credentialsView);
    credentialsView.setNext(purchaseView);
    credentialsView.setPrevious(storeView);
    purchaseView.setPrevious(credentialsView);
    purchaseView.setNext(receiptView);
    receiptView.setNext(storeView);
    receiptView.setPrevious(null);

    // Set actions for the previous & next buttons
    prevButton.setDirection(Direction.LEFT);
    nextButton.setDirection(Direction.RIGHT);
    prevButton.setOnAction(event -> viewDisplay.previous());
    nextButton.setOnAction(
        event -> {
          // If we are on purchase, going to the next view means finishing the purchase.
          if (viewDisplay.getCurrentView().get().equals(purchaseView)) sendOrder().handle(event);
          else viewDisplay.next();
        });

    // Initialize the navigation buttons
    btnToStore.initialize(storeView, show(storeView), btnToCredentials, storeLabel, null);
    btnToCredentials.initialize(
        credentialsView, show(credentialsView), btnToPurchase, credentialsLabel, fromStoreArrow);
    btnToPurchase.initialize(
        purchaseView, show(purchaseView), btnToReceipt, purchaseLabel, fromCredentialsArrow);
    btnToReceipt.initialize(receiptView, sendOrder(), null, receiptLabel, fromPurchaseArrow);

    shoppingCartController.getShoppingListButton().setOnAction(e -> loadListPopup.show());
    shoppingCartController.getSaveListButton().setOnAction(e -> saveListPopup.show());

    contactButton.setOnAction(e -> contactPopup.show());
    historyButton.setOnAction(
        e -> {
          purchaseHistoryPopupController.update();
          purchaseHistoryPopup.show();
        });
    helpButton.setOnAction(e -> helpPopup.show());

    // Drag & drop:  resizing of window to 'highlight' the shopping cart.
    purchaseHistoryPopup.setOnDragOver(
        e -> {
          popupPane.setMouseTransparent(true);
          removeShadePane.getStyleClass().add("transparent");
        });

    // Show the store
    viewDisplay.show(storeView);

    wrapperStackPane.toFront();
  }
Пример #4
0
 /** Event that shows the view <code>view</code> */
 private EventHandler<ActionEvent> show(ContentView view) {
   return e -> viewDisplay.show(view);
 }