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

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

Introduction

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

Prototype

public void show(final IPartialPageRequestHandler target) 

Source Link

Document

Shows the modal window.

Usage

From source file:org.sakaiproject.profile2.tool.pages.panels.WallItemPanel.java

License:Educational Community License

/**
 * Creates a new instance of <code>WallItemPanel</code>.
 * /*from w  w w. j a v  a2  s  .  c o m*/
 * @param id
 * @param userUuid the id of the user whose wall this item panel is on.
 * @param wallItem
 * @param myWallPanel a reference to my wall panel for repainting.
 */
public WallItemPanel(String id, final String userUuid, final WallItem wallItem, final MyWallPanel myWallPanel) {
    super(id);

    setOutputMarkupId(true);

    // image wrapper, links to profile
    Link<String> wallItemPhoto = new Link<String>("wallItemPhotoWrap",
            new Model<String>(wallItem.getCreatorUuid())) {

        private static final long serialVersionUID = 1L;

        public void onClick() {
            setResponsePage(new ViewProfile(getModelObject()));
        }
    };

    // image
    ProfileImage photo = new ProfileImage("wallItemPhoto", new Model<String>(wallItem.getCreatorUuid()));
    photo.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
    wallItemPhoto.add(photo);

    add(wallItemPhoto);

    // name and link to profile
    Link<String> wallItemProfileLink = new Link<String>("wallItemProfileLink",
            new Model<String>(wallItem.getCreatorUuid())) {

        private static final long serialVersionUID = 1L;

        public void onClick() {
            setResponsePage(new ViewProfile(getModelObject()));
        }

    };
    wallItemProfileLink
            .add(new Label("wallItemName", sakaiProxy.getUserDisplayName(wallItem.getCreatorUuid())));
    add(wallItemProfileLink);

    add(new Label("wallItemDate",
            ProfileUtils.convertDateToString(wallItem.getDate(), ProfileConstants.WALL_DISPLAY_DATE_FORMAT)));

    // ACTIONS

    final ModalWindow wallItemActionWindow = new ModalWindow("wallItemActionWindow");
    add(wallItemActionWindow);

    final WallAction wallAction = new WallAction();
    // delete link
    final AjaxLink<WallItem> removeItemLink = new AjaxLink<WallItem>("removeWallItemLink",
            new Model<WallItem>(wallItem)) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {

            wallItemActionWindow.setContent(new RemoveWallItem(wallItemActionWindow.getContentId(),
                    wallItemActionWindow, wallAction, userUuid, this.getModelObject()));

            wallItemActionWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClose(AjaxRequestTarget target) {
                    if (wallAction.isItemRemoved()) {
                        myWallPanel.replaceSelf(target, userUuid);
                    }
                }
            });

            wallItemActionWindow.show(target);
            target.appendJavaScript("fixWindowVertical();");
        }
    };

    removeItemLink.add(new Label("removeWallItemLabel", new ResourceModel("link.wall.item.remove")));
    removeItemLink.add(new AttributeModifier("title", true, new ResourceModel("link.title.wall.remove")));

    // not visible when viewing another user's wall
    if (false == sakaiProxy.getCurrentUserId().equals(userUuid)) {
        removeItemLink.setVisible(false);
    }

    add(removeItemLink);

    // panel for posting a comment that slides up/down
    final WallItemPostCommentPanel postCommentPanel = new WallItemPostCommentPanel("wallItemPostCommentPanel",
            userUuid, wallItem, this, myWallPanel);
    postCommentPanel.setOutputMarkupPlaceholderTag(true);
    postCommentPanel.setVisible(false);
    add(postCommentPanel);

    final AjaxLink<WallItem> commentItemLink = new AjaxLink<WallItem>("commentWallItemLink",
            new Model<WallItem>(wallItem)) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {

            postCommentPanel.setVisible(true);
            target.add(postCommentPanel);
            target.appendJavaScript("$('#" + postCommentPanel.getMarkupId() + "').slideDown();");
        }
    };

    commentItemLink.add(new Label("commentWallItemLabel", new ResourceModel("link.wall.item.comment")));
    commentItemLink.add(new AttributeModifier("title", true, new StringResourceModel("link.title.wall.comment",
            null, new Object[] { sakaiProxy.getUserDisplayName(wallItem.getCreatorUuid()) })));

    add(commentItemLink);

    if (ProfileConstants.WALL_ITEM_TYPE_EVENT == wallItem.getType()) {
        add(new Label("wallItemText", new ResourceModel(wallItem.getText())));

    } else if (ProfileConstants.WALL_ITEM_TYPE_POST == wallItem.getType()) {
        add(new Label("wallItemText", ProfileUtils.processHtml(wallItem.getText()))
                .setEscapeModelStrings(false));

    } else if (ProfileConstants.WALL_ITEM_TYPE_STATUS == wallItem.getType()) {
        add(new Label("wallItemText", wallItem.getText()));

    }

    // COMMENTS

    ListView<WallItemComment> wallItemCommentsListView = new ListView<WallItemComment>("wallItemComments",
            wallItem.getComments()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<WallItemComment> item) {

            WallItemComment comment = (WallItemComment) item.getDefaultModelObject();

            item.add(new WallItemCommentPanel("wallItemCommentPanel", comment));
        }

    };
    wallItemCommentsListView.setOutputMarkupId(true);
    add(wallItemCommentsListView);

}

From source file:org.sakaiproject.profile2.tool.pages.ViewProfile.java

License:Educational Community License

public ViewProfile(final String userUuid, final String tab) {

    log.debug("ViewProfile()");

    //setup model to store the actions in the modal windows
    final FriendAction friendActionModel = new FriendAction();

    //get current user info
    User currentUser = sakaiProxy.getUserQuietly(sakaiProxy.getCurrentUserId());
    final String currentUserId = currentUser.getId();
    String currentUserType = currentUser.getType();

    //double check, if somehow got to own ViewPage, redirect to MyProfile instead
    if (userUuid.equals(currentUserId)) {
        log.warn("ViewProfile: user " + userUuid + " accessed ViewProfile for self. Redirecting...");
        throw new RestartResponseException(new MyProfile());
    }/*from  ww  w.  j a  v  a 2 s  .  co m*/

    //check if super user, to grant editing rights to another user's profile
    if (sakaiProxy.isSuperUser()) {
        log.warn("ViewProfile: superUser " + currentUserId + " accessed ViewProfile for " + userUuid
                + ". Redirecting to allow edit.");
        throw new RestartResponseException(new MyProfile(userUuid));
    }

    //post view event
    sakaiProxy.postEvent(ProfileConstants.EVENT_PROFILE_VIEW_OTHER, "/profile/" + userUuid, false);

    /* DEPRECATED via PRFL-24 when privacy was relaxed
    if(!isProfileAllowed) {
       throw new ProfileIllegalAccessException("User: " + currentUserId + " is not allowed to view profile for: " + userUuid);
    }
    */

    //get some values from User
    User user = sakaiProxy.getUserQuietly(userUuid);
    String userDisplayName = user.getDisplayName();
    String userType = user.getType();

    //init
    final boolean friend;
    boolean friendRequestToThisPerson = false;
    boolean friendRequestFromThisPerson = false;

    //friend?
    friend = connectionsLogic.isUserXFriendOfUserY(userUuid, currentUserId);

    //if not friend, has a friend request already been made to this person?
    if (!friend) {
        friendRequestToThisPerson = connectionsLogic.isFriendRequestPending(currentUserId, userUuid);
    }

    //if not friend and no friend request to this person, has a friend request been made from this person to the current user?
    if (!friend && !friendRequestToThisPerson) {
        friendRequestFromThisPerson = connectionsLogic.isFriendRequestPending(userUuid, currentUserId);
    }

    //privacy checks
    final ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(userUuid);

    boolean isFriendsListVisible = privacyLogic.isActionAllowed(userUuid, currentUserId,
            PrivacyType.PRIVACY_OPTION_MYFRIENDS);
    boolean isKudosVisible = privacyLogic.isActionAllowed(userUuid, currentUserId,
            PrivacyType.PRIVACY_OPTION_MYKUDOS);
    boolean isGalleryVisible = privacyLogic.isActionAllowed(userUuid, currentUserId,
            PrivacyType.PRIVACY_OPTION_MYPICTURES);
    boolean isConnectionAllowed = sakaiProxy.isConnectionAllowedBetweenUserTypes(currentUserType, userType);
    boolean isOnlineStatusVisible = privacyLogic.isActionAllowed(userUuid, currentUserId,
            PrivacyType.PRIVACY_OPTION_ONLINESTATUS);

    final ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(userUuid);

    /* IMAGE */
    add(new ProfileImage("photo", new Model<String>(userUuid)));

    /* NAME */
    Label profileName = new Label("profileName", userDisplayName);
    add(profileName);

    /* ONLINE PRESENCE INDICATOR */
    if (sakaiProxy.isOnlineStatusEnabledGlobally() && prefs.isShowOnlineStatus() && isOnlineStatusVisible) {
        add(new OnlinePresenceIndicator("online", userUuid));
    } else {
        add(new EmptyPanel("online"));
    }

    /*STATUS PANEL */
    if (sakaiProxy.isProfileStatusEnabled()) {
        add(new ProfileStatusRenderer("status", userUuid, privacy, null, "tiny"));
    } else {
        add(new EmptyPanel("status"));
    }

    /* TABS */
    List<ITab> tabs = new ArrayList<ITab>();

    AjaxTabbedPanel tabbedPanel = new AjaxTabbedPanel("viewProfileTabs", tabs) {

        private static final long serialVersionUID = 1L;

        // overridden so we can add tooltips to tabs
        @Override
        protected WebMarkupContainer newLink(String linkId, final int index) {
            WebMarkupContainer link = super.newLink(linkId, index);

            if (ProfileConstants.TAB_INDEX_PROFILE == index) {
                link.add(new AttributeModifier("title", true, new ResourceModel("link.tab.profile.tooltip")));

            } else if (ProfileConstants.TAB_INDEX_WALL == index) {
                link.add(new AttributeModifier("title", true, new ResourceModel("link.tab.wall.tooltip")));
            }
            return link;
        }
    };

    CookieUtils utils = new CookieUtils();
    Cookie tabCookie = utils.getCookie(ProfileConstants.TAB_COOKIE);

    if (sakaiProxy.isProfileFieldsEnabled()) {
        tabs.add(new AbstractTab(new ResourceModel("link.tab.profile")) {

            private static final long serialVersionUID = 1L;

            @Override
            public Panel getPanel(String panelId) {

                setTabCookie(ProfileConstants.TAB_INDEX_PROFILE);
                return new ViewProfilePanel(panelId, userUuid, currentUserId, privacy, friend);
            }
        });
    }

    if (sakaiProxy.isWallEnabledGlobally()) {

        tabs.add(new AbstractTab(new ResourceModel("link.tab.wall")) {

            private static final long serialVersionUID = 1L;

            @Override
            public Panel getPanel(String panelId) {

                setTabCookie(ProfileConstants.TAB_INDEX_WALL);
                return new ViewWallPanel(panelId, userUuid);
            }
        });

        if (sakaiProxy.isWallDefaultProfilePage() && null == tabCookie) {

            tabbedPanel.setSelectedTab(ProfileConstants.TAB_INDEX_WALL);
        }
    }

    if (null != tab) {
        tabbedPanel.setSelectedTab(Integer.parseInt(tab));
    } else if (null != tabCookie) {
        try {
            tabbedPanel.setSelectedTab(Integer.parseInt(tabCookie.getValue()));
        } catch (IndexOutOfBoundsException e) {
            //do nothing. This will be thrown if the cookie contains a value > the number of tabs but thats ok.
        }
    }

    add(tabbedPanel);

    /* SIDELINKS */
    WebMarkupContainer sideLinks = new WebMarkupContainer("sideLinks");
    int visibleSideLinksCount = 0;

    WebMarkupContainer addFriendContainer = new WebMarkupContainer("addFriendContainer");

    //ADD FRIEND MODAL WINDOW
    final ModalWindow addFriendWindow = new ModalWindow("addFriendWindow");

    //FRIEND LINK/STATUS
    final AjaxLink<Void> addFriendLink = new AjaxLink<Void>("addFriendLink") {
        private static final long serialVersionUID = 1L;

        public void onClick(AjaxRequestTarget target) {
            addFriendWindow.show(target);
        }
    };

    final Label addFriendLabel = new Label("addFriendLabel");
    addFriendLink.add(addFriendLabel);

    addFriendContainer.add(addFriendLink);

    //setup link/label and windows
    if (friend) {
        addFriendLabel.setDefaultModel(new ResourceModel("text.friend.confirmed"));
        addFriendLink.add(new AttributeModifier("class", true,
                new Model<String>("instruction icon connection-confirmed")));
        addFriendLink.setEnabled(false);
    } else if (friendRequestToThisPerson) {
        addFriendLabel.setDefaultModel(new ResourceModel("text.friend.requested"));
        addFriendLink.add(
                new AttributeModifier("class", true, new Model<String>("instruction icon connection-request")));
        addFriendLink.setEnabled(false);
    } else if (friendRequestFromThisPerson) {
        //TODO (confirm pending friend request link)
        //could be done by setting the content off the addFriendWindow.
        //will need to rename some links to make more generic and set the onClick and setContent in here for link and window
        addFriendLabel.setDefaultModel(new ResourceModel("text.friend.pending"));
        addFriendLink.add(
                new AttributeModifier("class", true, new Model<String>("instruction icon connection-request")));
        addFriendLink.setEnabled(false);
    } else {
        addFriendLabel.setDefaultModel(
                new StringResourceModel("link.friend.add.name", null, new Object[] { user.getFirstName() }));
        addFriendWindow.setContent(new AddFriend(addFriendWindow.getContentId(), addFriendWindow,
                friendActionModel, currentUserId, userUuid));
    }
    sideLinks.add(addFriendContainer);

    //ADD FRIEND MODAL WINDOW HANDLER 
    addFriendWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
        private static final long serialVersionUID = 1L;

        public void onClose(AjaxRequestTarget target) {
            if (friendActionModel.isRequested()) {
                //friend was successfully requested, update label and link
                addFriendLabel.setDefaultModel(new ResourceModel("text.friend.requested"));
                addFriendLink.add(new AttributeModifier("class", true,
                        new Model<String>("instruction icon connection-request")));
                addFriendLink.setEnabled(false);
                target.add(addFriendLink);
            }
        }
    });
    addFriendWindow.setVisible(sakaiProxy.isConnectionsEnabledGlobally());
    add(addFriendWindow);

    //hide connection link if not allowed
    if (!isConnectionAllowed && !sakaiProxy.isConnectionsEnabledGlobally()) {
        addFriendContainer.setVisible(false);
    } else {
        visibleSideLinksCount++;
    }

    //hide entire list if no links to show
    if (visibleSideLinksCount == 0) {
        sideLinks.setVisible(false);
    }

    add(sideLinks);

    /* KUDOS PANEL */
    if (sakaiProxy.isMyKudosEnabledGlobally() && isKudosVisible) {
        add(new AjaxLazyLoadPanel("myKudos") {
            private static final long serialVersionUID = 1L;

            @Override
            public Component getLazyLoadComponent(String markupId) {
                if (prefs.isShowKudos()) {

                    int score = kudosLogic.getKudos(userUuid);
                    if (score > 0) {
                        return new KudosPanel(markupId, userUuid, currentUserId, score);
                    }
                }
                return new EmptyPanel(markupId);
            }
        });
    } else {
        add(new EmptyPanel("myKudos").setVisible(false));
    }

    /* FRIENDS FEED PANEL */
    if (sakaiProxy.isConnectionsEnabledGlobally() && isFriendsListVisible) {
        add(new AjaxLazyLoadPanel("friendsFeed") {
            private static final long serialVersionUID = 1L;

            @Override
            public Component getLazyLoadComponent(String markupId) {
                return new FriendsFeed(markupId, userUuid, currentUserId);
            }

        });
    } else {
        add(new EmptyPanel("friendsFeed").setVisible(false));
    }

    /* GALLERY FEED PANEL */
    if (sakaiProxy.isProfileGalleryEnabledGlobally() && isGalleryVisible && prefs.isShowGalleryFeed()) {
        add(new AjaxLazyLoadPanel("galleryFeed") {
            private static final long serialVersionUID = 1L;

            @Override
            public Component getLazyLoadComponent(String markupId) {
                return new GalleryFeed(markupId, userUuid, currentUserId).setOutputMarkupId(true);
            }
        });
    } else {
        add(new EmptyPanel("galleryFeed").setVisible(false));
    }
}

From source file:org.syncope.console.pages.BasePage.java

License:Apache License

private void pageSetup() {
    ((SyncopeApplication) getApplication()).setupNavigationPane(this, xmlRolesReader, true, version);

    feedbackPanel = new FeedbackPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);/* w  w  w  .j av a2  s  . c o m*/

    final String kind = getClass().getSimpleName().toLowerCase();
    final BookmarkablePageLink kindLink = (BookmarkablePageLink) get(kind);
    if (kindLink != null) {
        kindLink.add(new Behavior() {

            private static final long serialVersionUID = 1469628524240283489L;

            @Override
            public void onComponentTag(final Component component, final ComponentTag tag) {

                tag.put("class", kind);
            }
        });

        Component kindIcon = kindLink.get(0);
        if (kindIcon != null) {
            kindIcon.add(new Behavior() {

                private static final long serialVersionUID = 1469628524240283489L;

                @Override
                public void onComponentTag(final Component component, final ComponentTag tag) {

                    tag.put("src",
                            "../.." + SyncopeApplication.IMG_PREFIX + kind + SyncopeApplication.IMG_SUFFIX);
                }
            });
        }
    }

    // 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");
    add(editProfileModalWin);

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

    Fragment editProfileFrag;
    if ("admin".equals(SyncopeSession.get().getUserId())) {
        editProfileFrag = new Fragment("editProfile", "adminEmptyFrag", this);
    } else {
        final UserTO userTO = SyncopeSession.get().isAuthenticated() ? profileRestClient.readProfile()
                : new UserTO();

        editProfileFrag = new Fragment("editProfile", "editProfileFrag", this);

        AjaxLink editProfileLink = new IndicatingAjaxLink("link") {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target) {
                editProfileModalWin.setPageCreator(new ModalWindow.PageCreator() {

                    @Override
                    public Page createPage() {
                        return new UserRequestModalPage(BasePage.this.getPageReference(), editProfileModalWin,
                                userTO);
                    }
                });

                editProfileModalWin.show(target);
            }
        };
        editProfileLink.add(new Label("linkTitle", getString("editProfile")));

        Panel panel = new LinkPanel("editProfile", new ResourceModel("editProfile"));
        panel.add(editProfileLink);
        editProfileFrag.add(panel);
    }
    add(editProfileFrag);
}

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

License:Apache License

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

    form = new Form("login");

    userIdField = new TextField("userId", new Model());
    userIdField.setMarkupId("userId");
    form.add(userIdField);//  w w  w .  j a  v  a 2  s .  c om

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

    languageSelect = new LocaleDropDown("language",
            Arrays.asList(new Locale[] { Locale.ENGLISH, Locale.ITALIAN }));

    form.add(languageSelect);

    Button submitButton = new Button("submit", new Model(getString("submit"))) {

        private static final long serialVersionUID = 429178684321093953L;

        @Override
        public void onSubmit() {
            String[] entitlements = authenticate(userIdField.getRawInput(), passwordField.getRawInput());

            if (entitlements == null) {
                error(getString("login-error"));
            } else {
                SyncopeSession.get().setUserId(userIdField.getRawInput());
                SyncopeSession.get().setEntitlements(entitlements);
                SyncopeSession.get().setCoreVersion(getCoreVersion());

                setResponsePage(WelcomePage.class, parameters);
            }
        }
    };

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

    add(form);
    add(new FeedbackPanel("feedback"));

    // 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 (isSelfRegistrationAllowed()) {
        selfRegFrag = new Fragment("selfRegistration", "selfRegAllowed", this);

        AjaxLink selfRegLink = new IndicatingAjaxLink("link") {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target) {
                editProfileModalWin.setPageCreator(new ModalWindow.PageCreator() {

                    private static final long serialVersionUID = -7834632442532690940L;

                    @Override
                    public Page createPage() {
                        return new UserRequestModalPage(Login.this.getPageReference(), editProfileModalWin,
                                new UserTO());
                    }
                });

                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.syncope.console.pages.panels.PoliciesPanel.java

License:Apache License

public PoliciesPanel(final String id, final PolicyType policyType) {
    super(id);//from  w  w w  . ja  va2  s  .c  o  m

    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> columns = new ArrayList<IColumn>();

    columns.add(new PropertyColumn(new ResourceModel("id"), "id", "id"));

    columns.add(new PropertyColumn(new ResourceModel("description"), "description", "description"));

    columns.add(new AbstractColumn<PolicyTO>(new ResourceModel("type")) {

        private static final long serialVersionUID = 8263694778917279290L;

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

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

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

        private static final long serialVersionUID = 2054811145491901166L;

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

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

            final PolicyTO accountPolicyTO = model.getObject();

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

            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;

                        @Override
                        public Page createPage() {
                            final PolicyModalPage page = new PolicyModalPage(mwindow, accountPolicyTO);
                            return page;
                        }
                    });

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

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    try {

                        policyRestClient.delete(accountPolicyTO.getId());
                        info(getString("operation_succeded"));

                    } catch (SyncopeClientCompositeErrorException e) {
                        error(getString("operation_error"));

                        LOG.error("While deleting resource {}({})",
                                new Object[] { accountPolicyTO.getId(), accountPolicyTO.getDescription() }, e);
                    }

                    target.add(container);
                    target.add(getPage().get("feedback"));
                }
            }, ActionLink.ActionType.DELETE, "Policies", "delete");

            cellItem.add(panel);
        }
    });

    final AjaxFallbackDefaultDataTable table = new AjaxFallbackDefaultDataTable("datatable", columns,
            new PolicyDataProvider(), paginatorRows);

    container.add(table);

    final IndicatingAjaxLink createButton = new IndicatingAjaxLink("createLink") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {

            mwindow.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = -7834632442532690940L;

                @Override
                public Page createPage() {
                    final PolicyModalPage page = new PolicyModalPage(mwindow, getPolicyTOInstance(policyType));
                    return page;
                }
            });

            mwindow.show(target);
        }
    };

    add(createButton);

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

    final Form paginatorForm = new Form("PaginatorForm");

    final DropDownChoice rowsChooser = new DropDownChoice("rowsChooser",
            new PropertyModel(this, "paginatorRows"), prefMan.getPaginatorChoices());

    rowsChooser.add(new AjaxFormComponentUpdatingBehavior("onchange") {

        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.syncope.console.pages.panels.RolesPanel.java

License:Apache License

public RolesPanel(final String id, final UserTO userTO, final boolean templateMode) {

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

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

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

    BaseTree tree = new LinkTree("treeTable", roleTreeBuilder.build()) {

        private static final long serialVersionUID = -5514696922119256101L;

        @Override
        protected IModel getNodeTextModel(final IModel model) {
            return new PropertyModel(model, "userObject.displayName");
        }

        @Override
        protected void onNodeLinkClicked(final Object node, final BaseTree tree,
                final AjaxRequestTarget target) {

            final RoleTO roleTO = (RoleTO) ((DefaultMutableTreeNode) node).getUserObject();

            membershipWin.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = 7661763358801821185L;

                private MembershipTO membershipTO;

                @Override
                public Page createPage() {

                    for (MembershipTO memberTO : membershipsView.getList()) {

                        if (memberTO.getRoleId() == roleTO.getId()) {
                            return new MembershipModalPage(getPage().getPageReference(), membershipWin,
                                    memberTO, templateMode);
                        }
                    }
                    membershipTO = new MembershipTO();
                    membershipTO.setRoleId(roleTO.getId());
                    membershipTO.setRoleName(roleTO.getName());

                    return new MembershipModalPage(getPage().getPageReference(), membershipWin, membershipTO,
                            templateMode);
                }
            });
            membershipWin.show(target);
        }
    };

    tree.setOutputMarkupId(true);
    tree.getTreeState().expandAll();

    add(tree);

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

        private static final long serialVersionUID = 9101744072914090143L;

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

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

            AjaxLink editLink = new IndicatingAjaxLink("editLink") {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    membershipWin.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

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

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

            AjaxLink deleteLink = new IndicatingDeleteOnConfirmAjaxLink("deleteLink") {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    userTO.removeMembership(membershipTO);
                    target.add(membershipsContainer);
                }
            };
            item.add(deleteLink);
        }
    };

    membershipsContainer.add(membershipsView);

    setWindowClosedCallback(membershipWin, membershipsContainer);
}

From source file:org.syncope.console.pages.ReportModalPage.java

License:Apache License

private void setupExecutions() {
    final WebMarkupContainer executions = new WebMarkupContainer("executions");
    executions.setOutputMarkupId(true);// w  w w  . j a  v  a  2s  .  c  o m
    form.add(executions);

    final ModalWindow reportExecMessageWin = new ModalWindow("reportExecMessageWin");
    reportExecMessageWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    reportExecMessageWin.setCookieName("report-exec-message-win-modal");
    add(reportExecMessageWin);

    final ModalWindow reportExecExportWin = new ModalWindow("reportExecExportWin");
    reportExecExportWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    reportExecExportWin.setCookieName("report-exec-export-win-modal");
    reportExecExportWin.setInitialHeight(EXEC_EXPORT_WIN_HEIGHT);
    reportExecExportWin.setInitialWidth(EXEC_EXPORT_WIN_WIDTH);
    reportExecExportWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 8804221891699487139L;

        @Override
        public void onClose(final AjaxRequestTarget target) {
            AjaxExportDownloadBehavior behavior = new AjaxExportDownloadBehavior(
                    ReportModalPage.this.exportFormat, ReportModalPage.this.exportExecId);
            executions.add(behavior);
            behavior.initiate(target);
        }
    });
    add(reportExecExportWin);

    final List<IColumn> columns = new ArrayList<IColumn>();
    columns.add(new PropertyColumn(new ResourceModel("id"), "id", "id"));
    columns.add(new DatePropertyColumn(new ResourceModel("startDate"), "startDate", "startDate"));
    columns.add(new DatePropertyColumn(new ResourceModel("endDate"), "endDate", "endDate"));
    columns.add(new PropertyColumn(new ResourceModel("status"), "status", "status"));
    columns.add(new AbstractColumn<ReportExecTO>(new ResourceModel("actions", "")) {

        private static final long serialVersionUID = 2054811145491901166L;

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

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

            final ReportExecTO taskExecutionTO = model.getObject();

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

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    reportExecMessageWin.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            return new ExecMessageModalPage(model.getObject().getMessage());
                        }
                    });
                    reportExecMessageWin.show(target);
                }
            }, ActionLink.ActionType.EDIT, "Reports", "read",
                    StringUtils.hasText(model.getObject().getMessage()));

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    reportExecExportWin.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            ReportModalPage.this.exportExecId = model.getObject().getId();
                            return new ReportExecResultDownloadModalPage(reportExecExportWin,
                                    ReportModalPage.this.getPageReference());
                        }
                    });
                    reportExecExportWin.show(target);
                }
            }, ActionLink.ActionType.EXPORT, "Reports", "read",
                    ReportExecStatus.SUCCESS.name().equals(model.getObject().getStatus()));

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    try {
                        restClient.deleteExecution(taskExecutionTO.getId());

                        reportTO.removeExecution(taskExecutionTO);

                        info(getString("operation_succeded"));
                    } catch (SyncopeClientCompositeErrorException scce) {
                        error(scce.getMessage());
                    }

                    target.add(feedbackPanel);
                    target.add(executions);
                }
            }, ActionLink.ActionType.DELETE, "Reports", "delete");

            cellItem.add(panel);
        }
    });

    final AjaxFallbackDefaultDataTable table = new AjaxFallbackDefaultDataTable("executionsTable", columns,
            new ReportExecutionsProvider(reportTO), 10);
    executions.add(table);
}

From source file:org.syncope.console.pages.Schema.java

License:Apache License

private <T extends AbstractSchemaModalPage> List<IColumn> getColumnsForSchema(
        final WebMarkupContainer webContainer, final ModalWindow modalWindow,
        final SchemaModalPageFactory.Entity entity, final SchemaModalPageFactory.SchemaType schemaType,
        final String[] fields, final String readPermissions, final String deletePermissions) {

    List<IColumn> columns = new ArrayList<IColumn>();

    for (String field : fields) {
        columns.add(new PropertyColumn(new ResourceModel(field), field, field));
    }//from  w w w  .j a  v a  2  s . c  om

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

        private static final long serialVersionUID = 2054811145491901166L;

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

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

            final AbstractBaseBean schemaTO = model.getObject();

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

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    modalWindow.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            AbstractSchemaModalPage page = SchemaModalPageFactory.getSchemaModalPage(entity,
                                    schemaType);

                            page.setSchemaModalPage(Schema.this.getPageReference(), modalWindow, schemaTO,
                                    false);

                            return page;
                        }
                    });

                    modalWindow.show(target);
                }
            }, ActionType.EDIT, readPermissions);

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {

                    switch (schemaType) {
                    case DERIVED:
                        restClient.deleteDerivedSchema(entity.toString(),
                                ((DerivedSchemaTO) schemaTO).getName());
                        break;
                    case VIRTUAL:
                        restClient.deleteVirtualSchema(entity.toString(),
                                ((VirtualSchemaTO) schemaTO).getName());
                        break;
                    default:
                        restClient.deleteSchema(entity.toString(), ((SchemaTO) schemaTO).getName());
                        break;
                    }

                    info(getString("operation_succeded"));
                    target.add(feedbackPanel);

                    target.add(webContainer);
                }
            }, ActionType.DELETE, deletePermissions);

            cellItem.add(panel);
        }
    });

    return columns;
}

From source file:org.syncope.console.pages.Schema.java

License:Apache License

private <T extends AbstractSchemaModalPage> AjaxLink getCreateSchemaWindow(final ModalWindow createSchemaWin,
        final SchemaModalPageFactory.Entity entity, final SchemaModalPageFactory.SchemaType schemaType,
        final String winLinkName, final String winName, final String createPermissions) {

    AjaxLink createSchemaWinLink = new IndicatingAjaxLink(winLinkName) {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override//from ww  w.j  a  v a  2s  . com
        public void onClick(final AjaxRequestTarget target) {

            createSchemaWin.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = -7834632442532690940L;

                @Override
                public Page createPage() {
                    AbstractSchemaModalPage page = SchemaModalPageFactory.getSchemaModalPage(entity,
                            schemaType);

                    page.setSchemaModalPage(Schema.this.getPageReference(), new ModalWindow(winName), null,
                            true);

                    return page;
                }
            });

            createSchemaWin.show(target);
        }
    };

    MetaDataRoleAuthorizationStrategy.authorize(createSchemaWinLink, ENABLE, createPermissions);

    return createSchemaWinLink;
}

From source file:org.syncope.console.pages.TaskModalPage.java

License:Apache License

public TaskModalPage(final TaskTO taskTO) {
    final TaskTO actual = taskTO.getId() == 0 ? taskTO
            : taskTO instanceof PropagationTaskTO ? taskRestClient.readPropagationTask(taskTO.getId())
                    : taskTO instanceof NotificationTaskTO ? taskRestClient.readNotificationTask(taskTO.getId())
                            : taskTO instanceof SyncTaskTO
                                    ? taskRestClient.readSchedTask(SyncTaskTO.class, taskTO.getId())
                                    : taskRestClient.readSchedTask(SchedTaskTO.class, taskTO.getId());

    taskTO.setExecutions(actual.getExecutions());

    final ModalWindow taskExecMessageWin = new ModalWindow("taskExecMessageWin");
    taskExecMessageWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    taskExecMessageWin.setCookieName("task-exec-message-win-modal");
    add(taskExecMessageWin);/*from   w  w w.j a v  a  2s. c  o m*/

    form = new Form("form");
    form.setModel(new CompoundPropertyModel(taskTO));
    add(form);

    profile = new WebMarkupContainer("profile");
    profile.setOutputMarkupId(true);
    form.add(profile);

    executions = new WebMarkupContainer("executions");
    executions.setOutputMarkupId(true);
    form.add(executions);

    final Label idLabel = new Label("idLabel", new ResourceModel("id"));
    profile.add(idLabel);

    final AjaxTextFieldPanel id = new AjaxTextFieldPanel("id", getString("id"),
            new PropertyModel<String>(taskTO, "id"), false);

    id.setEnabled(false);
    profile.add(id);

    final List<IColumn> columns = new ArrayList<IColumn>();
    columns.add(new PropertyColumn(new ResourceModel("id"), "id", "id"));

    columns.add(new DatePropertyColumn(new ResourceModel("startDate"), "startDate", "startDate"));

    columns.add(new DatePropertyColumn(new ResourceModel("endDate"), "endDate", "endDate"));

    columns.add(new PropertyColumn(new ResourceModel("status"), "status", "status"));

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

        private static final long serialVersionUID = 2054811145491901166L;

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

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

            final TaskExecTO taskExecutionTO = model.getObject();

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

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    taskExecMessageWin.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            return new ExecMessageModalPage(model.getObject().getMessage());
                        }
                    });
                    taskExecMessageWin.show(target);
                }
            }, ActionLink.ActionType.EDIT, "Tasks", "read",
                    StringUtils.hasText(model.getObject().getMessage()));

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    try {
                        taskRestClient.deleteExecution(taskExecutionTO.getId());

                        taskTO.removeExecution(taskExecutionTO);

                        info(getString("operation_succeded"));
                    } catch (SyncopeClientCompositeErrorException scce) {
                        error(scce.getMessage());
                    }

                    target.add(feedbackPanel);
                    target.add(executions);
                }
            }, ActionLink.ActionType.DELETE, "Tasks", "delete");

            cellItem.add(panel);
        }
    });

    final AjaxFallbackDefaultDataTable table = new AjaxFallbackDefaultDataTable("executionsTable", columns,
            new TaskExecutionsProvider(taskTO), 10);

    executions.add(table);
}