Example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow ModalWindow

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow ModalWindow

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow ModalWindow.

Prototype

public ModalWindow(final String id) 

Source Link

Document

Creates a new modal window component.

Usage

From source file:org.apache.syncope.client.console.SyncopeApplication.java

License:Apache License

public void setupNavigationPanel(final WebPage page, final XMLRolesReader xmlRolesReader,
        final boolean notsel) {
    final ModalWindow infoModal = new ModalWindow("infoModal");
    page.add(infoModal);//from   w  ww .  j a v  a  2 s.  com
    infoModal.setInitialWidth(350);
    infoModal.setInitialHeight(300);
    infoModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    infoModal.setCookieName("infoModal");
    infoModal.setPageCreator(new ModalWindow.PageCreator() {

        private static final long serialVersionUID = -7834632442532690940L;

        @Override
        public Page createPage() {
            return new InfoModalPage();
        }
    });

    final AjaxLink<Page> infoLink = new AjaxLink<Page>("infoLink") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            infoModal.show(target);
        }
    };
    page.add(infoLink);

    BookmarkablePageLink<Page> schemaLink = new BookmarkablePageLink<>("schema", Schema.class);
    MetaDataRoleAuthorizationStrategy.authorize(schemaLink, WebPage.ENABLE,
            xmlRolesReader.getEntitlement("Schema", "list"));
    page.add(schemaLink);
    schemaLink.add(new Image("schemaIcon", new ContextRelativeResource(
            IMG_PREFIX + (notsel ? IMG_NOTSEL : StringUtils.EMPTY) + "schema" + Constants.PNG_EXT)));

    BookmarkablePageLink<Page> usersLink = new BookmarkablePageLink<>("users", Users.class);
    MetaDataRoleAuthorizationStrategy.authorize(usersLink, WebPage.ENABLE,
            xmlRolesReader.getEntitlement("Users", "list"));
    page.add(usersLink);
    usersLink.add(new Image("usersIcon", new ContextRelativeResource(
            IMG_PREFIX + (notsel ? IMG_NOTSEL : StringUtils.EMPTY) + "users" + Constants.PNG_EXT)));

    BookmarkablePageLink<Page> groupsLink = new BookmarkablePageLink<>("groups", Groups.class);
    MetaDataRoleAuthorizationStrategy.authorize(groupsLink, WebPage.ENABLE,
            xmlRolesReader.getEntitlement("Groups", "list"));
    page.add(groupsLink);
    groupsLink.add(new Image("groupsIcon", new ContextRelativeResource(
            IMG_PREFIX + (notsel ? IMG_NOTSEL : StringUtils.EMPTY) + "groups" + Constants.PNG_EXT)));

    BookmarkablePageLink<Page> resourcesLink = new BookmarkablePageLink<>("resources", Resources.class);
    MetaDataRoleAuthorizationStrategy.authorize(resourcesLink, WebPage.ENABLE,
            xmlRolesReader.getEntitlement("Resources", "list"));
    page.add(resourcesLink);
    resourcesLink.add(new Image("resourcesIcon", new ContextRelativeResource(
            IMG_PREFIX + (notsel ? IMG_NOTSEL : StringUtils.EMPTY) + "resources" + Constants.PNG_EXT)));

    BookmarkablePageLink<Page> todoLink = new BookmarkablePageLink<>("todo", Todo.class);
    MetaDataRoleAuthorizationStrategy.authorize(todoLink, WebPage.ENABLE,
            xmlRolesReader.getEntitlement("Approval", "list"));
    page.add(todoLink);
    todoLink.add(new Image("todoIcon", new ContextRelativeResource(
            IMG_PREFIX + (notsel ? IMG_NOTSEL : StringUtils.EMPTY) + "todo" + Constants.PNG_EXT)));

    BookmarkablePageLink<Page> reportLink = new BookmarkablePageLink<>("reports", Reports.class);
    MetaDataRoleAuthorizationStrategy.authorize(reportLink, WebPage.ENABLE,
            xmlRolesReader.getEntitlement("Reports", "list"));
    page.add(reportLink);
    reportLink.add(new Image("reportsIcon", new ContextRelativeResource(
            IMG_PREFIX + (notsel ? IMG_NOTSEL : StringUtils.EMPTY) + "reports" + Constants.PNG_EXT)));

    BookmarkablePageLink<Page> configurationLink = new BookmarkablePageLink<>("configuration",
            Configuration.class);
    MetaDataRoleAuthorizationStrategy.authorize(configurationLink, WebPage.ENABLE,
            xmlRolesReader.getEntitlement("Configuration", "list"));
    page.add(configurationLink);
    configurationLink.add(new Image("configurationIcon", new ContextRelativeResource(
            IMG_PREFIX + (notsel ? IMG_NOTSEL : StringUtils.EMPTY) + "configuration" + Constants.PNG_EXT)));

    BookmarkablePageLink<Page> taskLink = new BookmarkablePageLink<>("tasks", Tasks.class);
    MetaDataRoleAuthorizationStrategy.authorize(taskLink, WebPage.ENABLE,
            xmlRolesReader.getEntitlement("Tasks", "list"));
    page.add(taskLink);
    taskLink.add(new Image("tasksIcon", new ContextRelativeResource(
            IMG_PREFIX + (notsel ? IMG_NOTSEL : StringUtils.EMPTY) + "tasks" + Constants.PNG_EXT)));

    page.add(new BookmarkablePageLink<Page>("logout", Logout.class));
}

From source file:org.apache.syncope.client.console.SyncopeApplication.java

License:Apache License

public void setupEditProfileModal(final WebPage page, final UserSelfRestClient userSelfRestClient) {
    // Modal window for editing user profile
    final ModalWindow editProfileModalWin = new ModalWindow("editProfileModal");
    editProfileModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    editProfileModalWin.setInitialHeight(EDIT_PROFILE_WIN_HEIGHT);
    editProfileModalWin.setInitialWidth(EDIT_PROFILE_WIN_WIDTH);
    editProfileModalWin.setCookieName("edit-profile-modal");
    page.add(editProfileModalWin);//  ww  w  .  j  a v  a 2 s.c  o  m

    final AjaxLink<Page> editProfileLink = new AjaxLink<Page>("editProfileLink") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            final UserTO userTO;
            if (SyncopeSession.get().isAuthenticated()) {
                try {
                    userTO = userSelfRestClient.read();
                } catch (Exception e) {
                    throw new WicketRuntimeException(e);
                }
            } else {
                userTO = new UserTO();
            }

            editProfileModalWin.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = -7834632442532690940L;

                @Override
                public Page createPage() {
                    return new UserSelfModalPage(page.getPageReference(), editProfileModalWin, userTO);
                }
            });

            editProfileModalWin.show(target);
        }
    };

    editProfileLink.add(new Label("username", SyncopeSession.get().getUsername()));

    if ("admin".equals(SyncopeSession.get().getUsername())) {
        editProfileLink.setEnabled(false);
    }

    page.add(editProfileLink);
}

From source file:org.apache.syncope.console.pages.ApprovalModalPage.java

License:Apache License

public ApprovalModalPage(final PageReference pageRef, final ModalWindow window, final WorkflowFormTO formTO) {
    super();//from ww w. java 2  s  .  c o m

    IModel<List<WorkflowFormPropertyTO>> formProps = new LoadableDetachableModel<List<WorkflowFormPropertyTO>>() {

        private static final long serialVersionUID = 3169142472626817508L;

        @Override
        protected List<WorkflowFormPropertyTO> load() {
            return formTO.getProperties();
        }
    };

    final ListView<WorkflowFormPropertyTO> propView = new AltListView<WorkflowFormPropertyTO>("propView",
            formProps) {

        private static final long serialVersionUID = 9101744072914090143L;

        @Override
        @SuppressWarnings({ "unchecked", "rawtypes" })
        protected void populateItem(final ListItem<WorkflowFormPropertyTO> item) {
            final WorkflowFormPropertyTO prop = item.getModelObject();

            Label label = new Label("key", prop.getName() == null ? prop.getId() : prop.getName());
            item.add(label);

            FieldPanel field;
            switch (prop.getType()) {
            case Boolean:
                field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(),
                        new Model<Boolean>(Boolean.valueOf(prop.getValue())))
                                .setChoices(Arrays.asList(new String[] { "Yes", "No" }));
                break;

            case Date:
                SimpleDateFormat df = StringUtils.isNotBlank(prop.getDatePattern())
                        ? new SimpleDateFormat(prop.getDatePattern())
                        : new SimpleDateFormat();
                Date parsedDate = null;
                if (StringUtils.isNotBlank(prop.getValue())) {
                    try {
                        parsedDate = df.parse(prop.getValue());
                    } catch (ParseException e) {
                        LOG.error("Unparsable date: {}", prop.getValue(), e);
                    }
                }

                field = new DateTimeFieldPanel("value", label.getDefaultModelObjectAsString(),
                        new Model<Date>(parsedDate), df.toLocalizedPattern());
                break;

            case Enum:
                MapChoiceRenderer<String, String> enumCR = new MapChoiceRenderer<String, String>(
                        prop.getEnumValues());

                field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(),
                        new Model(prop.getValue())).setChoiceRenderer(enumCR).setChoices(new Model() {

                            private static final long serialVersionUID = -858521070366432018L;

                            @Override
                            public Serializable getObject() {
                                return new ArrayList<String>(prop.getEnumValues().keySet());
                            }
                        });
                break;

            case Long:
                field = new SpinnerFieldPanel<Long>("value", label.getDefaultModelObjectAsString(), Long.class,
                        new Model<Long>(NumberUtils.toLong(prop.getValue())), null, null);
                break;

            case String:
            default:
                field = new AjaxTextFieldPanel("value", PARENT_PATH, new Model<String>(prop.getValue()));
                break;
            }

            field.setReadOnly(!prop.isWritable());
            if (prop.isRequired()) {
                field.addRequiredLabel();
            }

            item.add(field);
        }
    };

    final AjaxButton userDetails = new IndicatingAjaxButton("userDetails",
            new Model<String>(getString("userDetails"))) {

        private static final long serialVersionUID = -4804368561204623354L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            editUserWin.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = -7834632442532690940L;

                @Override
                public Page createPage() {
                    return new ViewUserModalPage(ApprovalModalPage.this.getPageReference(), editUserWin,
                            userRestClient.read(formTO.getUserId())) {

                        private static final long serialVersionUID = -2819994749866481607L;

                        @Override
                        protected void closeAction(final AjaxRequestTarget target, final Form form) {
                            setResponsePage(ApprovalModalPage.this);
                        }
                    };
                }
            });

            editUserWin.show(target);
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(userDetails, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Users", "read"));

    final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<String>(getString(SUBMIT))) {

        private static final long serialVersionUID = -958724007591692537L;

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

            Map<String, WorkflowFormPropertyTO> props = formTO.getPropertyMap();

            for (int i = 0; i < propView.size(); i++) {
                @SuppressWarnings("unchecked")
                ListItem<WorkflowFormPropertyTO> item = (ListItem<WorkflowFormPropertyTO>) propView.get(i);
                String input = ((FieldPanel) item.get("value")).getField().getInput();

                if (!props.containsKey(item.getModelObject().getId())) {
                    props.put(item.getModelObject().getId(), new WorkflowFormPropertyTO());
                }

                if (item.getModelObject().isWritable()) {
                    switch (item.getModelObject().getType()) {
                    case Boolean:
                        props.get(item.getModelObject().getId()).setValue(String.valueOf("0".equals(input)));
                        break;

                    case Date:
                    case Enum:
                    case String:
                    case Long:
                    default:
                        props.get(item.getModelObject().getId()).setValue(input);
                        break;
                    }
                }
            }

            formTO.setProperties(props.values());
            try {
                restClient.submitForm(formTO);

                ((Todo) pageRef.getPage()).setModalResult(true);
                window.close(target);
            } catch (SyncopeClientException e) {
                error(getString(Constants.ERROR) + ": " + e.getMessage());
                LOG.error("While submitting form {}", formTO, e);
                feedbackPanel.refresh(target);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            feedbackPanel.refresh(target);
        }
    };

    final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form form) {
            window.close(target);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form form) {
            // nothing
        }
    };

    cancel.setDefaultFormProcessing(false);

    Form form = new Form(FORM);
    form.add(propView);
    form.add(userDetails);
    form.add(submit);
    form.add(cancel);

    MetaDataRoleAuthorizationStrategy.authorize(form, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Approval", SUBMIT));

    editUserWin = new ModalWindow("editUserWin");
    editUserWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    editUserWin.setInitialHeight(USER_WIN_HEIGHT);
    editUserWin.setInitialWidth(USER_WIN_WIDTH);
    editUserWin.setCookieName("edit-user-modal");
    add(editUserWin);

    add(form);
}

From source file:org.apache.syncope.console.pages.Configuration.java

License:Apache License

public Configuration() {
    super();/*from   w w  w .ja  va  2 s . co m*/

    setupSyncopeConf();

    add(new PoliciesPanel("passwordPoliciesPanel", getPageReference(), PolicyType.PASSWORD));
    add(new PoliciesPanel("accountPoliciesPanel", getPageReference(), PolicyType.ACCOUNT));
    add(new PoliciesPanel("syncPoliciesPanel", getPageReference(), PolicyType.SYNC));

    add(createNotificationWin = new ModalWindow("createNotificationWin"));
    add(editNotificationWin = new ModalWindow("editNotificationWin"));
    setupNotification();

    // Workflow definition stuff
    WebMarkupContainer noActivitiEnabledForUsers = new WebMarkupContainer("noActivitiEnabledForUsers");
    noActivitiEnabledForUsers.setOutputMarkupPlaceholderTag(true);
    add(noActivitiEnabledForUsers);

    WebMarkupContainer workflowDefContainer = new WebMarkupContainer("workflowDefContainer");
    workflowDefContainer.setOutputMarkupPlaceholderTag(true);

    if (wfRestClient.isActivitiEnabledForUsers()) {
        noActivitiEnabledForUsers.setVisible(false);
    } else {
        workflowDefContainer.setVisible(false);
    }

    BookmarkablePageLink<Void> activitiModeler = new BookmarkablePageLink<Void>("activitiModeler",
            ActivitiModelerPopupPage.class);
    activitiModeler.setPopupSettings(new VeilPopupSettings().setHeight(600).setWidth(800));
    MetaDataRoleAuthorizationStrategy.authorize(activitiModeler, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Configuration", "workflowDefRead"));
    workflowDefContainer.add(activitiModeler);
    // Check if Activiti Modeler directory is found
    boolean activitiModelerEnabled = false;
    try {
        String activitiModelerDirectory = WebApplicationContextUtils
                .getWebApplicationContext(WebApplication.get().getServletContext())
                .getBean("activitiModelerDirectory", String.class);
        File baseDir = new File(activitiModelerDirectory);
        activitiModelerEnabled = baseDir.exists() && baseDir.canRead() && baseDir.isDirectory();
    } catch (Exception e) {
        LOG.error("Could not check for Activiti Modeler directory", e);
    }
    activitiModeler.setEnabled(activitiModelerEnabled);

    BookmarkablePageLink<Void> xmlEditor = new BookmarkablePageLink<Void>("xmlEditor",
            XMLEditorPopupPage.class);
    xmlEditor.setPopupSettings(new VeilPopupSettings().setHeight(480).setWidth(800));
    MetaDataRoleAuthorizationStrategy.authorize(xmlEditor, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Configuration", "workflowDefRead"));
    workflowDefContainer.add(xmlEditor);

    Image workflowDefDiagram = new Image("workflowDefDiagram", new Model()) {

        private static final long serialVersionUID = -8457850449086490660L;

        @Override
        protected IResource getImageResource() {
            return new DynamicImageResource() {

                private static final long serialVersionUID = 923201517955737928L;

                @Override
                protected byte[] getImageData(final IResource.Attributes attributes) {
                    return wfRestClient.isActivitiEnabledForUsers() ? wfRestClient.getDiagram() : new byte[0];
                }
            };
        }

    };
    workflowDefContainer.add(workflowDefDiagram);

    MetaDataRoleAuthorizationStrategy.authorize(workflowDefContainer, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Configuration", "workflowDefRead"));
    add(workflowDefContainer);

    // Logger stuff
    PropertyListView<LoggerTO> coreLoggerList = new LoggerPropertyList(null, "corelogger",
            loggerRestClient.listLogs());
    WebMarkupContainer coreLoggerContainer = new WebMarkupContainer("coreLoggerContainer");
    coreLoggerContainer.add(coreLoggerList);
    coreLoggerContainer.setOutputMarkupId(true);

    MetaDataRoleAuthorizationStrategy.authorize(coreLoggerContainer, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Configuration", "logList"));
    add(coreLoggerContainer);

    ConsoleLoggerController consoleLoggerController = new ConsoleLoggerController();
    PropertyListView<LoggerTO> consoleLoggerList = new LoggerPropertyList(consoleLoggerController,
            "consolelogger", consoleLoggerController.getLoggers());
    WebMarkupContainer consoleLoggerContainer = new WebMarkupContainer("consoleLoggerContainer");
    consoleLoggerContainer.add(consoleLoggerList);
    consoleLoggerContainer.setOutputMarkupId(true);

    MetaDataRoleAuthorizationStrategy.authorize(consoleLoggerContainer, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Configuration", "logList"));
    add(consoleLoggerContainer);
}

From source file:org.apache.syncope.console.pages.Login.java

License:Apache License

public Login(final PageParameters parameters) {
    super(parameters);

    feedbackPanel = new NotificationPanel(Constants.FEEDBACK);
    add(feedbackPanel);//w  ww  . ja v  a 2s. co m

    form = new Form<Void>("login");

    userIdField = new TextField<String>("userId", new Model<String>());
    userIdField.setMarkupId("userId");
    form.add(userIdField);

    passwordField = new PasswordTextField("password", new Model<String>());
    passwordField.setMarkupId("password");
    form.add(passwordField);

    languageSelect = new LocaleDropDown("language");

    form.add(languageSelect);

    AjaxButton submitButton = new AjaxButton("submit", new Model<String>(getString("submit"))) {

        private static final long serialVersionUID = 429178684321093953L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            try {
                if (anonymousUser.equals(userIdField.getRawInput())) {
                    throw new AccessControlException("Illegal username");
                }

                authenticate(userIdField.getRawInput(), passwordField.getRawInput());

                setResponsePage(WelcomePage.class, parameters);
            } catch (AccessControlException e) {
                error(getString("login-error"));
                feedbackPanel.refresh(target);
                SyncopeSession.get().resetClients();
            }
        }
    };

    submitButton.setDefaultFormProcessing(false);
    form.add(submitButton);

    add(form);

    // Modal window for self registration
    final ModalWindow editProfileModalWin = new ModalWindow("selfRegModal");
    editProfileModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    editProfileModalWin.setInitialHeight(SELF_REG_WIN_HEIGHT);
    editProfileModalWin.setInitialWidth(SELF_REG_WIN_WIDTH);
    editProfileModalWin.setCookieName("self-reg-modal");
    add(editProfileModalWin);

    Fragment selfRegFrag;
    if (userSelfRestClient.isSelfRegistrationAllowed()) {
        selfRegFrag = new Fragment("selfRegistration", "selfRegAllowed", this);

        final AjaxLink<Void> selfRegLink = new ClearIndicatingAjaxLink<Void>("link", getPageReference()) {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            protected void onClickInternal(final AjaxRequestTarget target) {
                editProfileModalWin.setPageCreator(new ModalWindow.PageCreator() {

                    private static final long serialVersionUID = -7834632442532690940L;

                    @Override
                    public Page createPage() {
                        // anonymous authentication needed for self-registration
                        authenticate(anonymousUser, anonymousKey);

                        return new UserSelfModalPage(Login.this.getPageReference(), editProfileModalWin,
                                new UserTO());
                    }
                });

                editProfileModalWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

                    private static final long serialVersionUID = 251794406325329768L;

                    @Override
                    public void onClose(final AjaxRequestTarget target) {
                        SyncopeSession.get().invalidate();
                    }
                });

                editProfileModalWin.show(target);
            }
        };
        selfRegLink.add(new Label("linkTitle", getString("selfRegistration")));

        Panel panel = new LinkPanel("selfRegistration", new ResourceModel("selfRegistration"));
        panel.add(selfRegLink);
        selfRegFrag.add(panel);
    } else {
        selfRegFrag = new Fragment("selfRegistration", "selfRegNotAllowed", this);
    }
    add(selfRegFrag);
}

From source file:org.apache.syncope.console.pages.panels.AbstractSyncTasksPanel.java

License:Apache License

public AbstractSyncTasksPanel(final String id, final PageReference pageRef, final Class<T> reference) {
    super(id, pageRef);

    this.reference = reference;

    container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);//from w  w  w . j a va  2s .co  m
    add(container);

    window = new ModalWindow("taskWin");
    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setInitialHeight(WIN_HEIGHT);
    window.setInitialWidth(WIN_WIDTH);
    window.setCookieName(VIEW_TASK_WIN_COOKIE_NAME);
    add(window);

    ((Tasks) pageRef.getPage()).setWindowClosedCallback(window, container);

    paginatorRows = prefMan.getPaginatorRows(getWebRequest(), Constants.PREF_SYNC_TASKS_PAGINATOR_ROWS);
}

From source file:org.apache.syncope.console.pages.panels.AjaxDataTablePanel.java

License:Apache License

public AjaxDataTablePanel(final String id, final List<IColumn<T, S>> columns,
        final ISortableDataProvider<T, S> dataProvider, final int rowsPerPage,
        final Collection<ActionLink.ActionType> actions, final BaseRestClient bulkActionExecutor,
        final String itemIdField, final String pageId, final PageReference pageRef) {

    super(id);//from w w  w .j a  v  a2s  .c  o m

    final ModalWindow bulkModalWin = new ModalWindow("bulkModal");
    bulkModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    bulkModalWin.setInitialHeight(600);
    bulkModalWin.setInitialWidth(900);
    bulkModalWin.setCookieName("bulk-modal");
    add(bulkModalWin);

    bulkModalWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 8804221891699487149L;

        @Override
        public void onClose(final AjaxRequestTarget target) {
            final EventDataWrapper data = new EventDataWrapper();
            data.setTarget(target);
            data.setRows(rowsPerPage);

            send(pageRef.getPage(), Broadcast.BREADTH, data);

            final AbstractBasePage page = (AbstractBasePage) pageRef.getPage();

            if (page.isModalResult()) {
                // reset modal result
                page.setModalResult(false);
                // set operation succeeded
                getSession().info(getString(Constants.OPERATION_SUCCEEDED));
                // refresh feedback panel
                target.add(page.getFeedbackPanel());
            }
        }
    });

    Fragment fragment = new Fragment("tablePanel", "bulkAvailable", this);
    add(fragment);

    Form<T> bulkActionForm = new Form<T>("groupForm");
    fragment.add(bulkActionForm);

    group = new CheckGroup<T>("checkgroup", model);
    group.add(new AjaxFormChoiceComponentUpdatingBehavior() {

        private static final long serialVersionUID = -151291731388673682L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            // triggers AJAX form submit
        }
    });
    bulkActionForm.add(group);

    columns.add(0, new CheckGroupColumn<T, S>(group));
    dataTable = new AjaxFallbackDefaultDataTable<T, S>("dataTable", columns, dataProvider, rowsPerPage);
    group.add(dataTable);

    fragment.add(new ClearIndicatingAjaxButton("bulkActionLink", bulkActionForm, pageRef) {

        private static final long serialVersionUID = 382302811235019988L;

        @Override
        protected void onSubmitInternal(final AjaxRequestTarget target, final Form<?> form) {
            bulkModalWin.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = -7834632442532690941L;

                @Override
                public Page createPage() {
                    return new BulkActionModalPage<T, S>(bulkModalWin, group.getModelObject(), columns, actions,
                            bulkActionExecutor, itemIdField, pageId);
                }
            });

            bulkModalWin.show(target);
        }
    });
}

From source file:org.apache.syncope.console.pages.panels.MembershipsPanel.java

License:Apache License

public MembershipsPanel(final String id, final UserTO userTO, final boolean templateMode,
        final StatusPanel statusPanel, final PageReference pageRef) {

    super(id);//  ww  w  .  j  a  v a2s  .  c  o m
    this.userTO = userTO;
    this.statusPanel = statusPanel;

    final WebMarkupContainer membershipsContainer = new WebMarkupContainer("membershipsContainer");
    membershipsContainer.setOutputMarkupId(true);
    add(membershipsContainer);

    final ModalWindow membWin = new ModalWindow("membershipWin");
    membWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    membWin.setCookieName("create-membership-modal");
    add(membWin);

    final ITreeProvider<DefaultMutableTreeNode> treeProvider = new TreeRoleProvider(roleTreeBuilder, true);
    final DefaultMutableTreeNodeExpansionModel treeModel = new DefaultMutableTreeNodeExpansionModel();

    tree = new DefaultNestedTree<DefaultMutableTreeNode>("treeTable", treeProvider, treeModel) {

        private static final long serialVersionUID = 7137658050662575546L;

        @Override
        protected Component newContentComponent(final String id, final IModel<DefaultMutableTreeNode> node) {
            final DefaultMutableTreeNode treeNode = node.getObject();
            final RoleTO roleTO = (RoleTO) treeNode.getUserObject();

            return new Folder<DefaultMutableTreeNode>(id, MembershipsPanel.this.tree, node) {

                private static final long serialVersionUID = 9046323319920426493L;

                @Override
                protected boolean isClickable() {
                    return true;
                }

                @Override
                protected IModel<?> newLabelModel(final IModel<DefaultMutableTreeNode> model) {
                    return new Model<String>(roleTO.getDisplayName());
                }

                @Override
                protected void onClick(final AjaxRequestTarget target) {
                    if (roleTO.getId() > 0) {
                        membWin.setPageCreator(new ModalWindow.PageCreator() {

                            private static final long serialVersionUID = 7661763358801821185L;

                            @Override
                            public Page createPage() {
                                PageReference pageRef = getPage().getPageReference();

                                for (MembershipTO membTO : membView.getList()) {
                                    if (membTO.getRoleId() == roleTO.getId()) {
                                        return new MembershipModalPage(pageRef, membWin, membTO, templateMode);
                                    }
                                }
                                MembershipTO membTO = new MembershipTO();
                                membTO.setRoleId(roleTO.getId());
                                membTO.setRoleName(roleTO.getName());

                                return new MembershipModalPage(pageRef, membWin, membTO, templateMode);
                            }
                        });
                        membWin.show(target);
                    }
                }
            };
        }
    };
    tree.add(new WindowsTheme());
    tree.setOutputMarkupId(true);

    DefaultMutableTreeNodeExpansion.get().expandAll();

    this.add(tree);

    membView = new ListView<MembershipTO>("memberships",
            new PropertyModel<List<? extends MembershipTO>>(userTO, "memberships")) {

        private static final long serialVersionUID = 9101744072914090143L;

        @Override
        protected void populateItem(final ListItem<MembershipTO> item) {
            final MembershipTO membershipTO = (MembershipTO) item.getDefaultModelObject();

            item.add(new Label("roleId", new Model<Long>(membershipTO.getRoleId())));
            item.add(new Label("roleName", new Model<String>(membershipTO.getRoleName())));

            AjaxLink editLink = new ClearIndicatingAjaxLink("editLink", pageRef) {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                protected void onClickInternal(final AjaxRequestTarget target) {
                    membWin.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            return new MembershipModalPage(getPage().getPageReference(), membWin, membershipTO,
                                    templateMode);

                        }
                    });
                    membWin.show(target);
                }
            };
            item.add(editLink);

            AjaxLink deleteLink = new IndicatingOnConfirmAjaxLink("deleteLink", pageRef) {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                protected void onClickInternal(final AjaxRequestTarget target) {
                    userTO.getMemberships().remove(membershipTO);
                    ((UserModalPage) getPage()).getUserTO().getMemberships().remove(membershipTO);
                    target.add(membershipsContainer);

                    RoleTO roleTO = RoleUtils.findRole(roleTreeBuilder, membershipTO.getRoleId());
                    Set<String> resourcesToRemove = roleTO == null ? Collections.<String>emptySet()
                            : roleTO.getResources();
                    if (!resourcesToRemove.isEmpty()) {
                        Set<String> resourcesAssignedViaMembership = new HashSet<String>();
                        for (MembershipTO membTO : userTO.getMemberships()) {
                            roleTO = RoleUtils.findRole(roleTreeBuilder, membTO.getRoleId());
                            if (roleTO != null) {
                                resourcesAssignedViaMembership.addAll(roleTO.getResources());
                            }
                        }
                        resourcesToRemove.removeAll(resourcesAssignedViaMembership);
                        resourcesToRemove.removeAll(userTO.getResources());
                    }

                    StatusUtils.update(userTO, statusPanel, target, Collections.<String>emptySet(),
                            resourcesToRemove);
                }
            };
            item.add(deleteLink);
        }
    };

    membershipsContainer.add(membView);

    setWindowClosedCallback(membWin, membershipsContainer);
}

From source file:org.apache.syncope.console.pages.panels.PoliciesPanel.java

License:Apache License

public PoliciesPanel(final String id, final PageReference pageRef, final PolicyType policyType) {
    super(id);//w w  w . j ava 2 s. c  o  m
    this.pageRef = pageRef;
    this.policyType = policyType;

    // Modal window for editing user attributes
    final ModalWindow mwindow = new ModalWindow("editModalWin");
    mwindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    mwindow.setInitialHeight(MODAL_WIN_HEIGHT);
    mwindow.setInitialWidth(MODAL_WIN_WIDTH);
    mwindow.setCookieName("policy-modal");
    add(mwindow);

    // Container for user list
    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);
    add(container);

    setWindowClosedCallback(mwindow, container);

    final List<IColumn<AbstractPolicyTO, String>> columns = new ArrayList<IColumn<AbstractPolicyTO, String>>();

    columns.add(new PropertyColumn<AbstractPolicyTO, String>(new ResourceModel("id"), "id", "id"));

    columns.add(new PropertyColumn<AbstractPolicyTO, String>(new ResourceModel("description"), "description",
            "description"));

    columns.add(new AbstractColumn<AbstractPolicyTO, String>(new ResourceModel("type")) {

        private static final long serialVersionUID = 8263694778917279290L;

        @Override
        public void populateItem(final Item<ICellPopulator<AbstractPolicyTO>> cellItem,
                final String componentId, final IModel<AbstractPolicyTO> model) {

            cellItem.add(new Label(componentId, getString(model.getObject().getType().name())));
        }
    });

    columns.add(new AbstractColumn<AbstractPolicyTO, String>(new ResourceModel("actions", "")) {

        private static final long serialVersionUID = 2054811145491901166L;

        @Override
        public String getCssClass() {
            return "action";
        }

        @Override
        public void populateItem(final Item<ICellPopulator<AbstractPolicyTO>> cellItem,
                final String componentId, final IModel<AbstractPolicyTO> model) {

            final AbstractPolicyTO policyTO = model.getObject();

            final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, pageRef);

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {

                    mwindow.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @SuppressWarnings({ "unchecked", "rawtypes" })
                        @Override
                        public Page createPage() {
                            return new PolicyModalPage(pageRef, mwindow, policyTO);
                        }
                    });

                    mwindow.show(target);
                }
            }, ActionLink.ActionType.EDIT, "Policies");

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    try {
                        policyRestClient.delete(policyTO.getId(), policyTO.getClass());
                        info(getString(Constants.OPERATION_SUCCEEDED));
                    } catch (SyncopeClientException e) {
                        error(getString(Constants.OPERATION_ERROR));

                        LOG.error("While deleting policy {}({})", policyTO.getId(), policyTO.getDescription(),
                                e);
                    }

                    target.add(container);
                    ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target);
                }
            }, ActionLink.ActionType.DELETE, "Policies");

            cellItem.add(panel);
        }
    });

    @SuppressWarnings({ "unchecked", "rawtypes" })
    final AjaxFallbackDefaultDataTable table = new AjaxFallbackDefaultDataTable("datatable", columns,
            new PolicyDataProvider(), paginatorRows);

    container.add(table);

    final AjaxLink<Void> createButton = new ClearIndicatingAjaxLink<Void>("createLink", pageRef) {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        protected void onClickInternal(final AjaxRequestTarget target) {
            mwindow.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = -7834632442532690940L;

                @SuppressWarnings({ "unchecked", "rawtypes" })
                @Override
                public Page createPage() {
                    return new PolicyModalPage(pageRef, mwindow, getPolicyTOInstance(policyType));
                }
            });

            mwindow.show(target);
        }
    };

    add(createButton);

    MetaDataRoleAuthorizationStrategy.authorize(createButton, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Policies", "create"));

    @SuppressWarnings("rawtypes")
    final Form paginatorForm = new Form("PaginatorForm");

    @SuppressWarnings({ "unchecked", "rawtypes" })
    final DropDownChoice rowsChooser = new DropDownChoice("rowsChooser",
            new PropertyModel(this, "paginatorRows"), prefMan.getPaginatorChoices());

    rowsChooser.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            prefMan.set(getWebRequest(), (WebResponse) getResponse(), Constants.PREF_POLICY_PAGINATOR_ROWS,
                    String.valueOf(paginatorRows));
            table.setItemsPerPage(paginatorRows);

            target.add(container);
        }
    });

    paginatorForm.add(rowsChooser);
    add(paginatorForm);
}

From source file:org.apache.syncope.console.pages.panels.PropagationTasks.java

License:Apache License

public PropagationTasks(final String id, final PageReference pageRef) {
    super(id, pageRef);

    container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);// w  ww.ja v a  2  s .c  om
    add(container);

    add(window = new ModalWindow("taskWin"));

    paginatorRows = prefMan.getPaginatorRows(getWebRequest(), Constants.PREF_PROPAGATION_TASKS_PAGINATOR_ROWS);

    table = Tasks.updateTaskTable(getColumns(),
            new TasksProvider<PropagationTaskTO>(restClient, paginatorRows, getId(), PropagationTaskTO.class),
            container, 0, pageRef, restClient);

    window.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 8804221891699487139L;

        @Override
        public void onClose(final AjaxRequestTarget target) {
            target.add(container);
            if (operationResult) {
                info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(getPage().get(Constants.FEEDBACK));
                operationResult = false;
            }
        }
    });

    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setInitialHeight(WIN_HEIGHT);
    window.setInitialWidth(WIN_WIDTH);
    window.setCookieName(VIEW_TASK_WIN_COOKIE_NAME);

    @SuppressWarnings("rawtypes")
    Form paginatorForm = new Form("PaginatorForm");

    @SuppressWarnings({ "unchecked", "rawtypes" })
    final DropDownChoice rowsChooser = new DropDownChoice("rowsChooser",
            new PropertyModel(this, "paginatorRows"), prefMan.getPaginatorChoices());

    rowsChooser.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            prefMan.set(getWebRequest(), (WebResponse) getResponse(),
                    Constants.PREF_PROPAGATION_TASKS_PAGINATOR_ROWS, String.valueOf(paginatorRows));

            table = Tasks.updateTaskTable(getColumns(),
                    new TasksProvider<PropagationTaskTO>(restClient, paginatorRows, getId(),
                            PropagationTaskTO.class),
                    container, table == null ? 0 : (int) table.getCurrentPage(), pageRef, restClient);

            target.add(container);
        }
    });

    paginatorForm.add(rowsChooser);
    add(paginatorForm);
}