コード例 #1
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());
    }
  }
コード例 #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
  /** 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);
        });
  }