Esempio n. 1
0
  private final ContentPanel createPropertiesContent() {
    FormPanel panel = new FormPanel();
    panel.setHeaderVisible(false);
    panel.setButtonAlign(HorizontalAlignment.RIGHT);
    panel.setStyleAttribute("padding", "20");

    KeyListener keyListener =
        new KeyListener() {
          public void componentKeyUp(ComponentEvent event) {
            editor.markDirty();
          }
        };

    name = new TextField<String>();
    name.setFieldLabel(constants.name());
    name.setEmptyText(constants.groupName());
    name.setAllowBlank(false);
    name.setMinLength(2);
    name.addKeyListener(keyListener);
    name.setStyleAttribute("marginTop", "5");
    name.setStyleAttribute("marginBottom", "5");
    panel.add(name);

    description = new TextArea();
    description.setPreventScrollbars(true);
    description.setFieldLabel(constants.description());
    description.addKeyListener(keyListener);
    description.setStyleAttribute("marginTop", "5");
    description.setStyleAttribute("marginBottom", "5");
    panel.add(description);

    return panel;
  }
Esempio n. 2
0
 /**
  * Instantiates a new prompt top dialog.
  *
  * @param builder the builder
  */
 protected PromptTopDialog(final Builder builder) {
   super(builder);
   promptLabel = new Label();
   promptLabel.addStyleName("kune-Margin-Medium-b");
   if (builder.promptLines > 1) {
     textField = new TextArea();
     textField.setHeight(20 * builder.promptLines);
   } else {
     textField = new TextField<String>();
   }
   if (TextUtils.notEmpty(builder.textFieldStyle)) {
     textField.addStyleName(builder.textFieldStyle);
   }
   textField.setRegex(builder.regex);
   textField.getMessages().setRegexText(builder.regexText);
   textField.getMessages().setMinLengthText(builder.minLengthText);
   textField.getMessages().setMaxLengthText(builder.maxLengthText);
   textField.setTabIndex(1);
   textField.setId(builder.textboxId);
   if (TextUtils.notEmpty(builder.emptyText)) {
     textField.setEmptyText(builder.emptyText);
   }
   if (builder.textFieldWidth != 0) {
     textField.setWidth(builder.textFieldWidth);
   }
   if (builder.minLength != 0) {
     textField.setMinLength(builder.minLength);
   }
   if (builder.maxLength != 0) {
     textField.setMaxLength(builder.maxLength);
   }
   if (builder.promptWidth != 0) {
     textField.setWidth(builder.promptWidth);
   }
   textField.setAllowBlank(builder.allowBlank);
   textField.addListener(
       Events.OnKeyPress,
       new Listener<FieldEvent>() {
         @Override
         public void handleEvent(final FieldEvent fe) {
           if (fe.getEvent().getKeyCode() == 13) {
             builder.onEnter.onEnter();
           }
         }
       });
   if (TextUtils.notEmpty(builder.promptText)) {
     promptLabel.setText(builder.promptText);
   }
   super.getInnerPanel().add(promptLabel);
   super.getInnerPanel().add(textField);
 }
Esempio n. 3
0
  private final ContentPanel createPropertiesPanel() {
    FormPanel panel = new FormPanel();
    panel.setHeaderVisible(false);
    panel.setButtonAlign(HorizontalAlignment.RIGHT);
    panel.setStyleAttribute("padding", "20");

    serverName = new TextField<String>();
    serverName.setFieldLabel("Server Name");
    serverName.setEmptyText("Please enter the server name");
    serverName.setAllowBlank(false);
    serverName.setMinLength(1);
    panel.add(serverName);

    return panel;
  }
Esempio n. 4
0
  private void createNewUSerDialog() {
    setButtons("");
    setLayout(new FitLayout());
    setHeading(HarvesterUI.CONSTANTS.addUser());
    setIcon(HarvesterUI.ICONS.add16());
    setResizable(false);
    setModal(true);
    setSize(600, 200);
    setBodyBorder(false);
    FormData formData = new FormData("95%");

    newUserFormPanel = new DefaultFormPanel();
    newUserFormPanel.setHeaderVisible(false);

    newUserFormPanel.setLayout(new EditableFormLayout(175));

    userNameField = new TextField<String>();
    userNameField.setFieldLabel(HarvesterUI.CONSTANTS.username() + HarvesterUI.REQUIRED_STR);
    userNameField.setId("userNameField");
    userNameField.setMinLength(4);
    userNameField.setAllowBlank(false);
    newUserFormPanel.add(userNameField, formData);

    Validator usernameValidator =
        new Validator() {
          public String validate(Field<?> field, String s) {
            if (!s.matches("^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$"))
              return HarvesterUI.CONSTANTS.usernameValidateMessage();
            return null;
          }
        };
    userNameField.setValidator(usernameValidator);

    emailField = new TextField<String>();
    emailField.setFieldLabel(HarvesterUI.CONSTANTS.email() + HarvesterUI.REQUIRED_STR);
    emailField.setId("emailField");
    emailField.setAllowBlank(false);
    newUserFormPanel.add(emailField, formData);

    Validator emailValidator =
        new Validator() {
          public String validate(Field<?> field, String s) {
            if (!s.matches("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"))
              return HarvesterUI.CONSTANTS.emailValidateMessage();
            return null;
          }
        };
    emailField.setValidator(emailValidator);

    roleCombo = new SimpleComboBox<String>();
    roleCombo.setEditable(false);
    roleCombo.setFieldLabel(HarvesterUI.CONSTANTS.role() + HarvesterUI.REQUIRED_STR);
    roleCombo.setTriggerAction(ComboBox.TriggerAction.ALL);
    for (UserRole userRole : UserRole.values()) {
      if (userRole != UserRole.ANONYMOUS) roleCombo.add(userRole.name());
    }
    roleCombo.setValue(roleCombo.getStore().getAt(0));
    newUserFormPanel.add(roleCombo, formData);

    saveButton =
        new Button(
            HarvesterUI.CONSTANTS.save(),
            HarvesterUI.ICONS.save_icon(),
            new SelectionListener<ButtonEvent>() {
              @Override
              public void componentSelected(ButtonEvent be) {
                AsyncCallback<User> callback =
                    new AsyncCallback<User>() {
                      public void onFailure(Throwable caught) {
                        new ServerExceptionDialog(
                                "Failed to get response from server", caught.getMessage())
                            .show();
                      }

                      public void onSuccess(User user) {
                        AsyncCallback<ResponseState> callback =
                            new AsyncCallback<ResponseState>() {
                              public void onFailure(Throwable caught) {
                                new ServerExceptionDialog(
                                        "Failed to get response from server", caught.getMessage())
                                    .show();
                              }

                              public void onSuccess(ResponseState result) {
                                unmask();
                                if (result == ResponseState.USER_ALREADY_EXISTS) {
                                  HarvesterUI.UTIL_MANAGER.getErrorBox(
                                      HarvesterUI.CONSTANTS.newUser(),
                                      HarvesterUI.CONSTANTS.usernameAlreadyExists());
                                  return;
                                }
                                hide();
                                userManagementGrid.getStore().add(newUser);
                                HarvesterUI.UTIL_MANAGER.getSaveBox(
                                    HarvesterUI.CONSTANTS.newUser(),
                                    HarvesterUI.CONSTANTS.saveNewUserSuccess());
                                Dispatcher.get().dispatch(AppEvents.ViewUserManagementForm);
                              }
                            };
                        mask(HarvesterUI.CONSTANTS.saveUserMask());
                        newUserFormPanel.submit();
                        String role = roleCombo.getValue().getValue().trim();
                        String userName = userNameField.getValue().trim();
                        String email = emailField.getValue().trim();
                        String password = "******";
                        newUser = new User(userName, password, role, email, 15);
                        service.saveNewUser(newUser, callback);
                      }
                    };
                String userName = userNameField.getValue();
                service.getUser(userName, callback);
              }
            });
    newUserFormPanel.addButton(saveButton);
    newUserFormPanel.addButton(
        new Button(
            HarvesterUI.CONSTANTS.cancel(),
            HarvesterUI.ICONS.cancel_icon(),
            new SelectionListener<ButtonEvent>() {
              @Override
              public void componentSelected(ButtonEvent be) {
                hide();
                Dispatcher.get().dispatch(AppEvents.ViewUserManagementForm);
              }
            }));

    newUserFormPanel.setButtonAlign(Style.HorizontalAlignment.CENTER);

    FormButtonBinding binding = new FormButtonBinding(newUserFormPanel);
    binding.addButton(saveButton);

    add(newUserFormPanel);
  }