Exemplo n.º 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);
    }
  }
Exemplo n.º 2
0
  public UserPage() {
    addControl(usersTable);

    usersTable.setClass(Table.CLASS_ITS);
    usersTable.setPageSize(10);
    usersTable.setShowBanner(true);
    usersTable.setSortable(true);

    Column column = new Column("active", "");
    column.setDecorator(
        new Decorator() {
          @Override
          public String render(Object object, Context context) {
            boolean active = ((User) object).isActive();
            HtmlStringBuffer buffer = new HtmlStringBuffer();
            buffer.elementStart("img");
            buffer.appendAttribute(
                "src",
                context.getServletContext().getContextPath()
                    + "/css/images/"
                    + (active ? "bullet_green.png" : "bullet_red.png"));
            buffer.appendAttribute("title", (active ? "Активный" : "Не активный"));
            buffer.elementEnd();
            return buffer.toString();
          }
        });

    usersTable.addColumn(column);
    usersTable.addColumn(new Column("id"));
    usersTable.addColumn(new Column("name", "Логин"));

    usersTable.addColumn(new Column("firstname", "Имя"));
    usersTable.addColumn(new Column("lastname", "Фамилия"));
    column = new Column("role", "Группа");
    column.setDecorator(
        new Decorator() {
          @Override
          public String render(Object object, Context context) {
            final String role = ((User) object).getRole();
            if (role.equals("admin")) {
              return "Администратор";
            } else if (role.equals("moderator")) {
              return "Модератор";
            }
            return "Пользователь";
          }
        });
    usersTable.addColumn(column);
    usersTable.addColumn(new Column("lastLogin", "Последнее посещение"));

    editLink.setImageSrc("/css/images/user_edit.png");
    editLink.setTitle("Редактировать");

    deleteLink.setImageSrc("/css/images/user_delete.png");
    deleteLink.setTitle("Удалить");
    deleteLink.setAttribute(
        "onclick", "return window.confirm('Вы уверены, что хотите удалить этого пользователя?')");

    column = new Column("Action", "Операции");
    AbstractLink[] links = new AbstractLink[] {editLink, deleteLink};
    column.setDecorator(new LinkDecorator(usersTable, links, "id"));
    column.setSortable(false);
    usersTable.addColumn(column);

    usersTable.setDataProvider(
        new DataProvider<User>() {
          @Override
          public Iterable<User> getData() {
            return users;
          }
        });

    usersTable
        .getControlLink()
        .setActionListener(
            new ActionListener() {
              @Override
              public boolean onAction(Control source) {
                usersTable.saveState(getContext());
                return true;
              }
            });

    usersTable.restoreState(getContext());

    addControl(editUserForm);

    FieldSet loginFieldSet = new FieldSet("Учетная запись");
    editUserForm.add(loginFieldSet);

    usernameField = new TextField("name", "Имя пользователя");
    usernameField.setReadonly(true);
    loginFieldSet.add(usernameField);

    resetPasswordCheck = new Checkbox("resetPassword", "Сбросить пароль");
    loginFieldSet.add(resetPasswordCheck);
    isActiveCheck = new Checkbox("active", "Активный");
    loginFieldSet.add(isActiveCheck);

    roleSelect = new Select("role", "Группа");
    roleSelect.add(new Option("user", "Пользователь"));
    roleSelect.add(new Option("moderator", "Модератор"));
    roleSelect.add(new Option("admin", "Администратор"));
    loginFieldSet.add(roleSelect);

    FieldSet personalFieldSet = new FieldSet("Персональные данные");
    editUserForm.add(personalFieldSet);

    firstnameField = new TextField("firstname", "Имя", true);
    firstnameField.setMinLength(1);
    firstnameField.setMaxLength(30);
    personalFieldSet.add(firstnameField);

    lastnameField = new TextField("lastname", "Фамилия", true);
    lastnameField.setMinLength(1);
    lastnameField.setMaxLength(40);
    personalFieldSet.add(lastnameField);

    Submit save = new Submit("save", "Сохранить", this, "onSaveChanges");
    editUserForm.add(save);

    editUserForm.add(new HiddenField("id", Long.class));
  }