Beispiel #1
0
  private void printBarcode() throws AppException, UserException {
    Session session = HibernateUtils.openSession();
    try {
      int selectedRow = table.getSelectedRow();
      if (selectedRow < 0) {
        return;
      }
      int itemId =
          (int)
              table
                  .getModel()
                  .getValueAt(selectedRow, tableParameters.get(ColumnEnum.ID).getColumnIndex());

      ItemFacade facade = ItemFacade.getInstance();
      Item item = facade.getDetail(itemId, session);

      String barcode = item.getBarcode();
      if (barcode == null || barcode.trim().equals("")) {
        throw new UserException(
            "Barcode untuk barang ["
                + item.getCode()
                + "] "
                + item.getName()
                + " belum diregistrasi");
      }

      File file = BarcodeUtils.generatePdfFile(item.getBarcode());
      BarcodeUtils.print(file);

    } finally {
      session.close();
    }
  }