示例#1
0
  public void onInit() {
    super.onInit();
    BatchManager bm = getBatchManager();
    if (bm != null) {
      try {
        List<Batch> batches = bm.listAllBatches(user.getUsername(), collection.getId());
        if (batches.isEmpty()) {
          // skip it, and don't create a batch table
        } else {
          batchTable = new BatchTable("batches", batches);

          editItemsLink =
              new RelativeActionLink("edit", getMessage("label-batch-edit"), this, "onEditClick");
          addControl(editItemsLink);

          manageBatchLink =
              new RelativeActionLink(
                  "manage", getMessage("label-batch-manage"), this, "onManageClick");
          addControl(manageBatchLink);

          Column actionsColumn = new Column("action", getMessage("label-batch-action"));
          actionsColumn.setDecorator(
              new LinkDecorator(
                  batchTable, new AbstractLink[] {editItemsLink, manageBatchLink}, "id"));
          actionsColumn.setSortable(false);
          batchTable.addColumn(actionsColumn);

          toggleOpenLink = new RelativeActionLink("openClose", this, "onToggleOpenClick");
          addControl(toggleOpenLink);
          Column openCloseColumn = new Column("open/close", getMessage("label-batch-open-close"));
          openCloseColumn.setDecorator(
              new OpenLinkDecorator(
                  batchTable,
                  toggleOpenLink,
                  "id",
                  bm,
                  getMessage("label-batch-open"),
                  getMessage("label-batch-close")));
          openCloseColumn.setSortable(false);
          batchTable.addColumn(openCloseColumn);

          addControl(batchTable);
        }
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }

      // This is disabled until we add more robust mechanisms for editing
      // the contents of batches.
      batchForm = new Form("batchForm");
      TextField nameField = new TextField("name");
      nameField.setRequired(true);
      batchForm.add(nameField);
      Submit newBatchButton =
          new Submit("new", getMessage("button-new-batch"), this, "onCreateNewBatch");
      batchForm.add(newBatchButton);
      this.addControl(batchForm);
    }
  }
示例#2
0
 public boolean onToggleOpenClick() {
   BatchManager bm = getBatchManager();
   int batchId = toggleOpenLink.getValueInteger();
   try {
     if (!bm.isBatchOpen(user.getUsername(), collection.getId(), batchId)) {
       bm.openBatch(user.getUsername(), collection.getId(), batchId);
     } else {
       bm.closeBatch(user.getUsername(), collection.getId(), batchId);
     }
     setRedirect("batches.htm");
     return false;
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   }
 }