Search in sources :

Example 1 with NonCachingImage

use of org.apache.wicket.markup.html.image.NonCachingImage in project syncope by apache.

the class BinaryPDFPreviewer method preview.

@Override
public Component preview(final byte[] uploadedBytes) {
    firstPage = null;
    try (InputStream bais = new ByteArrayInputStream(uploadedBytes);
        PDDocument document = PDDocument.load(bais, MemoryUsageSetting.setupTempFileOnly())) {
        document.setResourceCache(new DefaultResourceCache() {

            @Override
            public void put(final COSObject indirect, final PDXObject xobject) throws IOException {
            }
        });
        if (document.isEncrypted()) {
            LOG.info("Document is encrypted, no preview is possible");
        } else {
            firstPage = new PDFRenderer(document).renderImageWithDPI(0, DPI, IMAGE_TYPE);
        }
    } catch (IOException e) {
        LOG.error("While generating thumbnail from first page", e);
    }
    Fragment fragment;
    if (firstPage == null) {
        fragment = new Fragment("preview", "noPreviewFragment", this);
    } else {
        fragment = new Fragment("preview", "previewFragment", this);
        fragment.add(new NonCachingImage("previewImage", new ThumbnailImageResource(firstPage)));
    }
    WebMarkupContainer previewContainer = new WebMarkupContainer("previewContainer");
    previewContainer.setOutputMarkupId(true);
    previewContainer.add(fragment);
    return this.addOrReplace(previewContainer);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NonCachingImage(org.apache.wicket.markup.html.image.NonCachingImage) IOException(java.io.IOException) Fragment(org.apache.wicket.markup.html.panel.Fragment) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) DefaultResourceCache(org.apache.pdfbox.pdmodel.DefaultResourceCache) ByteArrayInputStream(java.io.ByteArrayInputStream) COSObject(org.apache.pdfbox.cos.COSObject) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) PDFRenderer(org.apache.pdfbox.rendering.PDFRenderer) PDXObject(org.apache.pdfbox.pdmodel.graphics.PDXObject)

Example 2 with NonCachingImage

use of org.apache.wicket.markup.html.image.NonCachingImage in project midpoint by Evolveum.

the class AbstractSummaryPanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    box = new WebMarkupContainer(ID_BOX);
    add(box);
    IModel<String> archetypePolicyAdditionalCssClassModel = () -> {
        String archetypePolicyAdditionalCssClass = getArchetypePolicyAdditionalCssClass();
        if (archetypePolicyAdditionalCssClass == null) {
            return "";
        }
        return "border-color: " + archetypePolicyAdditionalCssClass + ";";
    };
    box.add(new AttributeModifier("class", BOX_CSS_CLASS + " " + getBoxAdditionalCssClass()));
    box.add(AttributeModifier.append("style", archetypePolicyAdditionalCssClassModel));
    if (getDisplayNameModel() != null) {
        box.add(new Label(ID_DISPLAY_NAME, getDisplayNameModel()));
    } else if (getDisplayNamePropertyName() != null) {
        box.add(new Label(ID_DISPLAY_NAME, createLabelModel(getDisplayNamePropertyName(), SummaryPanelSpecificationType.F_DISPLAY_NAME)));
    } else {
        box.add(new Label(ID_DISPLAY_NAME, " "));
    }
    WebMarkupContainer identifierPanel = new WebMarkupContainer(ID_IDENTIFIER_PANEL);
    identifierPanel.add(new Label(ID_IDENTIFIER, createLabelModel(getIdentifierPropertyName(), SummaryPanelSpecificationType.F_IDENTIFIER)));
    identifierPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isIdentifierVisible();
        }
    });
    box.add(identifierPanel);
    AjaxButton navigateToObject = new AjaxButton(ID_NAVIGATE_TO_OBJECT_BUTTON) {

        @Override
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            ObjectReferenceType ort = getReferencedObjectToNavigate();
            WebComponentUtil.dispatchToObjectDetailsPage(ort, AbstractSummaryPanel.this, false);
        }
    };
    navigateToObject.add(AttributeAppender.append("title", getReferenceObjectTitleModel()));
    navigateToObject.add(new VisibleBehaviour(() -> {
        ObjectReferenceType ort = getReferencedObjectToNavigate();
        Class refType = !isReferencedObjectNull() ? WebComponentUtil.qnameToClass(AbstractSummaryPanel.this.getPageBase().getPrismContext(), ort.getType()) : null;
        return ort != null && refType != null && WebComponentUtil.getObjectDetailsPage(refType) != null;
    }));
    navigateToObject.setOutputMarkupId(true);
    box.add(navigateToObject);
    if (getTitleModel() != null) {
        box.add(new Label(ID_TITLE, getTitleModel()));
    } else if (getTitlePropertyName() != null) {
        box.add(new Label(ID_TITLE, createLabelModel(getTitlePropertyName(), SummaryPanelSpecificationType.F_TITLE_1)));
    } else {
        box.add(new Label(ID_TITLE, " "));
    }
    if (getTitle2Model() != null) {
        box.add(new Label(ID_TITLE2, getTitle2Model()));
    } else if (getTitle2PropertyName() != null) {
        box.add(new Label(ID_TITLE, createLabelModel(getTitle2PropertyName(), SummaryPanelSpecificationType.F_TITLE_2)));
    } else {
        Label label = new Label(ID_TITLE2, " ");
        label.setVisible(false);
        box.add(label);
    }
    if (getTitle3Model() != null) {
        box.add(new Label(ID_TITLE3, getTitle3Model()));
    } else if (getTitle3PropertyName() != null) {
        box.add(new Label(ID_TITLE, createLabelModel(getTitle3PropertyName(), SummaryPanelSpecificationType.F_TITLE_3)));
    } else {
        Label label = new Label(ID_TITLE3, " ");
        label.setVisible(false);
        box.add(label);
    }
    final IModel<String> parentOrgModel = getParentOrgModel();
    Label parentOrgLabel = new Label(ID_ORGANIZATION, parentOrgModel);
    parentOrgLabel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return parentOrgModel.getObject() != null;
        }
    });
    box.add(parentOrgLabel);
    iconBox = new WebMarkupContainer(ID_ICON_BOX);
    box.add(iconBox);
    String iconAdditionalCssClass = getIconBoxAdditionalCssClass();
    if (StringUtils.isNotEmpty(iconAdditionalCssClass)) {
        iconBox.add(new AttributeModifier("class", ICON_BOX_CSS_CLASS + " " + iconAdditionalCssClass));
    }
    iconBox.add(AttributeModifier.append("style", createArchetypeBackgroundModel()));
    Label icon = new Label(ID_ICON, "");
    icon.add(AttributeModifier.append("class", getIconCssClass()));
    // String archetypeIconCssClass = getArchetypeIconCssClass();
    // if (StringUtils.isNotEmpty(archetypeIconCssClass)) {
    // icon.add(AttributeModifier.append("class", archetypeIconCssClass));
    // icon.add(AttributeModifier.append("style", ARCHETYPE_ICON_FONT_SIZE));
    // } else {
    // icon.add(AttributeModifier.append("class", getDefaultIconCssClass()));
    // }
    icon.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getPhotoModel().getObject() == null;
        }
    });
    iconBox.add(icon);
    NonCachingImage img = new NonCachingImage(ID_PHOTO, getPhotoModel());
    img.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getPhotoModel().getObject() != null;
        }
    });
    iconBox.add(img);
    tagBox = new RepeatingView(ID_TAG_BOX);
    List<SummaryTag<C>> summaryTags = getSummaryTagComponentList();
    // if (getArchetypeSummaryTag() != null) {
    summaryTags.add(getArchetypeSummaryTag());
    // }
    summaryTags.forEach(summaryTag -> {
        WebMarkupContainer summaryTagPanel = new WebMarkupContainer(tagBox.newChildId());
        summaryTagPanel.setOutputMarkupId(true);
        summaryTagPanel.add(summaryTag);
        tagBox.add(summaryTagPanel);
    });
    if (getTagBoxCssClass() != null) {
        tagBox.add(new AttributeModifier("class", getTagBoxCssClass()));
    }
    tagBox.add(new VisibleBehaviour(() -> CollectionUtils.isNotEmpty(summaryTags)));
    box.add(tagBox);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) NonCachingImage(org.apache.wicket.markup.html.image.NonCachingImage) Label(org.apache.wicket.markup.html.basic.Label) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SummaryTag(com.evolveum.midpoint.web.component.util.SummaryTag) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 3 with NonCachingImage

use of org.apache.wicket.markup.html.image.NonCachingImage in project midpoint by Evolveum.

the class AbstractSummaryPanel method initLayoutCommon.

protected void initLayoutCommon() {
    box = new WebMarkupContainer(ID_BOX);
    add(box);
    box.add(new AttributeModifier("class", BOX_CSS_CLASS + " " + getBoxAdditionalCssClass()));
    box.add(new Label(ID_DISPLAY_NAME, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getDisplayNamePropertyName())));
    WebMarkupContainer identifierPanel = new WebMarkupContainer(ID_IDENTIFIER_PANEL);
    identifierPanel.add(new Label(ID_IDENTIFIER, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getIdentifierPropertyName())));
    identifierPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return isIdentifierVisible();
        }
    });
    box.add(identifierPanel);
    if (getTitlePropertyName() != null) {
        box.add(new Label(ID_TITLE, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getTitlePropertyName())));
    } else if (getTitleModel() != null) {
        box.add(new Label(ID_TITLE, getTitleModel()));
    } else {
        box.add(new Label(ID_TITLE, " "));
    }
    if (getTitle2PropertyName() != null) {
        box.add(new Label(ID_TITLE2, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getTitle2PropertyName())));
    } else if (getTitle2Model() != null) {
        box.add(new Label(ID_TITLE2, getTitle2Model()));
    } else {
        Label label = new Label(ID_TITLE2, " ");
        label.setVisible(false);
        box.add(label);
    }
    if (getTitle3PropertyName() != null) {
        box.add(new Label(ID_TITLE3, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getTitle3PropertyName())));
    } else if (getTitle3Model() != null) {
        box.add(new Label(ID_TITLE3, getTitle3Model()));
    } else {
        Label label = new Label(ID_TITLE3, " ");
        label.setVisible(false);
        box.add(label);
    }
    Label parentOrgLabel = new Label(ID_ORGANIZATION, getParentOrgModel());
    parentOrgLabel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getParentOrgModel().getObject() != null;
        }
    });
    box.add(parentOrgLabel);
    iconBox = new WebMarkupContainer(ID_ICON_BOX);
    box.add(iconBox);
    if (getIconBoxAdditionalCssClass() != null) {
        iconBox.add(new AttributeModifier("class", ICON_BOX_CSS_CLASS + " " + getIconBoxAdditionalCssClass()));
    }
    Label icon = new Label(ID_ICON, "");
    icon.add(new AttributeModifier("class", getIconCssClass()));
    icon.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getPhotoModel().getObject() == null;
        }
    });
    iconBox.add(icon);
    NonCachingImage img = new NonCachingImage(ID_PHOTO, getPhotoModel());
    img.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getPhotoModel().getObject() != null;
        }
    });
    iconBox.add(img);
    tagBox = new WebMarkupContainer(ID_TAG_BOX);
    if (getTagBoxCssClass() != null) {
        tagBox.add(new AttributeModifier("class", getTagBoxCssClass()));
    }
    box.add(tagBox);
}
Also used : PrismPropertyRealValueFromContainerableModel(com.evolveum.midpoint.web.model.PrismPropertyRealValueFromContainerableModel) NonCachingImage(org.apache.wicket.markup.html.image.NonCachingImage) Label(org.apache.wicket.markup.html.basic.Label) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 4 with NonCachingImage

use of org.apache.wicket.markup.html.image.NonCachingImage in project midpoint by Evolveum.

the class UserMenuPanel method initLayout.

private void initLayout() {
    WebMarkupContainer iconBox = new WebMarkupContainer(ID_ICON_BOX);
    add(iconBox);
    IModel<AbstractResource> jpegPhotoModel = loadJpegPhotoModel();
    NonCachingImage img = new NonCachingImage(ID_PHOTO, jpegPhotoModel);
    iconBox.add(img);
    Label usernameLink = new Label(ID_USERNAME_LINK, (IModel<String>) this::getShortUserName);
    add(usernameLink);
    WebMarkupContainer panelIconBox = new WebMarkupContainer(ID_PANEL_ICON_BOX);
    add(panelIconBox);
    NonCachingImage panelImg = new NonCachingImage(ID_PANEL_PHOTO, jpegPhotoModel);
    panelIconBox.add(panelImg);
    Label username = new Label(ID_USERNAME, (IModel<String>) this::getShortUserName);
    username.setRenderBodyOnly(true);
    add(username);
    Label focusType = new Label(ID_FOCUS_TYPE, getPageBase().createStringResource("PageTemplate." + getFocusType()));
    add(focusType);
    MidpointForm<?> form = new MidpointForm<>(ID_LOGOUT_FORM);
    form.add(AttributeModifier.replace("action", (IModel<String>) () -> SecurityUtils.getPathForLogoutWithContextPath(getRequest().getContextPath(), getAuthenticatedModule().getPrefix())));
    add(form);
    WebMarkupContainer csrfField = SecurityUtils.createHiddenInputForCsrf(ID_CSRF_FIELD);
    form.add(csrfField);
}
Also used : IModel(org.apache.wicket.model.IModel) NonCachingImage(org.apache.wicket.markup.html.image.NonCachingImage) Label(org.apache.wicket.markup.html.basic.Label) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AbstractResource(org.apache.wicket.request.resource.AbstractResource) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Aggregations

WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)4 NonCachingImage (org.apache.wicket.markup.html.image.NonCachingImage)4 Label (org.apache.wicket.markup.html.basic.Label)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)2 AttributeModifier (org.apache.wicket.AttributeModifier)2 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)1 SummaryTag (com.evolveum.midpoint.web.component.util.SummaryTag)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 PrismPropertyRealValueFromContainerableModel (com.evolveum.midpoint.web.model.PrismPropertyRealValueFromContainerableModel)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 COSObject (org.apache.pdfbox.cos.COSObject)1 DefaultResourceCache (org.apache.pdfbox.pdmodel.DefaultResourceCache)1 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)1 PDXObject (org.apache.pdfbox.pdmodel.graphics.PDXObject)1 PDFRenderer (org.apache.pdfbox.rendering.PDFRenderer)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 Fragment (org.apache.wicket.markup.html.panel.Fragment)1 RepeatingView (org.apache.wicket.markup.repeater.RepeatingView)1