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

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

Introduction

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

Prototype

public final Component setVisible(final boolean visible) 

Source Link

Document

Sets whether this component and any children are visible.

Usage

From source file:org.apache.syncope.client.console.pages.ResultStatusModalPage.java

License:Apache License

private ResultStatusModalPage(final Builder builder) {
    super();/* www . j  a va2 s  .c  o  m*/
    this.subject = builder.subject;
    statusUtils = new StatusUtils(this.userRestClient);
    if (builder.mode == null) {
        this.mode = Mode.ADMIN;
    } else {
        this.mode = builder.mode;
    }

    final BaseModalPage page = this;

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

    final Fragment fragment = new Fragment("resultFrag",
            mode == Mode.SELF ? "userSelfResultFrag" : "propagationResultFrag", this);
    fragment.setOutputMarkupId(true);
    container.add(fragment);

    if (mode == Mode.ADMIN) {
        // add Syncope propagation status
        PropagationStatus syncope = new PropagationStatus();
        syncope.setResource("Syncope");
        syncope.setStatus(PropagationTaskExecStatus.SUCCESS);

        List<PropagationStatus> propagations = new ArrayList<PropagationStatus>();
        propagations.add(syncope);
        propagations.addAll(subject.getPropagationStatusTOs());

        fragment.add(new Label("info",
                ((subject instanceof UserTO) && ((UserTO) subject).getUsername() != null)
                        ? ((UserTO) subject).getUsername()
                        : ((subject instanceof GroupTO) && ((GroupTO) subject).getName() != null)
                                ? ((GroupTO) subject).getName()
                                : String.valueOf(subject.getKey())));

        final ListView<PropagationStatus> propRes = new ListView<PropagationStatus>("resources", propagations) {

            private static final long serialVersionUID = -1020475259727720708L;

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

                final ListView attributes = getConnObjectView(propTO);

                final Fragment attrhead;
                if (attributes.getModelObject() == null || attributes.getModelObject().isEmpty()) {
                    attrhead = new Fragment("attrhead", "emptyAttrHeadFrag", page);
                } else {
                    attrhead = new Fragment("attrhead", "attrHeadFrag", page);
                }

                item.add(attrhead);
                item.add(attributes);

                attrhead.add(new Label("resource", propTO.getResource()));

                attrhead.add(new Label("propagation",
                        propTO.getStatus() == null ? "UNDEFINED" : propTO.getStatus().toString()));

                final Image image;
                final String alt, title;
                final ModalWindow failureWindow = new ModalWindow("failureWindow");
                final AjaxLink<?> failureWindowLink = new AjaxLink<Void>("showFailureWindow") {

                    private static final long serialVersionUID = -7978723352517770644L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        failureWindow.show(target);
                    }
                };

                switch (propTO.getStatus()) {

                case SUCCESS:
                case SUBMITTED:
                case CREATED:
                    image = new Image("icon", new ContextRelativeResource(
                            IMG_PREFIX + Status.ACTIVE.toString() + Constants.PNG_EXT));
                    alt = "success icon";
                    title = "success";
                    failureWindow.setVisible(false);
                    failureWindowLink.setEnabled(false);
                    break;

                default:
                    image = new Image("icon", new ContextRelativeResource(
                            IMG_PREFIX + Status.SUSPENDED.toString() + Constants.PNG_EXT));
                    alt = "failure icon";
                    title = "failure";
                }

                image.add(new Behavior() {

                    private static final long serialVersionUID = 1469628524240283489L;

                    @Override
                    public void onComponentTag(final Component component, final ComponentTag tag) {
                        tag.put("alt", alt);
                        tag.put("title", title);
                    }
                });
                final FailureMessageModalPage executionFailureMessagePage;
                if (propTO.getFailureReason() == null) {
                    executionFailureMessagePage = new FailureMessageModalPage(failureWindow.getContentId(),
                            StringUtils.EMPTY);
                } else {
                    executionFailureMessagePage = new FailureMessageModalPage(failureWindow.getContentId(),
                            propTO.getFailureReason());
                }

                failureWindow.setPageCreator(new ModalWindow.PageCreator() {

                    private static final long serialVersionUID = -7834632442532690940L;

                    @Override
                    public Page createPage() {
                        return executionFailureMessagePage;
                    }
                });
                failureWindow.setCookieName("failureWindow");
                failureWindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
                failureWindowLink.add(image);
                attrhead.add(failureWindowLink);
                attrhead.add(failureWindow);
            }
        };
        fragment.add(propRes);
    }

    final AjaxLink<Void> close = new IndicatingAjaxLink<Void>("close") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            builder.window.close(target);
        }
    };
    container.add(close);

    setOutputMarkupId(true);
}

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

License:Apache License

private ResultStatusModalPage(final Builder builder) {
    super();/*from ww  w .jav  a 2  s .c om*/
    this.subject = builder.subject;
    statusUtils = new StatusUtils(this.userRestClient);
    if (builder.mode == null) {
        this.mode = UserModalPage.Mode.ADMIN;
    } else {
        this.mode = builder.mode;
    }

    final BaseModalPage page = this;

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

    final Fragment fragment = new Fragment("resultFrag",
            mode == UserModalPage.Mode.SELF ? "userSelfResultFrag" : "propagationResultFrag", this);
    fragment.setOutputMarkupId(true);
    container.add(fragment);

    if (mode == UserModalPage.Mode.ADMIN) {
        // add Syncope propagation status
        PropagationStatus syncope = new PropagationStatus();
        syncope.setResource("Syncope");
        syncope.setStatus(PropagationTaskExecStatus.SUCCESS);

        List<PropagationStatus> propagations = new ArrayList<PropagationStatus>();
        propagations.add(syncope);
        propagations.addAll(subject.getPropagationStatusTOs());

        fragment.add(new Label("info",
                ((subject instanceof UserTO) && ((UserTO) subject).getUsername() != null)
                        ? ((UserTO) subject).getUsername()
                        : ((subject instanceof RoleTO) && ((RoleTO) subject).getName() != null)
                                ? ((RoleTO) subject).getName()
                                : String.valueOf(subject.getId())));

        final ListView<PropagationStatus> propRes = new ListView<PropagationStatus>("resources", propagations) {

            private static final long serialVersionUID = -1020475259727720708L;

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

                final ListView attributes = getConnObjectView(propTO);

                final Fragment attrhead;
                if (attributes.getModelObject() == null || attributes.getModelObject().isEmpty()) {
                    attrhead = new Fragment("attrhead", "emptyAttrHeadFrag", page);
                } else {
                    attrhead = new Fragment("attrhead", "attrHeadFrag", page);
                }

                item.add(attrhead);
                item.add(attributes);

                attrhead.add(new Label("resource", propTO.getResource()));

                attrhead.add(new Label("propagation",
                        propTO.getStatus() == null ? "UNDEFINED" : propTO.getStatus().toString()));

                final Image image;
                final String alt, title;
                final ModalWindow failureWindow = new ModalWindow("failureWindow");
                final AjaxLink<?> failureWindowLink = new AjaxLink<Void>("showFailureWindow") {

                    private static final long serialVersionUID = -7978723352517770644L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        failureWindow.show(target);
                    }
                };

                switch (propTO.getStatus()) {

                case SUCCESS:
                case SUBMITTED:
                case CREATED:
                    image = new Image("icon", IMG_STATUSES + Status.ACTIVE.toString() + Constants.PNG_EXT);
                    alt = "success icon";
                    title = "success";
                    failureWindow.setVisible(false);
                    failureWindowLink.setEnabled(false);
                    break;

                default:
                    image = new Image("icon", IMG_STATUSES + Status.SUSPENDED.toString() + Constants.PNG_EXT);
                    alt = "failure icon";
                    title = "failure";
                }

                image.add(new Behavior() {

                    private static final long serialVersionUID = 1469628524240283489L;

                    @Override
                    public void onComponentTag(final Component component, final ComponentTag tag) {
                        tag.put("alt", alt);
                        tag.put("title", title);
                    }
                });
                final FailureMessageModalPage executionFailureMessagePage;
                if (propTO.getFailureReason() == null) {
                    executionFailureMessagePage = new FailureMessageModalPage(failureWindow.getContentId(),
                            StringUtils.EMPTY);
                } else {
                    executionFailureMessagePage = new FailureMessageModalPage(failureWindow.getContentId(),
                            propTO.getFailureReason());
                }

                failureWindow.setPageCreator(new ModalWindow.PageCreator() {

                    private static final long serialVersionUID = -7834632442532690940L;

                    @Override
                    public Page createPage() {
                        return executionFailureMessagePage;
                    }
                });
                failureWindow.setCookieName("failureWindow");
                failureWindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
                failureWindowLink.add(image);
                attrhead.add(failureWindowLink);
                attrhead.add(failureWindow);
            }
        };
        fragment.add(propRes);
    }

    final AjaxLink<Void> close = new IndicatingAjaxLink<Void>("close") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            if (mode == UserModalPage.Mode.SELF && anonymousUser.equals(SyncopeSession.get().getUsername())) {
                SyncopeSession.get().invalidate();
            }
            builder.window.close(target);
        }
    };
    container.add(close);

    setOutputMarkupId(true);
}

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 .  jav  a 2 s .  c  om*/

    //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.webical.web.pages.ErrorPage.java

License:Open Source License

public void setupNonAccessibleComponents() {
    //ModelDialog for the detailmessage
    final ModalWindow modalWindow = new ModalWindow(DETAILED_ERROR_PANEL_ID);

    //The detailed message
    final String detailedMessage = getDetailedMessage();

    //Link to show the details
    IndicatingAjaxLink showDetailsLink = new IndicatingAjaxLink(SHOW_DETAILS_LINK_MARKUP_ID) {

        private static final long serialVersionUID = 1L;

        @Override/*  w w w . j  a  v  a2s . c  o m*/
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {

            modalWindow.setContent(new DetailPanel(modalWindow.getContentId(), new Model(detailedMessage)));
            modalWindow.setVisible(true);
            modalWindow.show(ajaxRequestTarget);
        }

    };

    if (detailedMessage == null) {
        showDetailsLink.setEnabled(false);
    } else {
        modalWindow.setInitialWidth(700);
        modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

            private static final long serialVersionUID = 1L;

            public void onClose(AjaxRequestTarget ajaxRequestTarget) {
                modalWindow.setContent(new Label(modalWindow.getContentId(), new Model("")));
                modalWindow.setVisible(false);
                ajaxRequestTarget.addComponent(modalWindow);
                getSession().createAutoPageMap();
            }

        });
    }

    //Add components
    addOrReplace(modalWindow);
    addOrReplace(showDetailsLink);
}

From source file:org.xaloon.wicket.component.classifier.panel.ClassifierItemListPanel.java

License:Apache License

protected void addCreateNewClassifierItem(final ClassifierItemOptions classifierItemOptions,
        final ClassifierDropDownChoice classifierDropDownChoice) {
    final ModalWindow modal2 = new CustomModalWindow("modal2") {
        private static final long serialVersionUID = 1L;

        @Override// w  w  w. j  av a 2s  .  c  o  m
        protected void addComponentsToRefresh(java.util.List<Component> components) {
            components.add(ClassifierItemListPanel.this);
        };
    };
    PageParameters params = new PageParameters();
    params.set(ClassifiersPanel.PARAM_CLASSIFIER_TYPE, classifierItemOptions.getClassifierType());
    params.set(ClassifierConstants.PARENT_ITEM, parentClassifierItem);
    modal2.setContent(new NewClassifierItemPanel<ClassifierItem, Classifier>(modal2, params));
    modal2.setVisible(securityFacade.hasAny(SecurityAuthorities.CLASSIFIER_EDIT));
    add(modal2);

    add(new AjaxLink<Void>("add-new-item") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            modal2.show(target);
        }
    }.setVisible(securityFacade.hasAny(SecurityAuthorities.CLASSIFIER_EDIT)));
}