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);
}
Aggregations