Search in sources :

Example 1 with IHeaderResponse

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

the class OrgTreePanel method initLayout.

private void initLayout() {
    WebMarkupContainer treeHeader = new WebMarkupContainer(ID_TREE_HEADER);
    treeHeader.setOutputMarkupId(true);
    add(treeHeader);
    String title = StringUtils.isEmpty(treeTitleKey) ? "TreeTablePanel.hierarchy" : treeTitleKey;
    Label treeTitle = new Label(ID_TREE_TITLE, createStringResource(title));
    treeHeader.add(treeTitle);
    InlineMenu treeMenu = new InlineMenu(ID_TREE_MENU, new Model<>((Serializable) createTreeMenuInternal()));
    treeHeader.add(treeMenu);
    ISortableTreeProvider provider = new OrgTreeProvider(this, getModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<InlineMenuItem> createInlineMenuItems(OrgType org) {
            return createTreeChildrenMenu(org);
        }
    };
    List<IColumn<SelectableBean<OrgType>, String>> columns = new ArrayList<>();
    if (selectable) {
        columns.add(new CheckBoxHeaderColumn<SelectableBean<OrgType>>());
    }
    columns.add(new TreeColumn<SelectableBean<OrgType>, String>(createStringResource("TreeTablePanel.hierarchy")));
    columns.add(new InlineMenuHeaderColumn(createTreeChildrenMenu(null)));
    WebMarkupContainer treeContainer = new WebMarkupContainer(ID_TREE_CONTAINER) {

        private static final long serialVersionUID = 1L;

        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead(response);
            // method computes height based on document.innerHeight() -
            // screen height;
            Component form = OrgTreePanel.this.getParent().get("memberPanel");
            if (form != null) {
                response.render(OnDomReadyHeaderItem.forScript("updateHeight('" + getMarkupId() + "', ['#" + form.getMarkupId() + "'], ['#" + OrgTreePanel.this.get(ID_TREE_HEADER).getMarkupId() + "'])"));
            }
        }
    };
    add(treeContainer);
    TreeStateModel treeStateMode = new TreeStateModel(this, provider) {

        private static final long serialVersionUID = 1L;

        @Override
        public Set<SelectableBean<OrgType>> getExpandedItems() {
            return OrgTreePanel.this.getExpandedItems(getOrgTreeStateStorage());
        }

        @Override
        public SelectableBean<OrgType> getCollapsedItem() {
            return OrgTreePanel.this.getCollapsedItem(getOrgTreeStateStorage());
        }

        @Override
        public void setCollapsedItem(SelectableBean<OrgType> item) {
            OrgTreePanel.this.setCollapsedItem(null, getOrgTreeStateStorage());
        }
    };
    TableTree<SelectableBean<OrgType>, String> tree = new TableTree<SelectableBean<OrgType>, String>(ID_TREE, columns, provider, Integer.MAX_VALUE, treeStateMode) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Component newContentComponent(String id, IModel<SelectableBean<OrgType>> model) {
            return new SelectableFolderContent(id, this, model, selected) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onClick(AjaxRequestTarget target) {
                    super.onClick(target);
                    OrgTreePanel.this.setSelectedItem(selected.getObject(), getOrgTreeStateStorage());
                    selectTreeItemPerformed(selected.getObject(), target);
                }
            };
        }

        @Override
        protected Item<SelectableBean<OrgType>> newRowItem(String id, int index, final IModel<SelectableBean<OrgType>> model) {
            Item<SelectableBean<OrgType>> item = super.newRowItem(id, index, model);
            item.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() {

                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    SelectableBean<OrgType> itemObject = model.getObject();
                    if (itemObject != null && itemObject.equals(selected.getObject())) {
                        return "success";
                    }
                    return null;
                }
            }));
            return item;
        }

        @Override
        public void collapse(SelectableBean<OrgType> collapsedItem) {
            super.collapse(collapsedItem);
            Set<SelectableBean<OrgType>> items = OrgTreePanel.this.getExpandedItems(getOrgTreeStateStorage());
            if (items != null && items.contains(collapsedItem)) {
                items.remove(collapsedItem);
            }
            OrgTreePanel.this.setExpandedItems((TreeStateSet) items, getOrgTreeStateStorage());
            OrgTreePanel.this.setCollapsedItem(collapsedItem, getOrgTreeStateStorage());
        }

        @Override
        protected void onModelChanged() {
            super.onModelChanged();
            TreeStateSet<SelectableBean<OrgType>> items = (TreeStateSet) getModelObject();
            if (!items.isInverse()) {
                OrgTreePanel.this.setExpandedItems(items, getOrgTreeStateStorage());
            }
        }
    };
    tree.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());
    tree.getTable().add(AttributeModifier.replace("class", "table table-striped table-condensed"));
    tree.add(new WindowsTheme());
    // tree.add(AttributeModifier.replace("class", "tree-midpoint"));
    treeContainer.add(tree);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Serializable(java.io.Serializable) InlineMenuHeaderColumn(com.evolveum.midpoint.web.component.data.column.InlineMenuHeaderColumn) TableTree(org.apache.wicket.extensions.markup.html.repeater.tree.TableTree) Label(org.apache.wicket.markup.html.basic.Label) WindowsTheme(org.apache.wicket.extensions.markup.html.repeater.tree.theme.WindowsTheme) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ReuseIfModelsEqualStrategy(org.apache.wicket.markup.repeater.ReuseIfModelsEqualStrategy) InlineMenu(com.evolveum.midpoint.web.component.menu.cog.InlineMenu) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) OrgTreeProvider(com.evolveum.midpoint.web.page.admin.users.component.OrgTreeProvider) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) Component(org.apache.wicket.Component) IModel(org.apache.wicket.model.IModel) SelectableFolderContent(com.evolveum.midpoint.web.page.admin.users.component.SelectableFolderContent) TreeStateSet(com.evolveum.midpoint.web.page.admin.users.dto.TreeStateSet) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) ISortableTreeProvider(org.apache.wicket.extensions.markup.html.repeater.tree.ISortableTreeProvider) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)

Example 2 with IHeaderResponse

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

the class HtmlHeaderContainer method onComponentTagBody.

/**
 * First render the body of the component. And if it is the header component of a Page (compared
 * to a Panel or Border), then get the header sections from all component in the hierarchy and
 * render them as well.
 */
@Override
public final void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
    // We are able to automatically add <head> to the page if it is
    // missing. But we only want to add it, if we have content to be
    // written to its body. Thus we first write the output into a
    // StringResponse and if not empty, we copy it to the original
    // web response.
    // Temporarily replace the web response with a String response
    final Response webResponse = getResponse();
    try {
        // Create a (string) response for all headers contributed by any component on the Page.
        final StringResponse response = new StringResponse();
        getRequestCycle().setResponse(response);
        IHeaderResponse headerResponse = getHeaderResponse();
        if (!response.equals(headerResponse.getResponse())) {
            getRequestCycle().setResponse(headerResponse.getResponse());
        }
        // Render the header sections of all components on the page
        AbstractHeaderRenderStrategy.get().renderHeader(this, new HeaderStreamState(markupStream, openTag), getPage());
        // Close the header response before rendering the header container itself
        // See https://issues.apache.org/jira/browse/WICKET-3728
        headerResponse.close();
        // Cleanup extraneous CR and LF from the response
        CharSequence output = getCleanResponse(response);
        // Automatically add <head> if necessary
        if (output.length() > 0) {
            if (renderOpenAndCloseTags()) {
                webResponse.write("<head>");
            }
            webResponse.write(output);
            if (renderOpenAndCloseTags()) {
                webResponse.write("</head>");
            }
        }
    } finally {
        // Restore the original response
        getRequestCycle().setResponse(webResponse);
    }
}
Also used : HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse)

Example 3 with IHeaderResponse

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

the class HtmlHeaderContainer method renderHeaderTagBody.

/**
 * Renders the content of the &lt;head&gt; section of the page, including &lt;wicket:head&gt;
 * sections in subclasses of the page. For every child-component, the content is rendered to a
 * string and passed to {@link IHeaderResponse}.
 *
 * @param headerStreamState
 */
public void renderHeaderTagBody(HeaderStreamState headerStreamState) {
    if (headerStreamState == null)
        return;
    final Response oldResponse = getRequestCycle().getResponse();
    try {
        // Create a separate (string) response for the header container itself
        final StringResponse bodyResponse = new StringResponse();
        getRequestCycle().setResponse(bodyResponse);
        // render the header section directly associated with the markup
        super.onComponentTagBody(headerStreamState.getMarkupStream(), headerStreamState.getOpenTag());
        CharSequence bodyOutput = getCleanResponse(bodyResponse);
        if (bodyOutput.length() > 0) {
            getHeaderResponse().render(new PageHeaderItem(bodyOutput));
        }
    } finally {
        getRequestCycle().setResponse(oldResponse);
    }
}
Also used : HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) StringResponse(org.apache.wicket.response.StringResponse) PageHeaderItem(org.apache.wicket.markup.head.PageHeaderItem)

Example 4 with IHeaderResponse

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

the class AbstractHeaderRenderStrategy method renderApplicationLevelHeaders.

/**
 * Render the application level headers
 *
 * @param headerContainer
 */
protected final void renderApplicationLevelHeaders(final HtmlHeaderContainer headerContainer) {
    Args.notNull(headerContainer, "headerContainer");
    if (Application.exists()) {
        HeaderContributorListenerCollection headerContributorListenerCollection = Application.get().getHeaderContributorListeners();
        IHeaderResponse headerResponse = headerContainer.getHeaderResponse();
        for (IHeaderContributor listener : headerContributorListenerCollection) {
            listener.renderHead(headerResponse);
        }
    }
}
Also used : IHeaderContributor(org.apache.wicket.markup.html.IHeaderContributor) HeaderContributorListenerCollection(org.apache.wicket.application.HeaderContributorListenerCollection) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse)

Example 5 with IHeaderResponse

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

the class SimplePage1 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)

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