Author: toad
Date: 2008-04-18 21:00:43 +0000 (Fri, 18 Apr 2008)
New Revision: 19400
Modified:
trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
Log:
Set the alerts icon by the most important alert
Modified: trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
2008-04-18 20:55:39 UTC (rev 19399)
+++ trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
2008-04-18 21:00:43 UTC (rev 19400)
@@ -9,6 +9,7 @@
import java.util.LinkedHashSet;
import freenet.support.HTMLNode;
+import freenet.support.Logger;
import freenet.l10n.L10n;
import freenet.node.NodeClientCore;
@@ -116,11 +117,19 @@
* /alerts/[ anchor pointing to the real alert].
*/
public HTMLNode createAlertsShort(String title) {
- HTMLNode boxNode = new HTMLNode("div", "class", "infobox
infobox-alert infobox-summary-status-box");
+ UserAlert[] alerts = getAlerts();
+ short maxLevel = Short.MAX_VALUE;
+ for(int i=0;i<alerts.length;i++) {
+ short level = alerts[i].getPriorityClass();
+ if(level < maxLevel) maxLevel = level;
+ }
+ if(maxLevel == Short.MAX_VALUE) {
+ return new HTMLNode("#", "");
+ }
+ HTMLNode boxNode = new HTMLNode("div", "class", "infobox
infobox-"+getAlertLevelName(maxLevel)+" infobox-alert
infobox-summary-status-box");
boxNode.addChild("div", "class", "infobox-header infobox
summary-status-header", title);
HTMLNode contentNode = boxNode.addChild("div", "class",
"infobox-content infobox-summary-status-content");
HTMLNode alertsNode = contentNode.addChild("ul");
- UserAlert[] alerts = getAlerts();
int totalNumber = 0;
for (int i = 0; i < alerts.length; i++) {
UserAlert alert = alerts[i];
@@ -148,17 +157,8 @@
public HTMLNode renderAlert(UserAlert userAlert) {
HTMLNode userAlertNode = null;
short level = userAlert.getPriorityClass();
- if (level <= UserAlert.CRITICAL_ERROR)
- userAlertNode = new HTMLNode("div", "class", "infobox
infobox-error");
- else if (level <= UserAlert.ERROR)
- userAlertNode = new HTMLNode("div", "class", "infobox
infobox-alert");
- else if (level <= UserAlert.WARNING)
- userAlertNode = new HTMLNode("div", "class", "infobox
infobox-warning");
- else if (level <= UserAlert.MINOR)
- userAlertNode = new HTMLNode("div", "class", "infobox
infobox-information");
+ userAlertNode = new HTMLNode("div", "class", "infobox
infobox-"+getAlertLevelName(level));
- assert userAlertNode != null: "user alert has invalid
priority!";
-
userAlertNode.addChild("div", "class", "infobox-header",
userAlert.getTitle());
HTMLNode alertContentNode = userAlertNode.addChild("div",
"class", "infobox-content");
alertContentNode.addChild(userAlert.getHTMLText());
@@ -171,6 +171,21 @@
return userAlertNode;
}
+ private String getAlertLevelName(short level) {
+ if (level <= UserAlert.CRITICAL_ERROR)
+ return "error";
+ else if (level <= UserAlert.ERROR)
+ return "alert";
+ else if (level <= UserAlert.WARNING)
+ return "warning";
+ else if (level <= UserAlert.MINOR)
+ return "minor";
+ else {
+ Logger.error(this, "Unknown alert level: "+level, new
Exception("debug"));
+ return "error";
+ }
+ }
+
/**
* Write the alert summary as HTML to a StringBuffer
*/