Search in sources :

Example 11 with IHeaderResponse

use of org.apache.wicket.markup.head.IHeaderResponse in project syncope by apache.

the class Relationships method getViewFragment.

private Fragment getViewFragment() {
    final Map<String, List<RelationshipTO>> relationships = new HashMap<>();
    addRelationship(relationships, getCurrentRelationships().toArray(new RelationshipTO[] {}));
    final Fragment viewFragment = new Fragment("relationships", "viewFragment", this);
    viewFragment.setOutputMarkupId(true);
    viewFragment.add(new Accordion("relationships", relationships.keySet().stream().map(relationship -> {
        return new AbstractTab(new ResourceModel("relationship", relationship)) {

            private static final long serialVersionUID = 1037272333056449378L;

            @Override
            public Panel getPanel(final String panelId) {
                return new ListViewPanel.Builder<>(RelationshipTO.class, pageRef).setItems(relationships.get(relationship)).includes("otherEndType", "otherEndKey").addAction(new ActionLink<RelationshipTO>() {

                    private static final long serialVersionUID = -6847033126124401556L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RelationshipTO modelObject) {
                        removeRelationships(relationships, modelObject);
                        send(Relationships.this, Broadcast.DEPTH, new ListViewReload<>(target));
                    }
                }, ActionType.DELETE, AnyEntitlement.UPDATE.getFor(anyTO.getType()), true).build(panelId);
            }
        };
    }).collect(Collectors.toList())) {

        private static final long serialVersionUID = 1037272333056449379L;

        @Override
        public void renderHead(final IHeaderResponse response) {
            super.renderHead(response);
            if (relationships.isEmpty()) {
                response.render(OnDomReadyHeaderItem.forScript(String.format("$('#emptyPlaceholder').append(\"%s\")", getString("relationships.empty.list"))));
            }
        }
    });
    final ActionsPanel<RelationshipTO> panel = new ActionsPanel<>("actions", null);
    viewFragment.add(panel);
    panel.add(new ActionLink<RelationshipTO>() {

        private static final long serialVersionUID = 3257738274365467945L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RelationshipTO ignore) {
            Fragment addFragment = new Fragment("relationships", "addFragment", Relationships.this);
            addOrReplace(addFragment);
            addFragment.add(new Specification().setRenderBodyOnly(true));
            target.add(Relationships.this);
        }
    }, ActionType.CREATE, AnyEntitlement.UPDATE.getFor(anyTO.getType())).hideLabel();
    return viewFragment;
}
Also used : Arrays(java.util.Arrays) SearchClausePanel(org.apache.syncope.client.console.panels.search.SearchClausePanel) StringUtils(org.apache.commons.lang3.StringUtils) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) EntityTO(org.apache.syncope.common.lib.to.EntityTO) ICondition(org.apache.wicket.extensions.wizard.WizardModel.ICondition) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) AnyEntitlement(org.apache.syncope.common.lib.types.AnyEntitlement) IndicatorAjaxFormComponentUpdatingBehavior(org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) ListModel(org.apache.wicket.model.util.ListModel) Component(org.apache.wicket.Component) ListViewReload(org.apache.syncope.client.console.panels.ListViewPanel.ListViewReload) PageReference(org.apache.wicket.PageReference) SearchUtils(org.apache.syncope.client.console.panels.search.SearchUtils) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) Collectors(java.util.stream.Collectors) LabelInfo(org.apache.syncope.client.console.wicket.ajax.markup.html.LabelInfo) List(java.util.List) AnyDirectoryPanel(org.apache.syncope.client.console.panels.AnyDirectoryPanel) PropertyModel(org.apache.wicket.model.PropertyModel) AnySelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnySelectionDirectoryPanel) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) AnyObjectSelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnyObjectSelectionDirectoryPanel) ResourceModel(org.apache.wicket.model.ResourceModel) Broadcast(org.apache.wicket.event.Broadcast) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink) WizardStep(org.apache.wicket.extensions.wizard.WizardStep) Constants(org.apache.syncope.client.console.commons.Constants) ActionType(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink.ActionType) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) AnyObjectSearchPanel(org.apache.syncope.client.console.panels.search.AnyObjectSearchPanel) ArrayList(java.util.ArrayList) AnyTypeClassRestClient(org.apache.syncope.client.console.rest.AnyTypeClassRestClient) IWizard(org.apache.wicket.extensions.wizard.IWizard) Fragment(org.apache.wicket.markup.html.panel.Fragment) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) Accordion(org.apache.syncope.client.console.wicket.markup.html.bootstrap.tabs.Accordion) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) RelationshipTypeRestClient(org.apache.syncope.client.console.rest.RelationshipTypeRestClient) Panel(org.apache.wicket.markup.html.panel.Panel) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) WizardMgtPanel(org.apache.syncope.client.console.wizards.WizardMgtPanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) OnDomReadyHeaderItem(org.apache.wicket.markup.head.OnDomReadyHeaderItem) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Collections(java.util.Collections) IEvent(org.apache.wicket.event.IEvent) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) HashMap(java.util.HashMap) Fragment(org.apache.wicket.markup.html.panel.Fragment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SearchClausePanel(org.apache.syncope.client.console.panels.search.SearchClausePanel) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) AnyDirectoryPanel(org.apache.syncope.client.console.panels.AnyDirectoryPanel) AnySelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnySelectionDirectoryPanel) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) AnyObjectSelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnyObjectSelectionDirectoryPanel) AnyObjectSearchPanel(org.apache.syncope.client.console.panels.search.AnyObjectSearchPanel) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) Panel(org.apache.wicket.markup.html.panel.Panel) WizardMgtPanel(org.apache.syncope.client.console.wizards.WizardMgtPanel) ListViewReload(org.apache.syncope.client.console.panels.ListViewPanel.ListViewReload) Accordion(org.apache.syncope.client.console.wicket.markup.html.bootstrap.tabs.Accordion) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) ResourceModel(org.apache.wicket.model.ResourceModel) List(java.util.List) ArrayList(java.util.ArrayList) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Example 12 with IHeaderResponse

use of org.apache.wicket.markup.head.IHeaderResponse in project wicket by apache.

the class WebPage method validateHeaders.

/**
 * Validate that each component which wanted to contribute to the header section actually was
 * able to do so.
 */
private void validateHeaders() {
    // search for HtmlHeaderContainer in the first level of children or deeper
    // if there are transparent resolvers used
    HtmlHeaderContainer header = visitChildren(new IVisitor<Component, HtmlHeaderContainer>() {

        @Override
        public void component(final Component component, final IVisit<HtmlHeaderContainer> visit) {
            if (component instanceof HtmlHeaderContainer) {
                visit.stop((HtmlHeaderContainer) component);
            } else if (component instanceof TransparentWebMarkupContainer == false) {
                visit.dontGoDeeper();
            }
        }
    });
    if (header == null) {
        // the markup must at least contain a <body> tag for wicket to automatically
        // create a HtmlHeaderContainer. Log an error if no header container
        // was created but any of the components or behaviors want to contribute
        // something to the header.
        header = new HtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID);
        add(header);
        RequestCycle requestCycle = getRequestCycle();
        Response orgResponse = requestCycle.getResponse();
        try {
            StringResponse tempResponse = new StringResponse();
            requestCycle.setResponse(tempResponse);
            // Render all header sections of all components on the page
            AbstractHeaderRenderStrategy.get().renderHeader(header, null, getPage());
            IHeaderResponse headerResponse = header.getHeaderResponse();
            headerResponse.close();
            CharSequence collectedHeaderOutput = tempResponse.getBuffer();
            if (collectedHeaderOutput.length() > 0) {
                reportMissingHead(collectedHeaderOutput);
            }
        } catch (Exception e) {
            // just swallow this exception, there isn't much we can do about.
            log.error("header/body check throws exception", e);
        } finally {
            this.remove(header);
            requestCycle.setResponse(orgResponse);
        }
    }
}
Also used : IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) WebResponse(org.apache.wicket.request.http.WebResponse) Response(org.apache.wicket.request.Response) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) HtmlHeaderContainer(org.apache.wicket.markup.html.internal.HtmlHeaderContainer) Component(org.apache.wicket.Component)

Example 13 with IHeaderResponse

use of org.apache.wicket.markup.head.IHeaderResponse in project wicket by apache.

the class FilteringHeaderResponse method getContent.

/**
 * Gets the content that was rendered to this header response and matched the filter with the
 * given name.
 *
 * @param filterName
 *            the name of the filter to get the bucket for
 * @return the content that was accepted by the filter with this name
 */
@SuppressWarnings("resource")
public final CharSequence getContent(String filterName) {
    if (filterName == null || !responseFilterMap.containsKey(filterName)) {
        return "";
    }
    List<HeaderItem> resp = responseFilterMap.get(filterName);
    final StringResponse strResponse = new StringResponse();
    IHeaderResponse headerRenderer = new HeaderResponse() {

        @Override
        protected Response getRealResponse() {
            return strResponse;
        }

        @Override
        public boolean wasRendered(Object object) {
            return FilteringHeaderResponse.this.getRealResponse().wasRendered(object);
        }

        @Override
        public void markRendered(Object object) {
            FilteringHeaderResponse.this.getRealResponse().markRendered(object);
        }
    };
    headerRenderer = decorate(headerRenderer);
    for (HeaderItem curItem : resp) {
        headerRenderer.render(curItem);
    }
    headerRenderer.close();
    return strResponse.getBuffer();
}
Also used : HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) DecoratingHeaderResponse(org.apache.wicket.markup.html.DecoratingHeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) HeaderItem(org.apache.wicket.markup.head.HeaderItem) StringResponse(org.apache.wicket.response.StringResponse)

Example 14 with IHeaderResponse

use of org.apache.wicket.markup.head.IHeaderResponse in project wicket by apache.

the class SimplePage2 method addXXX.

private MarkupContainer addXXX(final String id, final MarkupContainer parent) {
    MarkupContainer container = new WebMarkupContainer(id);
    parent.add(container);
    container.add(new Behavior() {

        private static final long serialVersionUID = 1L;

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            response.render(CssHeaderItem.forUrl(id + ".css"));
        }
    });
    return container;
}
Also used : WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) MarkupContainer(org.apache.wicket.MarkupContainer) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) Behavior(org.apache.wicket.behavior.Behavior) Component(org.apache.wicket.Component) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 15 with IHeaderResponse

use of org.apache.wicket.markup.head.IHeaderResponse in project wicket by apache.

the class Component method internalRenderHead.

/**
 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!
 *
 * Print to the web response what ever the component wants to contribute to the head section.
 * Make sure that all attached behaviors are asked as well.
 * <p>
 * NOT intended for overriding by framework clients. Rather, use
 * {@link Component#renderHead(org.apache.wicket.markup.head.IHeaderResponse)}
 * </p>
 *
 * @param container
 *            The HtmlHeaderContainer
 */
public void internalRenderHead(final HtmlHeaderContainer container) {
    if (isVisibleInHierarchy() && isRenderAllowed()) {
        if (log.isDebugEnabled()) {
            log.debug("internalRenderHead: {}", toString(false));
        }
        IHeaderResponse response = container.getHeaderResponse();
        // Allow component to contribute
        if (response.wasRendered(this) == false) {
            StringResponse markupHeaderResponse = new StringResponse();
            Response oldResponse = getResponse();
            RequestCycle.get().setResponse(markupHeaderResponse);
            try {
                // Make sure the markup source strategy contributes to the header first
                // to be backward compatible. WICKET-3761
                getMarkupSourcingStrategy().renderHead(this, container);
                CharSequence headerContribution = markupHeaderResponse.getBuffer();
                if (Strings.isEmpty(headerContribution) == false) {
                    response.render(StringHeaderItem.forString(headerContribution));
                }
            } finally {
                RequestCycle.get().setResponse(oldResponse);
            }
            // Then let the component itself to contribute to the header
            renderHead(response);
            response.markRendered(this);
        }
        // Then ask all behaviors
        for (Behavior behavior : getBehaviors()) {
            if (isBehaviorAccepted(behavior)) {
                if (response.wasRendered(behavior) == false) {
                    behavior.renderHead(this, response);
                    List<IClusterable> pair = Arrays.asList(this, behavior);
                    response.markRendered(pair);
                }
            }
        }
    }
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) IClusterable(org.apache.wicket.util.io.IClusterable) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) Behavior(org.apache.wicket.behavior.Behavior)

Aggregations

IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)17 Component (org.apache.wicket.Component)9 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)6 Behavior (org.apache.wicket.behavior.Behavior)5 StringResponse (org.apache.wicket.response.StringResponse)5 Response (org.apache.wicket.request.Response)4 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)2 OrgTreeProvider (com.evolveum.midpoint.web.page.admin.users.component.OrgTreeProvider)2 TreeStateSet (com.evolveum.midpoint.web.page.admin.users.dto.TreeStateSet)2 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)2 ArrayList (java.util.ArrayList)2 MarkupContainer (org.apache.wicket.MarkupContainer)2 AbstractDefaultAjaxBehavior (org.apache.wicket.ajax.AbstractDefaultAjaxBehavior)2 ISortableTreeProvider (org.apache.wicket.extensions.markup.html.repeater.tree.ISortableTreeProvider)2 WindowsTheme (org.apache.wicket.extensions.markup.html.repeater.tree.theme.WindowsTheme)2 HeaderItem (org.apache.wicket.markup.head.HeaderItem)2 HeaderResponse (org.apache.wicket.markup.head.internal.HeaderResponse)2 Label (org.apache.wicket.markup.html.basic.Label)2 ReuseIfModelsEqualStrategy (org.apache.wicket.markup.repeater.ReuseIfModelsEqualStrategy)2