Search in sources :

Example 1 with ByteArrayResource

use of org.apache.wicket.request.resource.ByteArrayResource in project midpoint by Evolveum.

the class UserMenuPanel method initLayout.

private void initLayout() {
    WebMarkupContainer iconBox = new WebMarkupContainer(ID_ICON_BOX);
    add(iconBox);
    NonCachingImage img = new NonCachingImage(ID_PHOTO, new AbstractReadOnlyModel<AbstractResource>() {

        @Override
        public AbstractResource getObject() {
            if (jpegPhoto == null) {
                return null;
            } else {
                return new ByteArrayResource("image/jpeg", jpegPhoto);
            }
        }
    });
    img.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            if (userModel != null && userModel.getObject() == null) {
                loadModel(null);
            }
            return jpegPhoto != null;
        }
    });
    iconBox.add(img);
    ContextImage icon = new ContextImage(ID_ICON, "img/placeholder.png");
    icon.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            if (userModel != null && userModel.getObject() == null) {
                loadModel(null);
            }
            return jpegPhoto == null;
        }
    });
    iconBox.add(icon);
    Label usernameLink = new Label(ID_USERNAME_LINK, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            return getShortUserName();
        }
    });
    add(usernameLink);
    WebMarkupContainer panelIconBox = new WebMarkupContainer(ID_PANEL_ICON_BOX);
    add(panelIconBox);
    NonCachingImage panelImg = new NonCachingImage(ID_PANEL_PHOTO, new AbstractReadOnlyModel<AbstractResource>() {

        @Override
        public AbstractResource getObject() {
            if (jpegPhoto == null) {
                return null;
            } else {
                return new ByteArrayResource("image/jpeg", jpegPhoto);
            }
        }
    });
    panelImg.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            if (userModel != null && userModel.getObject() == null) {
                loadModel(null);
            }
            return jpegPhoto != null;
        }
    });
    panelIconBox.add(panelImg);
    ContextImage panelIcon = new ContextImage(ID_PANEL_ICON, "img/placeholder.png");
    panelIcon.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            if (userModel != null && userModel.getObject() == null) {
                loadModel(null);
            }
            return jpegPhoto == null;
        }
    });
    panelIconBox.add(panelIcon);
    Label username = new Label(ID_USERNAME, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            return getShortUserName();
        }
    });
    username.setRenderBodyOnly(true);
    add(username);
    ExternalLink logoutLink = new ExternalLink(ID_LOGOUT_LINK, new Model<>(RequestCycle.get().getRequest().getContextPath() + "/j_spring_security_logout"), createStringResource("UserMenuPanel.logout"));
    add(logoutLink);
    AjaxButton editPasswordQ = new AjaxButton(ID_PASSWORD_QUESTIONS, createStringResource("UserMenuPanel.editPasswordQuestions")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            PageMyPasswordQuestions myPasswordQuestions = new PageMyPasswordQuestions(passwordQuestionsDtoIModel);
            setResponsePage(myPasswordQuestions);
        }
    };
    add(editPasswordQ);
    if (!isPasswordModelLoaded) {
        passwordQuestionsDtoIModel = new LoadableModel<PasswordQuestionsDto>(false) {

            private static final long serialVersionUID = 1L;

            @Override
            protected PasswordQuestionsDto load() {
                return loadModel(null);
            }
        };
        isPasswordModelLoaded = true;
    }
    securityPolicyQuestionsModel = new LoadableModel<List<SecurityQuestionDefinitionType>>(false) {

        @Override
        protected List<SecurityQuestionDefinitionType> load() {
            return loadSecurityPloicyQuestionsModel();
        }
    };
    editPasswordQ.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            if (securityPolicyQuestionsModel == null || securityPolicyQuestionsModel.getObject() == null) {
                loadSecurityPloicyQuestionsModel();
            }
            return hasQuestions() || (securityPolicyQuestionsModel.getObject() != null && securityPolicyQuestionsModel.getObject().size() > 0);
        }
    });
}
Also used : NonCachingImage(org.apache.wicket.markup.html.image.NonCachingImage) Label(org.apache.wicket.markup.html.basic.Label) ContextImage(org.apache.wicket.markup.html.image.ContextImage) PageMyPasswordQuestions(com.evolveum.midpoint.web.page.admin.home.PageMyPasswordQuestions) AbstractResource(org.apache.wicket.request.resource.AbstractResource) ByteArrayResource(org.apache.wicket.request.resource.ByteArrayResource) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) PasswordQuestionsDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto)

Aggregations

AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 PageMyPasswordQuestions (com.evolveum.midpoint.web.page.admin.home.PageMyPasswordQuestions)1 PasswordQuestionsDto (com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 Label (org.apache.wicket.markup.html.basic.Label)1 ContextImage (org.apache.wicket.markup.html.image.ContextImage)1 NonCachingImage (org.apache.wicket.markup.html.image.NonCachingImage)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1 AbstractResource (org.apache.wicket.request.resource.AbstractResource)1 ByteArrayResource (org.apache.wicket.request.resource.ByteArrayResource)1