Example usage for org.apache.wicket.markup.html.form Form setMarkupId

List of usage examples for org.apache.wicket.markup.html.form Form setMarkupId

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form setMarkupId.

Prototype

final void setMarkupId(Component comp) 

Source Link

Document

Copy markupId

Usage

From source file:com.axway.ats.testexplorer.pages.reports.compare.CompareRunsPage.java

License:Apache License

public CompareRunsPage(PageParameters parameters) {

    super(parameters);

    final String runIds = extractParameter(parameters, "runIds").replace("_", ",");

    final WebMarkupContainer testsComparisonContainer = new WebMarkupContainer("testsComparison");
    testsComparisonContainer.setOutputMarkupId(true);
    add(testsComparisonContainer);//  w  ww.  ja  va2s  .c  o  m

    Form<Object> testsComparisonForm = new Form<Object>("testsComparisonForm");
    testsComparisonForm.setOutputMarkupId(true);
    testsComparisonForm.setMarkupId("testsComparisonForm");

    List<List<TestcasesTableCell>> testcasesTableModel = getTestcasesTableModel(runIds);
    final ListView<List<TestcasesTableCell>> testcasesTable = getTestcasesTable(testcasesTableModel);
    testsComparisonForm.add(testcasesTable);
    testsComparisonContainer.add(testsComparisonForm);

    AjaxButton applyFilterButton = new AjaxButton("applyFilterButton") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {

            List<List<TestcasesTableCell>> testcasesTableModel = getTestcasesTableModel(runIds);
            testcasesTable.setDefaultModelObject(testcasesTableModel);

            target.add(testsComparisonContainer);
        }
    };
    applyFilterButton.setOutputMarkupId(true);
    applyFilterButton.setMarkupId("applyFilterButton");

    testsComparisonForm.add(applyFilterButton);
    testsComparisonForm.setDefaultButton(applyFilterButton);
}

From source file:de.jetwick.ui.MobilePage.java

License:Apache License

public MobilePage(PageParameters pp) {
    add(new Label("title", "Jetwick Twitter Search . mobile"));
    Form form = new Form("searchform") {

        @Override//from   w  ww .j a  v a2 s .co m
        public void onSubmit() {
            PageParameters params = new PageParameters();
            if (queryString != null && !queryString.isEmpty())
                params.add("q", queryString);
            setResponsePage(MobilePage.class, params);
        }
    };
    form.setMarkupId("queryform");
    add(form);

    TextField textField = new TextField("textField", new PropertyModel(this, "queryString"));
    form.add(textField);

    remoteHost = getWebRequestCycle().getWebRequest().getHttpServletRequest().getRemoteHost();
    queryString = pp.getString("q");
    doSearch();
}

From source file:guru.mmp.application.web.template.pages.ChangePasswordPage.java

License:Apache License

/**
 * Constructs a new <code>ChangePasswordPage</code>.
 *
 * @param username the username/*  www  . j  a va  2 s  .  c o  m*/
 */
ChangePasswordPage(String username) {
    try {
        // Setup the page title
        String title = ((TemplateWebApplication) getApplication()).getDisplayName() + " | Change " + "Password";

        Label titleLabel = new Label("pageTitle", title);
        titleLabel.setRenderBodyOnly(false);
        add(titleLabel);

        // Setup the alerts
        Alerts alerts = new Alerts("alerts");
        add(alerts);

        // Setup the changePasswordForm
        Form<Void> changePasswordForm = new Form<>("changePasswordForm");
        changePasswordForm.setMarkupId("changePasswordForm");
        changePasswordForm.setOutputMarkupId(true);
        add(changePasswordForm);

        // The "oldPassword" field
        PasswordTextField oldPasswordField = new PasswordTextFieldWithFeedback("oldPassword",
                new PropertyModel<>(this, "oldPassword"));
        oldPasswordField.setRequired(true);
        oldPasswordField.add(new DefaultFocusBehavior());
        changePasswordForm.add(oldPasswordField);

        // The "newPassword" field
        PasswordTextField newPasswordField = new PasswordTextFieldWithFeedback("newPassword",
                new PropertyModel<>(this, "newPassword"));
        newPasswordField.setRequired(true);
        newPasswordField.add(StringValidator.minimumLength(6));
        newPasswordField.add(new PasswordPolicyValidator());
        changePasswordForm.add(newPasswordField);

        // The "confirmPassword" field
        PasswordTextField confirmPasswordField = new PasswordTextFieldWithFeedback("confirmPassword",
                new PropertyModel<>(this, "confirmPassword"));
        confirmPasswordField.setRequired(true);
        changePasswordForm.add(confirmPasswordField);

        changePasswordForm.add(new EqualPasswordInputValidator(newPasswordField, confirmPasswordField));

        // The "changePasswordButton" button
        Button changePasswordButton = new Button("changePasswordButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
                try {
                    // Authenticate the user
                    UUID userDirectoryId = securityService.changePassword(username, oldPassword, newPassword);

                    // Retrieve the user details
                    User user = securityService.getUser(userDirectoryId, username);

                    // Initialise the web session for the user
                    WebSession session = getWebApplicationSession();

                    session.setUserDirectoryId(user.getUserDirectoryId());
                    session.setUsername(user.getUsername());
                    session.setUserFullName(user.getFirstName() + " " + user.getLastName());

                    // Make session permanent after login
                    if (session.isTemporary()) {
                        session.bind();
                    } else {
                        session.dirty(); // for cluster replication
                    }

                    // Invalidate the cached navigation state
                    if (session instanceof TemplateWebSession) {
                        ((TemplateWebSession) session).getNavigationState().invalidate();
                    }

                    // Check whether the user is associated with more than 1 organisation
                    List<Organisation> organisations = securityService
                            .getOrganisationsForUserDirectory(userDirectoryId);

                    if (organisations.size() == 0) {
                        error("Authentication Failed.");
                        error(String.format("The user (%s) is not associated with any organisations.",
                                username));
                    } else if (organisations.size() == 1) {
                        List<String> groupNames = securityService.getGroupNamesForUser(userDirectoryId,
                                username);
                        List<String> functionCodes = securityService.getFunctionCodesForUser(userDirectoryId,
                                username);

                        session.setOrganisation(organisations.get(0));
                        session.setGroupNames(groupNames);
                        session.setFunctionCodes(functionCodes);

                        if (logger.isDebugEnabled()) {
                            logger.debug(String.format(
                                    "Successfully authenticated user (%s) for organisation (%s) with groups (%s) "
                                            + "and function codes (%s)",
                                    username, organisations.get(0).getId(), StringUtil.delimit(groupNames, ","),
                                    StringUtil.delimit(functionCodes, ",")));
                        }

                        // Redirect to the secure home page for the application
                        throw new RedirectToUrlException(
                                urlFor(((TemplateWebApplication) getApplication()).getSecureHomePage(),
                                        new PageParameters()).toString());
                    } else {
                        /*
                         * Redirect to the page allowing the user to select which organisation they wish to
                         * work with.
                         */
                        throw new RedirectToUrlException(
                                urlFor(SelectOrganisationPage.class, new PageParameters()).toString());
                    }
                } catch (RedirectToUrlException e) {
                    throw e;
                } catch (ExistingPasswordException e) {
                    error("The specified new password has been used recently.");
                } catch (AuthenticationFailedException | UserNotFoundException e) {
                    error("The specified old password is incorrect.");
                } catch (UserLockedException e) {
                    error("Your user account has been locked.");
                } catch (Throwable e) {
                    logger.error(
                            String.format("Failed to authenticate the user (%s): %s", username, e.getMessage()),
                            e);
                    error("The system is currently unavailable.");
                }
            }
        };

        changePasswordForm.add(changePasswordButton);
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the ChangePasswordPage", e);
    }
}

From source file:guru.mmp.application.web.template.pages.ConfigurationAdministrationPage.java

License:Apache License

/**
 * Constructs a new <code>ConfigurationAdministrationPage</code>.
 *///w w  w  .  ja  v  a 2s  .c o m
public ConfigurationAdministrationPage() {
    super("Configuration");

    try {
        /*
         * The table container, which allows the table and its associated navigator to be updated
         * using AJAX.
         */
        WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer");
        tableContainer.setOutputMarkupId(true);
        add(tableContainer);

        // The dialog used to confirm the removal of a configuration value
        RemoveDialog removeDialog = new RemoveDialog(tableContainer);
        add(removeDialog);

        // The "addLink" used to add a new configuration value
        Link<Void> addLink = new Link<Void>("addLink") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onClick() {
                setResponsePage(new AddConfigurationValuePage(getPageReference()));
            }
        };
        tableContainer.add(addLink);

        FilteredConfigurationValueDataProvider dataProvider = new FilteredConfigurationValueDataProvider();

        // The "filterForm" form
        Form<Void> filterForm = new Form<>("filterForm");
        filterForm.setMarkupId("filterForm");
        filterForm.setOutputMarkupId(true);

        // The "filter" field
        TextField<String> filterField = new TextField<>("filter", new PropertyModel<>(dataProvider, "filter"));
        filterForm.add(filterField);

        // The "filterButton" button
        Button filterButton = new Button("filterButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
            }
        };
        filterButton.setDefaultFormProcessing(true);
        filterForm.add(filterButton);

        // The "resetButton" button
        Button resetButton = new Button("resetButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
                dataProvider.setFilter("");
            }
        };
        filterForm.add(resetButton);

        tableContainer.add(filterForm);

        // The configuration value data view
        DataView<ConfigurationValue> dataView = new DataView<ConfigurationValue>("configurationValue",
                dataProvider) {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void populateItem(Item<ConfigurationValue> item) {
                item.add(new Label("key", new PropertyModel<String>(item.getModel(), "key")));
                item.add(new Label("value", new PropertyModel<String>(item.getModel(), "value")));

                // The "updateLink" link
                Link<Void> updateLink = new Link<Void>("updateLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        UpdateConfigurationValuePage page = new UpdateConfigurationValuePage(getPageReference(),
                                item.getModel());

                        setResponsePage(page);
                    }
                };
                item.add(updateLink);

                // The "removeLink" link
                AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        ConfigurationValue configuration = item.getModelObject();

                        if (configuration != null) {
                            removeDialog.show(target, configuration);
                        } else {
                            target.add(tableContainer);
                        }
                    }
                };
                item.add(removeLink);
            }
        };
        dataView.setItemsPerPage(10);
        dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
        tableContainer.add(dataView);

        tableContainer.add(new PagingNavigator("navigator", dataView));
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the ConfigurationAdministrationPage", e);
    }
}

From source file:guru.mmp.application.web.template.pages.JobAdministrationPage.java

License:Apache License

/**
 * Constructs a new <code>JobAdministrationPage</code>.
 *///from   w w w .j av a  2 s .  c  om
public JobAdministrationPage() {
    super("Scheduler");

    try {
        /*
         * The table container, which allows the table and its associated navigator to be updated
         * using AJAX.
         */
        WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer");
        tableContainer.setOutputMarkupId(true);
        add(tableContainer);

        // The dialog used to confirm the removal of a job
        RemoveDialog removeDialog = new RemoveDialog(tableContainer);
        add(removeDialog);

        // The "addLink" used to add a new job
        Link<Void> addLink = new Link<Void>("addLink") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onClick() {
                AddJobPage page = new AddJobPage(getPageReference());

                setResponsePage(page);
            }
        };
        tableContainer.add(addLink);

        FilteredJobDataProvider dataProvider = new FilteredJobDataProvider();

        // The "filterForm" form
        Form<Void> filterForm = new Form<>("filterForm");
        filterForm.setMarkupId("filterForm");
        filterForm.setOutputMarkupId(true);

        // The "filter" field
        TextField<String> filterField = new TextField<>("filter", new PropertyModel<>(dataProvider, "filter"));
        filterForm.add(filterField);

        // The "filterButton" button
        Button filterButton = new Button("filterButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
            }
        };
        filterButton.setDefaultFormProcessing(true);
        filterForm.add(filterButton);

        // The "resetButton" button
        Button resetButton = new Button("resetButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
                dataProvider.setFilter("");
            }
        };
        filterForm.add(resetButton);

        tableContainer.add(filterForm);

        // The job data view
        DataView<Job> dataView = new DataView<Job>("job", dataProvider) {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void populateItem(Item<Job> item) {
                item.add(new Label("name", new PropertyModel<String>(item.getModel(), "name")));
                item.add(new Label("jobClass", new PropertyModel<String>(item.getModel(), "jobClass")));
                item.add(DateLabel.forDatePattern("nextExecution",
                        new PropertyModel<>(item.getModel(), "nextExecution"), "YYYY-MM-dd hh:mm a"));

                // The "parametersLink" link
                Link<Void> parametersLink = new Link<Void>("parametersLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        //            Job job = item.getModelObject();

                        //            JobParametersPage page = new JobParametersPage(getPageReference(), job.getId());
                        //
                        //            setResponsePage(page);
                    }
                };
                item.add(parametersLink);

                // The "updateLink" link
                Link<Void> updateLink = new Link<Void>("updateLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        UpdateJobPage page = new UpdateJobPage(getPageReference(), item.getModel());

                        setResponsePage(page);
                    }
                };
                item.add(updateLink);

                // The "removeLink" link
                AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        Job job = item.getModelObject();

                        if (job != null) {
                            removeDialog.show(target, job);
                        } else {
                            target.add(tableContainer);
                        }
                    }
                };
                item.add(removeLink);
            }
        };
        dataView.setItemsPerPage(10);
        dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
        tableContainer.add(dataView);

        tableContainer.add(new PagingNavigator("navigator", dataView));
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the JobAdministrationPage", e);
    }
}

From source file:guru.mmp.application.web.template.pages.LoginPage.java

License:Apache License

/**
 * Constructs a new <code>LoginPage</code>.
 *//* w  w w . ja v a2 s .c o m*/
public LoginPage() {
    try {
        // Setup the page title
        String title = ((TemplateWebApplication) getApplication()).getDisplayName() + " | Login";

        Label titleLabel = new Label("pageTitle", title);
        titleLabel.setRenderBodyOnly(false);
        add(titleLabel);

        // Setup the alerts
        Alerts alerts = new Alerts("alerts");
        add(alerts);

        // Setup the loginForm
        Form<Void> loginForm = new Form<>("loginForm");
        loginForm.setMarkupId("loginForm");
        loginForm.setOutputMarkupId(true);
        add(loginForm);

        // The "username" field
        TextField<String> usernameField = new TextFieldWithFeedback<>("username",
                new PropertyModel<>(this, "username"));
        usernameField.setRequired(true);
        usernameField.add(new DefaultFocusBehavior());
        loginForm.add(usernameField);

        // The "password" field
        PasswordTextField passwordField = new PasswordTextFieldWithFeedback("password",
                new PropertyModel<>(this, "password"));
        passwordField.setRequired(true);
        loginForm.add(passwordField);

        // The "loginButton" button
        Button loginButton = new Button("loginButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
                try {
                    if (Debug.inDebugMode() && ("s".equals(username))) {
                        username = "Administrator";
                        password = "Password1";
                    }

                    // Authenticate the user
                    UUID userDirectoryId = securityService.authenticate(username, password);

                    // Retrieve the user details
                    User user = securityService.getUser(userDirectoryId, username);

                    // Initialise the web session for the user
                    WebSession session = getWebApplicationSession();

                    session.setUserDirectoryId(user.getUserDirectoryId());
                    session.setUsername(user.getUsername());
                    session.setUserFullName(user.getFirstName() + " " + user.getLastName());

                    // Make session permanent after login
                    if (session.isTemporary()) {
                        session.bind();
                    } else {
                        session.dirty(); // for cluster replication
                    }

                    // Invalidate the cached navigation state
                    if (session instanceof TemplateWebSession) {
                        ((TemplateWebSession) session).getNavigationState().invalidate();
                    }

                    // Check whether the user is associated with more than 1 organisation
                    List<Organisation> organisations = securityService
                            .getOrganisationsForUserDirectory(userDirectoryId);

                    if (organisations.size() == 0) {
                        error(String.format("The user (%s) is not associated with any organisations.",
                                username));
                    } else if (organisations.size() == 1) {
                        Organisation organisation = organisations.get(0);

                        if (organisation.getStatus() != OrganisationStatus.ACTIVE) {
                            error("The organisation (" + organisation.getName() + ") is not active.");

                            return;
                        }

                        List<String> groupNames = securityService.getGroupNamesForUser(userDirectoryId,
                                username);
                        List<String> functionCodes = securityService.getFunctionCodesForUser(userDirectoryId,
                                username);

                        logger.info("The user (" + username + ") is a member of the following groups: "
                                + ((groupNames.size() == 0) ? "None" : StringUtil.delimit(groupNames, ",")));

                        logger.info("The user (" + username + ") has access to the following functions: "
                                + ((functionCodes.size() == 0) ? "None"
                                        : StringUtil.delimit(functionCodes, ",")));

                        session.setOrganisation(organisation);
                        session.setGroupNames(groupNames);
                        session.setFunctionCodes(functionCodes);

                        if (logger.isDebugEnabled()) {
                            logger.debug(String.format(
                                    "Successfully authenticated user (%s) for organisation (%s) with groups (%s) "
                                            + "and function codes (%s)",
                                    username, organisations.get(0).getId(), StringUtil.delimit(groupNames, ","),
                                    StringUtil.delimit(functionCodes, ",")));
                        }

                        // Redirect to the secure home page for the application
                        throw new RedirectToUrlException(
                                urlFor(((TemplateWebApplication) getApplication()).getSecureHomePage(),
                                        new PageParameters()).toString());
                    } else {
                        /*
                         * Redirect to the page allowing the user to select which organisation they wish to
                         * work with.
                         */
                        throw new RedirectToUrlException(
                                urlFor(SelectOrganisationPage.class, new PageParameters()).toString());
                    }
                } catch (RedirectToUrlException e) {
                    throw e;
                } catch (AuthenticationFailedException | UserNotFoundException e) {
                    error("The specified username or password is incorrect.");
                } catch (UserLockedException e) {
                    error("Your user account has been locked.");
                } catch (ExpiredPasswordException e) {
                    getRequestCycle().setResponsePage(new ChangePasswordPage(username));
                } catch (Throwable e) {
                    logger.error(
                            String.format("Failed to authenticate the user (%s): %s", username, e.getMessage()),
                            e);
                    error("The system is currently unavailable.");
                }
            }
        };
        loginForm.add(loginButton);
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the LoginPage", e);
    }
}

From source file:guru.mmp.application.web.template.pages.OrganisationAdministrationPage.java

License:Apache License

/**
 * Constructs a new <code>OrganisationAdministrationPage</code>.
 *//*from   w  ww  . j av  a  2s .c  om*/
public OrganisationAdministrationPage() {
    super("Organisations");

    try {
        /*
         * The table container, which allows the table and its associated navigator to be updated
         * using AJAX.
         */
        WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer");
        tableContainer.setOutputMarkupId(true);
        add(tableContainer);

        // The dialog used to confirm the removal of an organisation
        RemoveDialog removeDialog = new RemoveDialog(tableContainer);
        add(removeDialog);

        // The "addLink" used to add a new organisation
        Link<Void> addLink = new Link<Void>("addLink") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onClick() {
                setResponsePage(new AddOrganisationPage(getPageReference()));
            }
        };
        tableContainer.add(addLink);

        FilteredOrganisationDataProvider dataProvider = new FilteredOrganisationDataProvider();

        // The "filterForm" form
        Form<Void> filterForm = new Form<>("filterForm");
        filterForm.setMarkupId("filterForm");
        filterForm.setOutputMarkupId(true);

        // The "filter" field
        TextField<String> filterField = new TextField<>("filter", new PropertyModel<>(dataProvider, "filter"));
        filterForm.add(filterField);

        // The "filterButton" button
        Button filterButton = new Button("filterButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
            }
        };
        filterButton.setDefaultFormProcessing(true);
        filterForm.add(filterButton);

        // The "resetButton" button
        Button resetButton = new Button("resetButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
                dataProvider.setFilter("");
            }
        };
        filterForm.add(resetButton);

        tableContainer.add(filterForm);

        // The organisation data view
        DataView<Organisation> dataView = new DataView<Organisation>("organisation", dataProvider) {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void populateItem(Item<Organisation> item) {
                item.add(new Label("id", new PropertyModel<String>(item.getModel(), "id")));
                item.add(new Label("name", new PropertyModel<String>(item.getModel(), "name")));

                // The "updateLink" link
                Link<Void> updateLink = new Link<Void>("updateLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        UpdateOrganisationPage page = new UpdateOrganisationPage(getPageReference(),
                                item.getModel());

                        setResponsePage(page);
                    }
                };
                item.add(updateLink);

                // The "removeLink" link
                AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        Organisation organisation = item.getModelObject();

                        if (organisation != null) {
                            removeDialog.show(target, organisation);
                        } else {
                            target.add(tableContainer);
                        }
                    }
                };
                item.add(removeLink);
            }
        };
        dataView.setItemsPerPage(10);
        dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
        tableContainer.add(dataView);

        tableContainer.add(new PagingNavigator("navigator", dataView));
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the OrganisationAdministrationPage", e);
    }
}

From source file:guru.mmp.application.web.template.pages.UserAdministrationPage.java

License:Apache License

/**
 * Constructs a new <code>UserAdministrationPage</code>.
 *///from  w  w  w  .  j  a v  a 2s  .  c  om
public UserAdministrationPage() {
    super("Users");

    try {
        /*
         * Retrieve the list of user directories for the organisation the currently logged on user
         * is associated with and default to the first user directory.
         */
        List<UserDirectory> userDirectories = getUserDirectories();

        userDirectory = userDirectories.get(0);

        /*
         * The table container, which allows the table and its associated navigator to be updated
         * using AJAX.
         */
        WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer");
        tableContainer.setOutputMarkupId(true);
        add(tableContainer);

        // The dialog used to confirm the removal of a user
        RemoveDialog removeDialog = new RemoveDialog(tableContainer);
        add(removeDialog);

        // The "addLink" used to add a new user
        Link<Void> addLink = new Link<Void>("addLink") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onClick() {
                AddUserPage page = new AddUserPage(getPageReference(), userDirectory.getId());

                setResponsePage(page);
            }
        };
        tableContainer.add(addLink);

        FilteredUserDataProvider dataProvider = new FilteredUserDataProvider(userDirectory.getId());

        // The "userDirectoryDropdownMenu" dropdown button
        DropdownMenu<UserDirectory> userDirectoryDropdownMenu = new DropdownMenu<UserDirectory>(
                "userDirectoryDropdownMenu", new PropertyModel<>(this, "userDirectory"), userDirectories,
                "fa fa-users") {
            @Override
            protected String getDisplayValue(UserDirectory menuItem) {
                return menuItem.getName();
            }

            @Override
            protected void onMenuItemSelected(AjaxRequestTarget target, UserDirectory menuItem) {
                dataProvider.setUserDirectoryId(userDirectory.getId());

                if (target != null) {
                    target.add(tableContainer);

                    target.appendJavaScript(
                            "jQuery('[data-toggle=\"tooltip\"]').tooltip({container: 'body', animation: false});");
                }
            }
        };
        userDirectoryDropdownMenu.setVisible(userDirectories.size() > 1);
        tableContainer.add(userDirectoryDropdownMenu);

        // The "filterForm" form
        Form<Void> filterForm = new Form<>("filterForm");
        filterForm.setMarkupId("filterForm");
        filterForm.setOutputMarkupId(true);

        // The "filter" field
        TextField<String> filterField = new TextField<>("filter", new PropertyModel<>(dataProvider, "filter"));
        filterForm.add(filterField);

        // The "filterButton" button
        Button filterButton = new Button("filterButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
            }
        };
        filterButton.setDefaultFormProcessing(true);
        filterForm.add(filterButton);

        // The "resetButton" button
        Button resetButton = new Button("resetButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
                dataProvider.setFilter("");
            }
        };
        filterForm.add(resetButton);

        tableContainer.add(filterForm);

        // The user data view
        DataView<User> dataView = new DataView<User>("user", dataProvider) {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void populateItem(Item<User> item) {
                User user = item.getModelObject();

                item.add(new Label("username", new PropertyModel<String>(item.getModel(), "username")));
                item.add(new Label("firstName", new PropertyModel<String>(item.getModel(), "firstName")));
                item.add(new Label("lastName", new PropertyModel<String>(item.getModel(), "lastName")));

                // The "userGroupsLink" link
                Link<Void> userGroupsLink = new Link<Void>("userGroupsLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        User user = item.getModelObject();

                        if (!user.getUsername().equalsIgnoreCase("Administrator")) {
                            UserGroupsPage page = new UserGroupsPage(getPageReference(), userDirectory.getId(),
                                    user.getUsername());

                            setResponsePage(page);
                        }
                    }
                };
                item.add(userGroupsLink);

                // The "updateLink" link
                Link<Void> updateLink = new Link<Void>("updateLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        User user = item.getModelObject();

                        if (!user.getUsername().equalsIgnoreCase("Administrator")) {
                            UpdateUserPage page = new UpdateUserPage(getPageReference(), item.getModel());

                            setResponsePage(page);
                        }
                    }
                };
                updateLink.setVisible(!user.isReadOnly());
                item.add(updateLink);

                // The "resetPassword" link
                Link<Void> resetPasswordLink = new Link<Void>("resetPasswordLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        ResetUserPasswordPage page = new ResetUserPasswordPage(getPageReference(),
                                new Model<>(item.getModelObject()));

                        setResponsePage(page);
                    }
                };
                resetPasswordLink.setVisible(!user.isReadOnly());
                item.add(resetPasswordLink);

                // The "removeLink" link
                AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        User user = item.getModelObject();

                        if (user != null) {
                            if (!user.getUsername().equalsIgnoreCase("Administrator")) {
                                removeDialog.show(target, user);
                            }
                        } else {
                            target.add(tableContainer);
                        }
                    }
                };
                removeLink.setVisible(!user.isReadOnly());
                item.add(removeLink);
            }
        };
        dataView.setItemsPerPage(10);
        dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
        tableContainer.add(dataView);

        tableContainer.add(new PagingNavigator("navigator", dataView));
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the UserAdministrationPage", e);
    }
}

From source file:guru.mmp.application.web.template.pages.UserDirectoryAdministrationPage.java

License:Apache License

/**
 * Constructs a new <code>UserDirectoryAdministrationPage</code>.
 *//*  w ww  . j a va  2  s.c o  m*/
public UserDirectoryAdministrationPage() {
    super("User Directories");

    try {
        /*
         * The table container, which allows the table and its associated navigator to be updated
         * using AJAX.
         */
        WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer");
        tableContainer.setOutputMarkupId(true);
        add(tableContainer);

        // The dialog used to confirm the removal of a user directory
        RemoveDialog removeDialog = new RemoveDialog(tableContainer);
        add(removeDialog);

        // The dialog used to select the type of user directory being added
        AddDialog selectUserDirectoryTypeDialog = new AddDialog();
        add(selectUserDirectoryTypeDialog);

        // The "addLink" used to add a new user directory
        AjaxLink<Void> addLink = new AjaxLink<Void>("addLink") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onClick(AjaxRequestTarget target) {
                selectUserDirectoryTypeDialog.show(target);
            }
        };
        tableContainer.add(addLink);

        FilteredUserDirectoryDataProvider dataProvider = new FilteredUserDirectoryDataProvider();

        // The "filterForm" form
        Form<Void> filterForm = new Form<>("filterForm");
        filterForm.setMarkupId("filterForm");
        filterForm.setOutputMarkupId(true);

        // The "filter" field
        TextField<String> filterField = new TextField<>("filter", new PropertyModel<>(dataProvider, "filter"));
        filterForm.add(filterField);

        // The "filterButton" button
        Button filterButton = new Button("filterButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
            }
        };
        filterButton.setDefaultFormProcessing(true);
        filterForm.add(filterButton);

        // The "resetButton" button
        Button resetButton = new Button("resetButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
                dataProvider.setFilter("");
            }
        };
        filterForm.add(resetButton);

        tableContainer.add(filterForm);

        // The user directory data view
        DataView<UserDirectory> dataView = new DataView<UserDirectory>("userDirectory", dataProvider) {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void populateItem(Item<UserDirectory> item) {
                item.add(new Label("name", new PropertyModel<String>(item.getModel(), "name")));
                item.add(new Label("type", new PropertyModel<String>(item.getModel(), "type.name")));

                // The "updateLink" link
                Link<Void> updateLink = new Link<Void>("updateLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        UpdateUserDirectoryPage page = new UpdateUserDirectoryPage(getPageReference(),
                                item.getModel());

                        setResponsePage(page);
                    }
                };
                item.add(updateLink);

                // The "removeLink" link
                AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        UserDirectory userDirectory = item.getModelObject();

                        if (userDirectory != null) {
                            removeDialog.show(target, userDirectory);
                        } else {
                            target.add(tableContainer);
                        }
                    }
                };
                item.add(removeLink);
            }
        };
        dataView.setItemsPerPage(10);
        dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
        tableContainer.add(dataView);

        tableContainer.add(new PagingNavigator("navigator", dataView));
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the UserDirectoryAdministrationPage", e);
    }
}

From source file:guru.mmp.application.web.template.pages.UserGroupsPage.java

License:Apache License

/**
 * Constructs a new <code>UserGroupsPage</code>.
 *
 * @param previousPage    the previous page
 * @param userDirectoryId the Universally Unique Identifier (UUID) used to uniquely identify the
 *                        user directory
 * @param username        the username identifying the user
 *//*w w  w. j  av a2 s . c  o m*/
UserGroupsPage(PageReference previousPage, UUID userDirectoryId, String username) {
    super("User Groups", username);

    try {
        /*
         * The table container, which allows the table and its associated navigator to be updated
         * using AJAX.
         */
        WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer");
        tableContainer.setOutputMarkupId(true);
        add(tableContainer);

        // The "backLink" link
        Link<Void> backLink = new Link<Void>("backLink") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onClick() {
                setResponsePage(previousPage.getPage());
            }
        };
        tableContainer.add(backLink);

        // The "addUserToGroupForm" form
        DropDownChoice<String> groupNameField = new DropDownChoice<>("groupName",
                new PropertyModel<>(this, "groupName"), getGroupOptions(userDirectoryId, username));

        groupNameField.setRequired(true);

        Form<Void> addUserToGroupForm = new Form<Void>("addUserToGroupForm") {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void onSubmit() {
                WebSession session = getWebApplicationSession();

                try {
                    securityService.addUserToGroup(userDirectoryId, username, groupName);

                    logger.info(String.format(
                            "User (%s) added the user (%s) to the group (%s) for the user directory (%s)",
                            session.getUsername(), username, groupName, userDirectoryId));

                    groupNameField.setChoices(getGroupOptions(userDirectoryId, username));
                    groupNameField.setModelObject(null);
                } catch (Throwable e) {
                    logger.error(String.format(
                            "Failed to add the user (%s) to the group (%s) for the user directory (%s): %s",
                            username, groupName, userDirectoryId, e.getMessage()), e);

                    UserGroupsPage.this.error(
                            String.format("Failed to add the user %s to the group %s", username, groupName));
                }
            }
        };

        addUserToGroupForm.setMarkupId("addUserToGroupForm");
        addUserToGroupForm.setOutputMarkupId(true);
        tableContainer.add(addUserToGroupForm);

        addUserToGroupForm.add(groupNameField);

        // The group data view
        GroupsForUserDataProvider dataProvider = new GroupsForUserDataProvider(userDirectoryId, username);

        DataView<Group> dataView = new DataView<Group>("group", dataProvider) {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void populateItem(Item<Group> item) {
                Group group = item.getModelObject();

                String name = group.getGroupName();

                item.add(new Label("name", Model.of(name)));

                // The "removeLink" link
                Link<Void> removeLink = new Link<Void>("removeLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        WebSession session = getWebApplicationSession();

                        Group group = item.getModelObject();

                        try {
                            securityService.removeUserFromGroup(userDirectoryId, username,
                                    group.getGroupName());

                            logger.info(String.format(
                                    "User (%s) removed the user (%s) from the group (%s) for the user directory (%s)",
                                    session.getUsername(), username, group.getGroupName(), userDirectoryId));

                            groupNameField.setChoices(getGroupOptions(userDirectoryId, username));
                            groupNameField.setModelObject(null);
                        } catch (Throwable e) {
                            logger.error(String.format(
                                    "Failed to remove the user (%s) from the group (%s) for the user directory (%s)"
                                            + ": %s",
                                    username, group.getGroupName(), userDirectoryId, e.getMessage()), e);

                            UserGroupsPage.this
                                    .error(String.format("Failed to remove the user %s from the group %s",
                                            username, group.getGroupName()));
                        }
                    }
                };
                item.add(removeLink);
            }
        };

        dataView.setItemsPerPage(10);
        dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
        tableContainer.add(dataView);

        tableContainer.add(new PagingNavigator("navigator", dataView));
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the UserGroupsPage", e);
    }
}