Skip to content

Commit

Permalink
links panel label/description now can be localized
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Nov 30, 2017
1 parent a6843bc commit c85bfd0
Showing 1 changed file with 101 additions and 78 deletions.
Expand Up @@ -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;
Expand All @@ -38,7 +39,9 @@
* @author Kate Honchar
*/
public class LinksPanel extends SimplePanel<List<RichHyperlinkType>> {

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";
Expand All @@ -50,8 +53,6 @@ public class LinksPanel extends SimplePanel<List<RichHyperlinkType>> {

private static final Trace LOGGER = TraceManager.getTrace(LinksPanel.class);

IModel<List<RichHyperlinkType>> model;

public LinksPanel(String id) {
super(id, null);
}
Expand All @@ -65,93 +66,115 @@ protected void initLayout() {

final List<RichHyperlinkType> 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<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++;
linkItem.add(new Label(ID_LABEL, new AbstractReadOnlyModel<String>() {

@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<String>() {

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

0 comments on commit c85bfd0

Please sign in to comment.