// Cycle through the messages
for (int i = 0; i < messages.size(); i++) {
final Message m = messages.get(i);
FreenetJs.log("REDRAWING MESSAGE:" + m.getMsg());
// The panel which will hold the message
HorizontalPanel hpanel = new HorizontalPanel();
// Sets the background color based on the priority
switch (m.getPriority()) {
case MINOR:
hpanel.getElement().getStyle().setProperty("background", "green");
break;
case WARNING:
hpanel.getElement().getStyle().setProperty("background", "yellow");
break;
case ERROR:
hpanel.getElement().getStyle().setProperty("background", "orange");
break;
case CRITICAL:
hpanel.getElement().getStyle().setProperty("background", "red");
break;
}
// Sets some css properties
hpanel.getElement().getStyle().setProperty("width", "100%");
hpanel.getElement().getStyle().setProperty("height", "100%");
hpanel.getElement().getStyle().setProperty("display", "block");
hpanel.getElement().getStyle().setPropertyPx("padding", 3);
// The short description label
Label msgLabel = new Label(m.getMsg());
hpanel.add(msgLabel);
msgLabel.getElement().getParentElement().getStyle().setProperty("border", "none");
if (m.getAnchor() != null) {
Anchor showElement = new Anchor(L10n.get("show"), "/alerts/#" + m.getAnchor());
hpanel.add(showElement);
showElement.getElement().getParentElement().getStyle().setProperty("border", "none");
}
if (m.isCanDismiss()) {
// The hide link, it will hide the message if clicked on
Anchor hideElement = new Anchor(L10n.get("hide"));
hideElement.addMouseDownHandler(new MouseDownHandler() {
@Override
public void onMouseDown(MouseDownEvent event) {
// Only send a request if the message is originated from the server
if (m.getAnchor() != null) {
FreenetRequest.sendRequest(UpdaterConstants.dismissAlertPath, new QueryParameter("anchor", m.getAnchor()), new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
// When a response is got, the server is already removed the message. We can remove it too safely
removeMessage(m);
}
@Override
public void onError(Request request, Throwable exception) {
// Don't do anything. If the server removed the message, it will push the change, if not, the user will try again
}
});
} else {
// If it is originated from the client, then simply hide it
messages.remove(m);
redrawMessages();
}
}
});
hpanel.add(hideElement);
hideElement.getElement().getParentElement().getStyle().setProperty("border", "none");
}
// Adds the message to the panel
messagesPanel.add(hpanel);