Example usage for com.vaadin.server UserError UserError

List of usage examples for com.vaadin.server UserError UserError

Introduction

In this page you can find the example usage for com.vaadin.server UserError UserError.

Prototype

public UserError(String message, ContentMode contentMode, ErrorLevel errorLevel) 

Source Link

Document

Creates an error message with level and content mode.

Usage

From source file:dhbw.clippinggorilla.userinterface.views.MenuBar.java

private void logInActions() {
    String usernameOrEmail = username.getValue();
    if (usernameOrEmail.contains("@")) {
        usernameOrEmail = usernameOrEmail.toLowerCase();
    }/*from w  w  w.j  a  va  2s.  c  o m*/
    HashMap<Integer, User> state = UserUtils.loginUser(usernameOrEmail, password.getValue());
    int stateInt = state.keySet().iterator().next();
    UserUtils.setCurrentUser(state.get(stateInt));
    String errorMsg = null;
    switch (stateInt) {
    case 0://successful
        password.setValue("");
        User user = state.get(stateInt);
        login.setComponentError(null);
        profile.setComponentError(null);
        groups.setComponentError(null);

        changeItems(MenuBarState.LOGIN);

        logoClick = logo.addClickListener(
                ce -> ClippingGorillaUI.getCurrent().setMainContent(ClippingView.getCurrent()));
        userBar.removeItems();
        MenuItem userMenu = userBar.addItem(user.getFirstName().charAt(0) + ". " + user.getLastName(), null);
        MenuItem subSettingsItem = userMenu.addItem(Language.get(Word.SETTINGS), VaadinIcons.COG,
                e -> UI.getCurrent().addWindow(PreferencesWindow.get(user)));
        Language.setCustom(Word.SETTINGS, s -> subSettingsItem.setText(s));
        MenuItem subArchiveItem = userMenu.addItem(Language.get(Word.ARCHIVE), VaadinIcons.ARCHIVE,
                e -> ClippingGorillaUI.getCurrent().setMainContent(ArchiveView.create()));
        Language.setCustom(Word.ARCHIVE, s -> subArchiveItem.setText(s));
        if (user.getAccessLevel() > 89) {
            MenuItem subAddSourceIcon = userMenu.addItem(Language.get(Word.MANAGE_SOURCES),
                    VaadinIcons.NEWSPAPER,
                    e -> ClippingGorillaUI.getCurrent().addWindow(ManageSourcesWindow.create()));
            Language.setCustom(Word.MANAGE_SOURCES, s -> subAddSourceIcon.setText(s));
        }
        MenuItem subLogoutItem = userMenu.addItem(Language.get(Word.SIGN_OUT), VaadinIcons.POWER_OFF, e -> {
            logOutActions();
        });
        Language.setCustom(Word.SIGN_OUT, s -> subLogoutItem.setText(s));

        ClippingGorillaUI.getCurrent().setMainContent(ClippingView.getCurrent());
        break;
    case -1://not found
    case -2://not match
        password.setValue("");
        errorMsg = Language.get(Word.WRONG_USERNAME_OR_PASSWORD);
        changeItems(MenuBarState.PW_FORGOTTEN);
        break;
    case -3://not activated
        errorMsg = Language.get(Word.NEEDS_ACTIVATION);
        UI.getCurrent().addWindow(ActivateWindow.get());
        break;
    case -4://banned
        password.setValue("");
        errorMsg = Language.get(Word.BANNED);
        break;
    default:
        password.setValue("");
        errorMsg = Language.get(Word.LOGIN_FAILED);
    }
    if (errorMsg != null) {
        VaadinUtils.errorNotification(errorMsg);
        login.setComponentError(
                new UserError(errorMsg, AbstractErrorMessage.ContentMode.TEXT, ErrorMessage.ErrorLevel.ERROR));
    }
}

From source file:dhbw.clippinggorilla.userinterface.windows.ActivateWindow.java

public static Window get() {
    Window window = new Window();
    window.setModal(true);//w  w w  . java  2s.  c o m
    window.setResizable(false);
    window.setDraggable(false);
    window.setCaption(Language.get(Word.ACTIVATION_CODE));
    window.addCloseShortcut(ShortcutAction.KeyCode.ENTER, null);

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setMargin(false);
    windowLayout.setSizeUndefined();

    FormLayout forms = new FormLayout();
    forms.setMargin(true);
    forms.setSizeUndefined();

    Button save = new Button(Language.get(Word.ACTIVATE));

    TextField activationCode = new TextField(Language.get(Word.ACTIVATION_CODE));
    activationCode.setMaxLength(6);
    activationCode.focus();
    activationCode.addValueChangeListener(e -> {
        if (activationCode.getValue().length() > 5) {
            save.setEnabled(true);
            activationCode.setComponentError(null);
        } else {
            save.setEnabled(false);
            activationCode.setComponentError(new UserError(Language.get(Word.ACTIVATION_CODE_SIX_CHARS),
                    AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_CODE_SIX_CHARS));
        }
    });
    forms.addComponent(activationCode);

    Button resendMail = new Button(Language.get(Word.RESEND_ACTIVATION_CODE));
    resendMail.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
    resendMail.addClickListener(ce -> {
        try {
            UserUtils.resendActivationMail(UserUtils.getCurrent());
            VaadinUtils.infoNotification(Language.get(Word.RESEND_ACTIVATION_CODE_SUCCESSFUL));
        } catch (EmailException ex) {
            VaadinUtils.errorNotification(Language.get(Word.RESEND_ACTIVATION_CODE_FAILED));
        }
    });
    forms.addComponent(resendMail);

    GridLayout footer = new GridLayout(3, 1);
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth(100.0f, Sizeable.Unit.PERCENTAGE);

    Label placeholder = new Label();

    Button cancel = new Button(Language.get(Word.CANCEL));
    cancel.setIcon(VaadinIcons.CLOSE);
    cancel.addClickListener(ce -> {
        window.close();
    });
    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);

    save.setEnabled(false);
    save.setIcon(VaadinIcons.CHECK);
    save.addStyleName(ValoTheme.BUTTON_PRIMARY);
    save.addClickListener(ce -> {
        try {
            String code = activationCode.getValue();
            User user = UserUtils.getCurrent();
            if (UserUtils.activateUser(user, code)) {
                VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_SUCCESSFUL));
                window.close();
            } else {
                activationCode.setValue("");
                VaadinUtils.errorNotification(Language.get(Word.ACTIVATION_FAILED));
            }
        } catch (NumberFormatException e) {
        }
    });
    save.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    footer.setSizeUndefined();
    footer.setWidth("100%");
    footer.addComponents(placeholder, cancel, save);
    footer.setColumnExpandRatio(0, 1);//ExpandRatio(placeholder, 1);
    footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(save, Alignment.MIDDLE_CENTER);

    windowLayout.addComponent(forms);
    windowLayout.addComponent(footer);

    window.setContent(windowLayout);
    return window;
}

From source file:dhbw.clippinggorilla.userinterface.windows.PasswordRecoveryWindow.java

public void changeWindow() {
    String errorMsg;//ww w. ja v a2 s.  com
    if (emailOrUsername.getValue().contains("@")) {
        errorMsg = UserUtils.checkEmailOnFormalCorrectness(emailOrUsername.getValue().toLowerCase());
    } else {
        errorMsg = UserUtils.checkUsernameOnFormalCorrectness(emailOrUsername.getValue());
    }

    if (errorMsg.isEmpty()) {
        VaadinUtils.middleInfoNotification(Language.get(Word.IF_USER_EXIST_CHECK_MAIL));
        try {
            String stringEmailOrUsername = emailOrUsername.getValue();
            if (stringEmailOrUsername.contains("@")) {
                stringEmailOrUsername = stringEmailOrUsername.toLowerCase();
            }
            String token = UserUtils.initiateForgottenPasswordRecovery(stringEmailOrUsername);
            forms.removeAllComponents();

            TextField resetCode = new TextField(Language.get(Word.RESET_CODE));
            resetCode.setMaxLength(6);
            resetCode.addValueChangeListener(e -> {
                if (resetCode.getValue().length() > 5) {
                    resetCode.setComponentError(null);
                    setError(resetCode, false);
                } else {
                    resetCode.setComponentError(new UserError(Language.get(Word.RESET_CODE_SIX_CHARS),
                            AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
                    VaadinUtils.infoNotification(Language.get(Word.RESET_CODE_SIX_CHARS));
                    setError(resetCode, true);
                }
            });

            ProgressBar strength = new ProgressBar();

            PasswordField pw1 = new PasswordField(Language.get(Word.PASSWORD));
            pw1.setMaxLength(51);
            pw1.addValueChangeListener(e -> {
                String pwErrorMsg = UserUtils.checkPassword(e.getValue());
                strength.setValue(UserUtils.calculatePasswordStrength(e.getValue()));
                if (!pwErrorMsg.isEmpty()) {
                    pw1.setComponentError(new UserError(pwErrorMsg, AbstractErrorMessage.ContentMode.HTML,
                            ErrorMessage.ErrorLevel.ERROR));
                    VaadinUtils.infoNotification(pwErrorMsg);
                    setError(pw1, true);
                } else {
                    pw1.setComponentError(null);
                    setError(pw1, false);
                }
            });

            strength.setWidth("184px");
            strength.setHeight("1px");

            PasswordField pw2 = new PasswordField(Language.get(Word.PASSWORD_AGAIN));
            pw2.setMaxLength(51);
            pw2.addValueChangeListener(e -> {
                String pwErrorMsg = UserUtils.checkSecondPassword(pw1.getValue(), e.getValue());
                if (!pwErrorMsg.isEmpty()) {
                    pw2.setComponentError(new UserError(pwErrorMsg, AbstractErrorMessage.ContentMode.HTML,
                            ErrorMessage.ErrorLevel.ERROR));
                    VaadinUtils.infoNotification(pwErrorMsg);
                    setError(pw2, true);
                } else {
                    pw2.setComponentError(null);
                    setError(pw2, false);
                }
            });

            send.setCaption(Language.get(Word.RESET));
            send.setEnabled(false);
            sendListener.remove();
            send.addClickListener(ce -> {
                try {
                    UserUtils.executeForgottenPasswordRecovery(emailOrUsername.getValue(), resetCode.getValue(),
                            token, pw1.getValue(), pw2.getValue());
                    VaadinUtils.infoNotification(Language.get(Word.RESET_SUCCESSFUL));
                    close();
                } catch (PasswordChangeException ex) {
                    VaadinUtils.infoNotification(Language.get(Word.RESET_FAILED));
                }
            });
            forms.addComponents(resetCode, pw1, strength, pw2);
            center();
        } catch (UserNotFoundException e) {
            VaadinUtils.errorNotification(Language.get(Word.RESET_FAILED));
        }
    } else {
        VaadinUtils.infoNotification(errorMsg);
    }
}

From source file:dhbw.clippinggorilla.userinterface.windows.PreferencesWindow.java

private Component buildUserTab(User user) {
    HorizontalLayout root = new HorizontalLayout();
    root.setCaption(Language.get(Word.PROFILE));
    root.setIcon(VaadinIcons.USER);/*from  w w  w.j  a v  a 2 s.  c  om*/
    root.setWidth("100%");
    root.setSpacing(true);
    root.setMargin(true);

    FormLayout details = new FormLayout();
    details.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    root.addComponent(details);

    firstNameField = new TextField(Language.get(Word.FIRST_NAME));
    firstNameField.setValue(user.getFirstName());
    firstNameField.setMaxLength(20);
    firstNameField.addValueChangeListener(event -> {
        String firstNameError = UserUtils.checkName(event.getValue());
        if (!firstNameError.isEmpty()) {
            firstNameField.setComponentError(new UserError(firstNameError,
                    AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(firstNameError);
            saveButton.setEnabled(setError(firstNameField, true));
        } else {
            firstNameField.setComponentError(null);
            boolean enabled = setError(firstNameField, false);
            saveButton.setEnabled(enabled);
        }
    });
    setError(firstNameField, false);

    lastNameField = new TextField(Language.get(Word.LAST_NAME));
    lastNameField.setValue(user.getLastName());
    lastNameField.setMaxLength(20);
    lastNameField.addValueChangeListener(event -> {
        String lastNameError = UserUtils.checkName(event.getValue());
        if (!lastNameError.isEmpty()) {
            lastNameField.setComponentError(new UserError(lastNameError, AbstractErrorMessage.ContentMode.HTML,
                    ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(lastNameError);
            saveButton.setEnabled(setError(lastNameField, true));
        } else {
            lastNameField.setComponentError(null);
            saveButton.setEnabled(setError(lastNameField, false));
        }
    });
    setError(lastNameField, false);

    usernameField = new TextField(Language.get(Word.USERNAME));
    usernameField.setValue(user.getUsername());
    usernameField.setMaxLength(20);
    usernameField.addValueChangeListener(event -> {
        if (!event.getValue().equals(user.getUsername())) {
            String userNameError = UserUtils.checkUsername(event.getValue());
            if (!userNameError.isEmpty()) {
                usernameField.setComponentError(new UserError(userNameError,
                        AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
                VaadinUtils.infoNotification(userNameError);
                saveButton.setEnabled(setError(usernameField, true));
            } else {
                usernameField.setComponentError(null);
                saveButton.setEnabled(setError(usernameField, false));
            }
        } else {
            usernameField.setComponentError(null);
            saveButton.setEnabled(setError(usernameField, false));
        }
    });
    setError(usernameField, false);

    emailField = new TextField(Language.get(Word.EMAIL));
    emailField.setValue(user.getEmail());
    emailField.setMaxLength(256);
    emailField.addValueChangeListener(event -> {
        if (!event.getValue().equals(user.getEmail())) {
            String email1Error = UserUtils.checkEmail(event.getValue().toLowerCase());
            if (!email1Error.isEmpty()) {
                emailField.setComponentError(new UserError(email1Error, AbstractErrorMessage.ContentMode.HTML,
                        ErrorMessage.ErrorLevel.INFORMATION));
                VaadinUtils.infoNotification(email1Error);
                saveButton.setEnabled(setError(emailField, true));
            } else {
                emailField.setComponentError(null);
                saveButton.setEnabled(setError(emailField, false));
            }
        } else {
            emailField.setComponentError(null);
            saveButton.setEnabled(setError(emailField, false));
        }
    });
    setError(emailField, false);

    oldPasswordField = new PasswordField(Language.get(Word.OLD_PASSWORD));
    oldPasswordField.setValue("");
    oldPasswordField.setMaxLength(51);
    oldPasswordField.addValueChangeListener(event -> {
        if (!event.getValue().isEmpty()) {
            String password1Error = UserUtils.checkPassword(event.getValue());
            if (!password1Error.isEmpty()) {
                oldPasswordField.setComponentError(new UserError(password1Error,
                        AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
                VaadinUtils.infoNotification(password1Error);
                saveButton.setEnabled(setError(oldPasswordField, true));
            } else {
                oldPasswordField.setComponentError(null);
                saveButton.setEnabled(setError(oldPasswordField, false));
            }
        } else {
            oldPasswordField.setComponentError(null);
            saveButton.setEnabled(setError(oldPasswordField, false));
        }
    });
    setError(oldPasswordField, false);

    ProgressBar strength = new ProgressBar();

    password1Field = new PasswordField(Language.get(Word.PASSWORD));
    password1Field.setValue("");
    password1Field.setMaxLength(51);
    password1Field.addValueChangeListener(event -> {
        if (!event.getValue().isEmpty()) {
            String password1Error = UserUtils.checkPassword(event.getValue());
            strength.setValue(UserUtils.calculatePasswordStrength(event.getValue()));
            if (!password1Error.isEmpty()) {
                password1Field.setComponentError(new UserError(password1Error,
                        AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
                VaadinUtils.infoNotification(password1Error);
                saveButton.setEnabled(setError(password1Field, true));
            } else {
                password1Field.setComponentError(null);
                saveButton.setEnabled(setError(password1Field, false));
            }
        } else {
            password1Field.setComponentError(null);
            saveButton.setEnabled(setError(password1Field, false));
        }
    });
    setError(password1Field, false);

    strength.setWidth("184px");
    strength.setHeight("1px");

    password2Field = new PasswordField(Language.get(Word.PASSWORD_AGAIN));
    password2Field.setValue("");
    password2Field.setMaxLength(51);
    password2Field.addValueChangeListener(event -> {
        if (!event.getValue().isEmpty()) {
            String password2Error = UserUtils.checkPassword(event.getValue())
                    + UserUtils.checkSecondPassword(password1Field.getValue(), event.getValue());
            if (!password2Error.isEmpty()) {
                password2Field.setComponentError(new UserError(password2Error,
                        AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
                VaadinUtils.infoNotification(password2Error);
                saveButton.setEnabled(setError(password2Field, true));
            } else {
                password2Field.setComponentError(null);
                saveButton.setEnabled(setError(password2Field, false));
            }
        } else {
            password2Field.setComponentError(null);
            saveButton.setEnabled(setError(password2Field, false));
        }
    });
    setError(password2Field, false);

    details.addComponents(firstNameField, lastNameField, usernameField, emailField, oldPasswordField,
            password1Field, strength, password2Field);

    return root;
}

From source file:dhbw.clippinggorilla.userinterface.windows.RegisterWindow.java

public RegisterWindow() {
    setModal(true);/*from ww w .  ja  v a2  s  .c o  m*/
    setResizable(false);
    setDraggable(false);
    setCaption(Language.get(Word.REGISTER));
    addCloseShortcut(KeyCode.ENTER, null);

    Button save = new Button(Language.get(Word.REGISTER));

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setMargin(false);
    windowLayout.setSizeUndefined();

    FormLayout forms = new FormLayout();
    forms.setMargin(true);
    forms.setSizeUndefined();

    TextField firstName = new TextField(Language.get(Word.FIRST_NAME));
    firstName.focus();
    firstName.setMaxLength(20);
    firstName.addValueChangeListener(event -> {
        String firstNameError = UserUtils.checkName(event.getValue());
        if (!firstNameError.isEmpty()) {
            firstName.setComponentError(new UserError(firstNameError, AbstractErrorMessage.ContentMode.HTML,
                    ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(firstNameError);
            save.setEnabled(setError(firstName, true));
        } else {
            firstName.setComponentError(null);
            boolean enabled = setError(firstName, false);
            save.setEnabled(enabled);
        }
    });
    forms.addComponent(firstName);

    TextField lastName = new TextField(Language.get(Word.LAST_NAME));
    lastName.setMaxLength(20);
    lastName.addValueChangeListener(event -> {
        String lastNameError = UserUtils.checkName(event.getValue());
        if (!lastNameError.isEmpty()) {
            lastName.setComponentError(new UserError(lastNameError, AbstractErrorMessage.ContentMode.HTML,
                    ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(lastNameError);
            save.setEnabled(setError(lastName, true));
        } else {
            lastName.setComponentError(null);
            save.setEnabled(setError(lastName, false));
        }
    });
    forms.addComponent(lastName);

    TextField userName = new TextField(Language.get(Word.USERNAME));
    userName.setMaxLength(20);
    userName.addValueChangeListener(event -> {
        String userNameError = UserUtils.checkUsername(event.getValue());
        if (!userNameError.isEmpty()) {
            userName.setComponentError(new UserError(userNameError, AbstractErrorMessage.ContentMode.HTML,
                    ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(userNameError);
            save.setEnabled(setError(userName, true));
        } else {
            userName.setComponentError(null);
            save.setEnabled(setError(userName, false));

        }
    });
    forms.addComponent(userName);

    TextField email1 = new TextField(Language.get(Word.EMAIL));
    email1.setMaxLength(256);
    email1.addValueChangeListener(event -> {
        String email1Error = UserUtils.checkEmail(event.getValue().toLowerCase());
        if (!email1Error.isEmpty()) {
            email1.setComponentError(new UserError(email1Error, AbstractErrorMessage.ContentMode.HTML,
                    ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(email1Error);
            save.setEnabled(setError(email1, true));
        } else {
            email1.setComponentError(null);
            save.setEnabled(setError(email1, false));
        }
    });
    forms.addComponent(email1);

    TextField email2 = new TextField(Language.get(Word.EMAIL_AGAIN));
    email2.setMaxLength(256);
    email2.addValueChangeListener(event -> {
        String email2Error = UserUtils.checkEmail(event.getValue().toLowerCase())
                + UserUtils.checkSecondEmail(email1.getValue().toLowerCase(), event.getValue().toLowerCase());
        if (!email2Error.isEmpty()) {
            email2.setComponentError(new UserError(email2Error, AbstractErrorMessage.ContentMode.HTML,
                    ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(email2Error);
            save.setEnabled(setError(email2, true));
        } else {
            email2.setComponentError(null);
            save.setEnabled(setError(email2, false));
        }
    });
    forms.addComponent(email2);

    ProgressBar strength = new ProgressBar();

    PasswordField password1 = new PasswordField(Language.get(Word.PASSWORD));
    password1.setMaxLength(51);
    password1.addValueChangeListener(event -> {
        String password1Error = UserUtils.checkPassword(event.getValue());
        strength.setValue(UserUtils.calculatePasswordStrength(event.getValue()));
        if (!password1Error.isEmpty()) {
            password1.setComponentError(new UserError(password1Error, AbstractErrorMessage.ContentMode.HTML,
                    ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(password1Error);
            save.setEnabled(setError(password1, true));
        } else {
            password1.setComponentError(null);
            save.setEnabled(setError(password1, false));
        }

    });
    forms.addComponent(password1);

    strength.setWidth("184px");
    strength.setHeight("1px");
    forms.addComponent(strength);

    PasswordField password2 = new PasswordField(Language.get(Word.PASSWORD_AGAIN));
    password2.setMaxLength(51);
    password2.addValueChangeListener(event -> {
        String password2Error = UserUtils.checkPassword(event.getValue())
                + UserUtils.checkSecondPassword(password1.getValue(), event.getValue());
        if (!password2Error.isEmpty()) {
            password2.setComponentError(new UserError(password2Error, AbstractErrorMessage.ContentMode.HTML,
                    ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(password2Error);
            save.setEnabled(setError(password2, true));
        } else {
            password2.setComponentError(null);
            save.setEnabled(setError(password2, false));
        }
    });
    forms.addComponent(password2);

    GridLayout footer = new GridLayout(3, 1);
    footer.setSpacing(true);
    footer.setSizeUndefined();
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth(100.0f, Unit.PERCENTAGE);

    Label placeholder = new Label();

    Button cancel = new Button(Language.get(Word.CANCEL));
    cancel.setIcon(VaadinIcons.CLOSE);
    cancel.addClickListener(ce -> {
        close();
    });
    cancel.setClickShortcut(KeyCode.ESCAPE, null);

    save.setEnabled(false);
    save.setIcon(VaadinIcons.CHECK);
    save.addStyleName(ValoTheme.BUTTON_PRIMARY);
    save.addClickListener(ce -> {
        try {
            User user = UserUtils.registerUser(userName.getValue(), password1.getValue(), password2.getValue(),
                    email1.getValue().toLowerCase(), email2.getValue().toLowerCase(), firstName.getValue(),
                    lastName.getValue());
            UserUtils.setCurrentUser(user);
            close();
            UI.getCurrent().addWindow(ActivateWindow.get());
        } catch (UserCreationException ex) {
            Log.error("Registration failed", ex);
            VaadinUtils.errorNotification(Language.get(Word.REG_FAILED));
        }
    });
    save.setClickShortcut(KeyCode.ENTER, null);

    footer.addComponents(placeholder, cancel, save);
    footer.setColumnExpandRatio(0, 1);//ExpandRatio(placeholder, 1);
    footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(save, Alignment.MIDDLE_CENTER);

    windowLayout.addComponent(forms);
    windowLayout.addComponent(footer);

    setContent(windowLayout);
}

From source file:edu.kit.dama.ui.admin.workflow.DataWorkflowTaskConfigurationTab.java

License:Apache License

/**
 * Create a new workflow configuration using the values from the UI.
 *
 * @param pName The configuration name./*from  w  ww  .  java2  s.c om*/
 */
private void createNewWorkflowConfiguration(String pName) {
    IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager();
    mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext());
    boolean result = false;

    if (getWorkflowVersion(pName) > 0) {
        UIComponentTools.showWarning("There is already a workflow configuration named '" + pName
                + "' registered. " + "Please select another name to proceed.");
        return;
    }
    if (pName.contains("@")) {
        getBasicPropertiesLayout().getNameField().setComponentError(
                new UserError("Data workflow configuration names may not contain the @ character.",
                        AbstractErrorMessage.ContentMode.TEXT, ErrorMessage.ErrorLevel.WARNING));
        return;
    } else {
        getBasicPropertiesLayout().getNameField().setComponentError(null);
    }

    try {
        LOGGER.debug("Creating new workflow configuration from UI.");
        selection = new DataWorkflowTaskConfiguration();
        selection.setName(pName);
        selection.setGroupId((String) getBasicPropertiesLayout().getGroupBox().getValue());
        String contactUserId = (String) getBasicPropertiesLayout().getContactBox().getValue();
        if (!checkContactUserId(contactUserId)) {
            return;
        }

        String applicationUrl = getBasicPropertiesLayout().getApplicationPackageUrlField().getValue();

        try {
            LOGGER.debug("Successfully validated application package URL {}", new URL(applicationUrl));
        } catch (MalformedURLException ex) {
            UIComponentTools.showWarning("The provided application package URL is invalid.");
            return;
        }

        selection.setApplicationPackageUrl(
                getBasicPropertiesLayout().getApplicationPackageUrlField().getValue());

        selection.setApplicationArguments(getBasicPropertiesLayout().getApplicationArgumentsField().getValue());
        selection.setVersion(1);
        selection.setContactUserId((String) getBasicPropertiesLayout().getContactBox().getValue());
        LOGGER.debug("Setting other attributes.");
        selection.setKeywords(getBasicPropertiesLayout().getKeywordsField().getValue());
        selection.setDescription(getBasicPropertiesLayout().getDescriptionArea().getValue());
        //            selection.setDisabled(getBasicPropertiesLayout().getDisabledBox().getValue());
        //            selection.setDefaultTask(getBasicPropertiesLayout().getDefaultBox().getValue());
        LOGGER.debug("Updating environment requirements.");
        selection.removeRequiredEnvironmentProperties();
        Set<Object> environmentProperties = (Set<Object>) getBasicPropertiesLayout()
                .getEnvironmentPropertiesSelect().getValue();
        for (Object propId : environmentProperties) {
            ExecutionEnvironmentProperty property = mdm.find(ExecutionEnvironmentProperty.class, propId);
            if (property == null) {
                LOGGER.warn("Failed to add environment property with id {}. Entry not found in database.",
                        propId);
                return;
            } else {
                selection.addRequiredEnvironmentProperty(property);
            }
        }
        LOGGER.debug("Saving new workflow configuration.");
        selection = mdm.save(selection);
        LOGGER.debug("Workflow configuration '{}' successully saved.", pName);
        result = true;
    } catch (UnauthorizedAccessAttemptException ex) {
        LOGGER.error("Not authorized to obtain data workflow configuration for id " + selection.getId(), ex);
    } finally {
        mdm.close();
    }
    if (result) {
        addNewElementInstance(selection);
    }

}

From source file:edu.kit.dama.ui.admin.workflow.DataWorkflowTaskConfigurationTab.java

License:Apache License

/**
 * Check the provided userId. If the user id exists and the max. role is
 * {@link edu.kit.dama.authorization.entities.Role#MEMBER}, TRUE is
 * returned. Otherwise, FALSE is returned and the cause of the failed check
 * is set as component error to the userId input field of the according
 * properties UI.//from w w w .j a v  a  2  s  . com
 *
 * @param pUserId The userId to check.
 *
 * @return TRUE if the user exists and has a proper max. role, FALSE
 * otherwise.
 */
private boolean checkContactUserId(String pUserId) {
    boolean result = true;
    LOGGER.debug("Checking contact user id {}.", pUserId);
    if (pUserId != null) {
        try {
            IRoleRestriction<Role> role = UserServiceLocal.getSingleton()
                    .getRoleRestriction(new UserId(pUserId), AuthorizationContext.factorySystemContext());
            if (!role.atLeast(Role.MEMBER)) {
                LOGGER.warn("Invalid contact userId '{}'. MaxRole is lower than MEMBER.", pUserId);
                getBasicPropertiesLayout().getContactBox()
                        .setComponentError(new UserError("User has insufficient permissions (role < MEMBER).",
                                AbstractErrorMessage.ContentMode.TEXT, ErrorMessage.ErrorLevel.WARNING));
                result = false;
            }
        } catch (UnauthorizedAccessAttemptException ex) {
            LOGGER.error("Failed to check contact userId. SystemContext is not authorized.", ex);
            getBasicPropertiesLayout().getContactBox()
                    .setComponentError(new UserError("Failed to check for user id '" + pUserId + "'",
                            AbstractErrorMessage.ContentMode.TEXT, ErrorMessage.ErrorLevel.WARNING));
            result = false;
        } catch (EntityNotFoundException ex) {
            LOGGER.warn("Invalid contact userId '{}'. UserId not found.", pUserId);
            getBasicPropertiesLayout().getContactBox()
                    .setComponentError(new UserError("No valid user id '" + pUserId + "'",
                            AbstractErrorMessage.ContentMode.TEXT, ErrorMessage.ErrorLevel.WARNING));
            result = false;
        }
    }
    if (result) {
        getBasicPropertiesLayout().getContactBox().setComponentError(null);
    }
    return result;
}

From source file:fr.amapj.view.engine.popup.formpopup.validator.ValidatorHolder.java

License:Open Source License

/**
 * Retourne une liste vide si tout est ok, sinon retourne une liste de message d'erreur
 * @return//from  ww w  .  j a  v a 2  s  .  c  om
 */
public List<String> validate() {
    errorMessage = new ArrayList<>();

    Object value = f.getValue();

    validator.performValidate(value, this);

    if (errorMessage.size() > 0) {
        String str = computeHtml();

        f.setComponentError(new UserError(str, ContentMode.HTML, ErrorLevel.ERROR));

        if (validator.canCheckOnFly()) {
            f.addValueChangeListener(e -> handleValueChange());
            AbstractField[] fields = validator.revalidateOnChangeOf();
            if (fields != null) {
                for (AbstractField field : fields) {
                    field.addValueChangeListener(e -> handleValueChange());
                }
            }
        }
    }

    return errorMessage;
}

From source file:fr.amapj.view.engine.popup.formpopup.validator.ValidatorHolder.java

License:Open Source License

private void handleValueChange() {
    errorMessage = new ArrayList<>();

    Object value = f.getValue();//from w ww  .  j  a  v  a 2s. co m

    validator.performValidate(value, this);

    // Si l'erreur a disparu
    if (errorMessage.size() == 0) {
        // On efface l'erreur
        f.setComponentError(null);
    }
    // Sinon on met  jour l'erreur
    else {
        String str = computeHtml();

        f.setComponentError(new UserError(str, ContentMode.HTML, ErrorLevel.ERROR));
    }
}

From source file:org.opencms.ui.contextmenu.CmsContextMenuEditHandler.java

License:Open Source License

/**
 * @see com.vaadin.event.FieldEvents.TextChangeListener#textChange(com.vaadin.event.FieldEvents.TextChangeEvent)
 *//*from  www . ja v a2 s.  co m*/
public void textChange(TextChangeEvent event) {

    TextField tf = (TextField) event.getSource();
    try {
        validate(event.getText());
        tf.setComponentError(null);
    } catch (InvalidValueException e) {
        tf.setComponentError(new UserError(e.getHtmlMessage(), ContentMode.HTML, null));
    }
}