Search in sources :

Example 1 with WebApplication

use of org.apache.wicket.protocol.http.WebApplication in project midpoint by Evolveum.

the class LinksPanel method initLayout.

@Override
protected void initLayout() {
    final List<RichHyperlinkType> linksList = getModel().getObject();
    RepeatingView rowView = new RepeatingView(ID_LINKS_ROW);
    int linksListSize = linksList == null ? 0 : linksList.size();
    if (linksListSize > 0) {
        int currentColumn = 0;
        RepeatingView columnView = null;
        WebMarkupContainer row = null;
        boolean isRowAdded = false;
        for (int i = 0; i < linksListSize; i++) {
            final RichHyperlinkType link = linksList.get(i);
            if (WebComponentUtil.isAuthorized(link.getAuthorization())) {
                if (currentColumn == 0) {
                    row = new WebMarkupContainer(rowView.newChildId());
                    isRowAdded = false;
                    columnView = new RepeatingView(ID_LINKS_COLUMN);
                }
                WebMarkupContainer column = new WebMarkupContainer(columnView.newChildId());
                Link linkItem = new Link(ID_LINK) {

                    @Override
                    public void onClick() {
                    }

                    @Override
                    protected void onComponentTag(final ComponentTag tag) {
                        super.onComponentTag(tag);
                        String rootContext = "";
                        //TODO: what is this for???
                        if (link.getTargetUrl() != null && !link.getTargetUrl().startsWith("http://") && !link.getTargetUrl().startsWith("https://") && !link.getTargetUrl().startsWith("www://") && !link.getTargetUrl().startsWith("//")) {
                            WebApplication webApplication = WebApplication.get();
                            if (webApplication != null) {
                                ServletContext servletContext = webApplication.getServletContext();
                                if (servletContext != null) {
                                    rootContext = servletContext.getContextPath();
                                }
                            }
                        }
                        tag.put("href", rootContext + (link.getTargetUrl() == null ? "#" : link.getTargetUrl()));
                    }
                };
                linkItem.add(new Label(ID_IMAGE) {

                    @Override
                    protected void onComponentTag(final ComponentTag tag) {
                        super.onComponentTag(tag);
                        String cssClass = ICON_DEFAULT_CSS_CLASS;
                        if (link.getIcon() != null) {
                            cssClass = link.getIcon().getCssClass();
                        }
                        tag.put("class", "info-box-icon " + (link.getColor() != null ? (link.getColor().startsWith("bg-") ? link.getColor() : "bg-" + link.getColor()) : "") + " " + cssClass);
                    }
                });
                linkItem.add(new Label(ID_LABEL, new Model<String>() {

                    public String getObject() {
                        return link.getLabel();
                    }
                }));
                Label description = new Label(ID_DESCRIPTION, new Model<String>() {

                    public String getObject() {
                        return link.getDescription();
                    }
                });
                description.setEnabled(false);
                linkItem.add(description);
                column.add(linkItem);
                columnView.add(column);
                if (currentColumn == 1 || (linksList.indexOf(link) == linksListSize - 1)) {
                    row.add(columnView);
                    rowView.add(row);
                    currentColumn = 0;
                    isRowAdded = true;
                } else {
                    currentColumn++;
                }
            } else {
                LOGGER.trace("Link {} not authorized, skipping", link);
            }
        }
        if (row != null && columnView != null && !isRowAdded) {
            row.add(columnView);
            rowView.add(row);
        }
    }
    add(rowView);
}
Also used : RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ComponentTag(org.apache.wicket.markup.ComponentTag) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) ServletContext(javax.servlet.ServletContext) WebApplication(org.apache.wicket.protocol.http.WebApplication) Link(org.apache.wicket.markup.html.link.Link)

Aggregations

ServletContext (javax.servlet.ServletContext)1 ComponentTag (org.apache.wicket.markup.ComponentTag)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 Label (org.apache.wicket.markup.html.basic.Label)1 Link (org.apache.wicket.markup.html.link.Link)1 RepeatingView (org.apache.wicket.markup.repeater.RepeatingView)1 IModel (org.apache.wicket.model.IModel)1 Model (org.apache.wicket.model.Model)1 WebApplication (org.apache.wicket.protocol.http.WebApplication)1