diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/component/LinksPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/component/LinksPanel.java index a8c36010642..591eef84a8b 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/component/LinksPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/component/LinksPanel.java @@ -26,6 +26,7 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.repeater.RepeatingView; +import org.apache.wicket.model.AbstractReadOnlyModel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import org.apache.wicket.protocol.http.WebApplication; @@ -38,7 +39,9 @@ * @author Kate Honchar */ public class LinksPanel extends SimplePanel> { + private static final String DOT_CLASS = LinksPanel.class.getName() + "."; + private static final String ID_IMAGE = "imageId"; private static final String ID_LINK = "link"; private static final String ID_LABEL = "labelId"; @@ -50,8 +53,6 @@ public class LinksPanel extends SimplePanel> { private static final Trace LOGGER = TraceManager.getTrace(LinksPanel.class); - IModel> model; - public LinksPanel(String id) { super(id, null); } @@ -65,93 +66,115 @@ protected void initLayout() { final List linksList = getModel().getObject(); RepeatingView rowView = new RepeatingView(ID_LINKS_ROW); + add(rowView); 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() { - } + if (linksListSize == 0) { + return; + } - @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(); + + 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())) { + LOGGER.trace("Link {} not authorized, skipping", link); + continue; + } + + 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("class", "info-box-icon " + (link.getColor() != null ? - (link.getColor().startsWith("bg-") ? link.getColor() : "bg-" + link.getColor()) : "") + " " - + cssClass); } - }); + } + 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() { - public String getObject() { - return link.getLabel(); - } - })); - Label description = new Label(ID_DESCRIPTION, new Model() { - 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++; + linkItem.add(new Label(ID_LABEL, new AbstractReadOnlyModel() { + + @Override + public String getObject() { + String key = link.getLabel(); + if (key == null) { + return null; } - } else { - LOGGER.trace("Link {} not authorized, skipping", link); + return getString(key, null, key); } - } - if (row != null && columnView != null && !isRowAdded){ + })); + + Label description = new Label(ID_DESCRIPTION, new AbstractReadOnlyModel() { + + @Override + public String getObject() { + String desc = link.getDescription(); + if (desc == null) { + return null; + } + return getString(desc, null, desc); + } + }); + 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++; } } - add(rowView); + + if (row != null && columnView != null && !isRowAdded){ + row.add(columnView); + rowView.add(row); + } } }