Esempio 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);
    }
  }
 @Override
 public void onInit() {
   super.onInit();
   if (id != null) {
     form.copyFrom(id);
   }
 }
Esempio n. 3
0
 public boolean onCreateNewBatch() {
   try {
     if (batchForm.isValid()) {
       getBatchManager()
           .createNewBatch(
               user.getUsername(),
               collection.getId(),
               batchForm.getField("name").getValue(),
               null);
       setRedirect("batches.htm");
       return false;
     } else {
       return true;
     }
   } catch (Throwable t) {
     throw new RuntimeException(t);
   }
 }
Esempio n. 4
0
  public boolean onSaveChanges() {
    try {
      User usr = userDao.findById(id);

      editUserForm.copyTo(usr);
      if (resetPasswordCheck.isChecked()) {
        usr.setPassword(usr.getName());
      }

      userDao.update(usr);
      setRedirect(UserPage.class);
    } catch (PersistenceException ex) {
      editUserForm.setError("Ошибка: " + ex.getMessage());
      return false;
    }

    return true;
  }
Esempio n. 5
0
 @Override
 public void onInit() {
   super.onInit();
   //        TODO Рассмотреть ситуацию, когда id не указан, так же во всех редаторах
   form.copyFrom(id);
   controlContours.setSelectedValues(id.getControlContours());
   sensorDevices.setSelectedValues(id.getSensorDevices());
   idField.setValueObject(id.getId());
 }
Esempio n. 6
0
  public ZoneEditor() {
    super("Редактирование зоны");
    ControlContour cc = new ControlContour();
    controlContours =
        new MultiObjectSelectField(cc, "controlContours", "Контуры управления", false);
    SensorDevice sd = new SensorDevice();
    sensorDevices =
        new MultiObjectSelectField(sd, "sensorDevices", "Устройства мониторинга", false);

    fs.add(name);
    fs.add(controlContours);
    fs.add(sensorDevices);
    fs.add(desc);
    fs.add(idField);

    backButton.setActionListener(
        new ActionListener() {

          @Override
          public boolean onAction(Control source) {
            setForward(ZoneTable.class);
            return false;
          }
        });
    sendButton.setActionListener(
        new ActionListener() {

          @Override
          public boolean onAction(Control source) {
            if (form.isValid()) {
              form.copyTo(id);
              RepositoryProvider.getRepository(Zone.class).save(id);
            }
            setRedirect(ZoneTable.class);
            return false;
          }
        });
    form.add(fs);
    form.add(backButton);
    form.add(resetButton);
    form.add(sendButton);
  }
Esempio n. 7
0
  @Override
  public void onInit() {
    super.onInit();

    EntityManager em = getEntityManager();
    if (em != null) {
      userDao = new UserDAO(em);
      if (id == null) {
        users = userDao.getAllUsers();
      } else {
        users = new ArrayList<User>();
        theUser = userDao.findById(id);
        users.add(theUser);

        editUserForm.copyFrom(theUser);
        resetPasswordCheck.setValue("" + false);
      }
    }
  }
Esempio n. 8
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));
  }
  public ImpactDeviceInserter() {
    super("Добавление нового исполнительного устройства");

    form.add(name);
    form.add(deviceType);
    form.add(unit);
    form.add(lowLimit);
    form.add(highLimit);
    form.add(state);
    form.add(desc);
    form.add(idField);

    backButton.setActionListener(
        new ActionListener() {

          @Override
          public boolean onAction(Control source) {
            setRedirect(ImpactDeviceTable.class);
            return false;
          }
        });
    sendButton.setActionListener(
        new ActionListener() {

          @Override
          public boolean onAction(Control source) {
            if (form.isValid()) {
              id = new ImpactDevice();
              form.copyTo(id);
              // TODO Проверять есть ли такая сущность с таким id, если есть - наращивать id в цикле
              id.setId(RepositoryProvider.getRepository(ImpactDevice.class).getTotalCount() + 1);
              RepositoryProvider.getRepository(ImpactDevice.class).save(id);
            }
            setRedirect(ImpactDeviceTable.class);
            return false;
          }
        });
    form.add(backButton);
    form.add(resetButton);
    form.add(sendButton);
  }