コード例 #1
0
  public void checkStatus() {
    boolean nothingToReport = true;
    Set<Stock> critical = Service.getCriticalStocks(75);
    if (critical != null && critical.size() > 0) {
      if (critical.size() <= 1) {
        String name = "Unnamed";
        for (Stock s : critical) {
          if (s != null && s.getName() != null && s.getName().trim().length() > 0) {
            name = s.getName();
            break;
          }
        }
        lblStocks.setText(
            "<html><strong style=\"color:#777700;\">We are in a bit of a pickle</strong>: one of your stocks ("
                + name
                + ") is running out of space. </html>");
      } else {
        String names = "";
        for (Stock s : critical) {
          if (s != null && s.getName() != null && s.getName().trim().length() > 0) {
            if (names.length() > 0) names += ", ";
            names += s.getName();
          } else {
            if (names.length() > 0) names += ", ";
            names += "Unnamed";
          }
        }
        lblStocks.setText(
            "<html><strong style=\"color:red;\">You are in a world of hurt</strong>: "
                + critical.size()
                + " of your stocks ("
                + names
                + ") are running out of space. </html>");
      }
      nothingToReport = false;
    } else {
      lblStocks.setText(
          "<html><strong style=\"color:green;\">Your storage is in tip-top shape</strong>: there are no Stocks running out of space. </html>");
    }

    Set<Tray> expiring = Service.getExpiringTrays();
    if (expiring != null && expiring.size() > 0) {
      Map<Stock, Integer> stocks = new HashMap<Stock, Integer>();
      for (Tray tray : expiring) {
        if (tray != null
            && tray.getStorageUnit() != null
            && tray.getStorageUnit().getStock() != null) {
          Stock stock = tray.getStorageUnit().getStock();
          if (stocks.containsKey(stock)) {
            stocks.put(stock, stocks.get(stock) + 1);
          } else {
            stocks.put(stock, 1);
          }
        } else {
          if (stocks.containsKey(null)) {
            stocks.put(null, stocks.get(null) + 1);
          } else {
            stocks.put(null, 1);
          }
        }
      }
      String names = "";
      for (Stock s : stocks.keySet()) {
        if (s != null && s.getName() != null && s.getName().trim().length() > 0) {
          if (names.length() > 0) names += ", ";
          names += s.getName();
          names += " - " + stocks.get(s);
        } else if (s == null) {
          if (names.length() > 0) names += ", ";
          names += "Unknown stock";
          names += " - " + stocks.get(s);
        }
      }
      lblExpiring.setText(
          "<html><strong style=\"color:#777700;\">The situation is getting hairy</strong>: the following stocks have aging trays: "
              + names
              + ". </html>");
      nothingToReport = false;
    } else {
      lblExpiring.setText(
          "<html><strong style=\"color:green;\">There is no problem with expiring trays</strong>: there are no expiring trays at the moment. </html>");
    }
    Set<Tray> wasted = Service.getWastedTrays();
    if (wasted != null && wasted.size() > 0) {
      Map<Stock, Integer> stocks = new HashMap<Stock, Integer>();
      for (Tray tray : wasted) {
        if (tray != null
            && tray.getStorageUnit() != null
            && tray.getStorageUnit().getStock() != null) {
          Stock stock = tray.getStorageUnit().getStock();
          if (stocks.containsKey(stock)) {
            stocks.put(stock, stocks.get(stock) + 1);
          } else {
            stocks.put(stock, 1);
          }
        } else {
          if (stocks.containsKey(null)) {
            stocks.put(null, stocks.get(null) + 1);
          } else {
            stocks.put(null, 1);
          }
        }
      }
      String names = "";
      for (Stock s : stocks.keySet()) {
        if (s != null && s.getName() != null && s.getName().trim().length() > 0) {
          if (names.length() > 0) names += ", ";
          names += s.getName();
          names += " - " + stocks.get(s);
        } else if (s == null) {
          if (names.length() > 0) names += ", ";
          names += "Unknown stock";
          names += " - " + stocks.get(s);
        }
      }
      lblWasted.setText(
          "<html><strong style=\"color:red;\">The reality is getting very sad</strong>: the following stocks have wasted trays: "
              + names
              + ". </html>");
      nothingToReport = false;
    } else {
      lblWasted.setText(
          "<html><strong style=\"color:green;\">There is no problem with wasted trays</strong>: there are no wasted trays at the moment. </html>");
    }

    if (nothingToReport) {
      this.setPreferredSize(new Dimension(0, 0));
    } else {
      this.setPreferredSize(new Dimension(0, 50));
    }
  }