예제 #1
0
  /**
   * prints out either the shopping List or the Overview of the items in stock depending on the type
   *
   * @param type
   */
  public void printOut(PrintOutType type) {

    boolean output = false;
    String fileToPrint = "";

    switch (type) {
      case OVERVIEW:
        output = SaveToFile.printOut(new ArrayList<ItemBox>(items), type, false);
        fileToPrint = "Overview.txt";
        break;
      case SHOPPING:
        ArrayList<ItemBox> temp = new ArrayList<>();

        // adds every Item which has an amount of 0 to the shopping list
        for (ItemBox item : items) {
          if (item.getAmount() == 0) {
            temp.add(item);
          }
        }
        output = SaveToFile.printOut(temp, type, false);
        fileToPrint = "Shopping.txt";
        break;
    }

    if (output) {
      log.debug(type.name() + " Successfully Saved PrintFile");
      File file = new File(System.getProperty("user.home") + "/Desktop/" + fileToPrint);

      if (file != null) {
        boolean printOut = Printing.printFile(file);

        if (printOut) {
          log.debug("Successfully printed File");
          Alert alert =
              Alerter.getAlert(AlertType.INFORMATION, "Print", null, "Successfully printed.");
          alert.showAndWait();
        } else {
          log.debug("File was saved but could not be printed");
          Alert alert =
              Alerter.getAlert(
                  AlertType.INFORMATION,
                  "Print Failed",
                  null,
                  "File saved but could not be printed.");
          alert.showAndWait();
        }
      }

    } else {
      Alert alert =
          Alerter.getAlert(
              AlertType.INFORMATION, "Error", null, "File could not be saved and printed.");
      alert.showAndWait();
      log.debug(type.name() + "PrintFile could NOT be saved and printed");
    }
  }
예제 #2
0
  /**
   * Updates the Item in the ItemBox itemBox
   *
   * @param itemBox
   */
  private void updateItem(ItemBox itemBox) {
    try {
      Item temp = getNewItem(itemBox.getGtin());

      // checks if the currently fetched temp Item is the still the same
      // item as the one online
      if (!temp.equals(itemBox.getItem())) {
        log.info(temp.name + " unequal to " + itemBox.getItem().name);
        itemBox.setItem(temp);
        log.info("Changed to " + temp.name);
      }
    } catch (Exception e1) {
      log.error("Error updating Item " + itemBox.getName() + " - " + e1.getMessage());
    }
  }
예제 #3
0
  /**
   * Updates the GUI sections labels on the left side of the GUI with the currently selected Item
   */
  private void updateOverview() {

    // check if anything is selected
    if (!listView.getSelectionModel().isEmpty()) {
      ItemBox itemBox = listView.getSelectionModel().getSelectedItem();

      nameLabel.setText(itemBox.getName());
      amountLabel.setText(String.valueOf(itemBox.getAmount()) + "x");
      gtinLabel.setText(itemBox.getGtin());
      categoriesLabel.setText(itemBox.getCategoriesText("long"));
      attributesLabel.setText(itemBox.getAttributes());
      log.info("Overview set to " + itemBox.getName());
    }
  }
예제 #4
0
  /** Sets up the behaviour of the Items int the menubar */
  private void setupMenuItems() {
    aboutMenu.setOnAction(
        event -> {
          AnchorPane root;
          try {
            root = FXMLLoader.load(getClass().getResource("about.fxml"));

            Stage stage = new Stage();
            stage.setScene(new Scene(root));
            stage.setTitle("About");
            stage.show();
          } catch (Exception e) {
            log.error("Error loading About Window - " + e.getMessage());
          }
        });

    exitMenu.setOnAction(
        event -> {
          Platform.runLater(
              new Runnable() {
                @Override
                public void run() {
                  Platform.exit();
                  log.debug("Window closed");
                }
              });
        });

    loadMenu.setOnAction(event -> loadFile(true));

    saveMenu.setOnAction(event -> Main.serializeItems());

    groupByMenu.setOnAction(
        event -> {
          Optional<String> sortOption =
              Alerter.getChoiceDialog("Sorting", null, "Select how you want to group: ");
          sortOption.ifPresent(letter -> groupItems(letter));
        });

    updateAllMenu.setOnAction(
        event -> {
          new Thread(
                  new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {
                      log.debug("UpdateAll Thread Triggered");

                      itemsMap.forEach(
                          (a, b) -> {
                            updateItem(b);
                          });

                      updateList();
                      Main.serializeItems();

                      log.debug("UpdateAll Thread terminated successfully");
                      return null;
                    }
                  })
              .start();
        });

    updateMenu.setOnAction(
        event -> {
          if (!listView.getSelectionModel().isEmpty()) {
            ItemBox itemBox = listView.getSelectionModel().getSelectedItem();
            updateItem(itemBox);
          } else {
            Alert alert =
                Alerter.getAlert(
                    AlertType.INFORMATION,
                    "No Item selected",
                    null,
                    "Please select the Item you want to update!");
            alert.showAndWait();
            log.debug("Info Popup triggered, No item selected");
          }
        });

    deleteMenu.setOnAction(
        event -> {
          ItemBox rem = itemsMap.remove(listView.getSelectionModel().getSelectedItem().getGtin());
          log.info("Item: " + rem.getName() + " removed");
          updateList();
        });

    repeatMenu.setOnAction(
        event -> {
          if (lastCommand != null) {
            String[] props = lastCommand.split(" ");
            log.info("Repeat called with: " + lastCommand);

            switch (props[0]) {
              case "ADD":
                addItem(props[1]);
                break;
              case "RM":
                removeItem(props[1]);
                break;
            }
          }
        });

    printMenu.setOnAction(
        event -> {
          printOut(PrintOutType.OVERVIEW);
        });

    printShoppingMenu.setOnAction(
        event -> {
          printOut(PrintOutType.SHOPPING);
        });
  }