Author: nextgens
Date: 2006-12-05 17:32:11 +0000 (Tue, 05 Dec 2006)
New Revision: 11236

Modified:
   trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
Log:
Some untested code allowing column sorting to be inverted


Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2006-12-05 16:32:44 UTC (rev 11235)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2006-12-05 17:32:11 UTC (rev 11236)
@@ -39,6 +39,7 @@

        private final Node node;
        private final NodeClientCore core;
+       private boolean isInversed = false;

        protected DarknetConnectionsToadlet(Node n, NodeClientCore core, 
HighLevelSimpleClient client) {
                super(client);
@@ -69,30 +70,44 @@
                PeerNodeStatus[] peerNodeStatuses = node.getPeerNodeStatuses();
                Arrays.sort(peerNodeStatuses, new Comparator() {
                        public int compare(Object first, Object second) {
+                               int result = 0;
+                               boolean isSet = true;
                                PeerNodeStatus firstNode = (PeerNodeStatus) 
first;
                                PeerNodeStatus secondNode = (PeerNodeStatus) 
second;

                                if(request.isParameterSet("sortBy")){
                                        final String sortBy = 
request.getParam("sortBy"); 
+
                                        if(sortBy.equals("name")){
-                                               return 
firstNode.getName().compareToIgnoreCase(secondNode.getName());
+                                               result = 
firstNode.getName().compareToIgnoreCase(secondNode.getName());
                                        }else if(sortBy.equals("address")){
-                                               return 
firstNode.getPeerAddress().compareToIgnoreCase(secondNode.getPeerAddress());
+                                               result = 
firstNode.getPeerAddress().compareToIgnoreCase(secondNode.getPeerAddress());
                                        }else if(sortBy.equals("location")){
                                                double diff = 
firstNode.getLocation() - secondNode.getLocation();
-                                               return diff > 0 ? -1 : 1; // It 
shouldn't ever be equal anyway
+                                               result = diff > 0 ? -1 : 1; // 
It shouldn't ever be equal anyway
                                        }else if(sortBy.equals("version")){
-                                               return 
firstNode.getVersion().compareTo(secondNode.getVersion());
+                                               result = 
firstNode.getVersion().compareTo(secondNode.getVersion());
                                        }else if(sortBy.equals("privnote")){
-                                               return 
firstNode.getPrivateDarknetCommentNote().compareTo(secondNode.getPrivateDarknetCommentNote());
-                                       }
+                                               result = 
firstNode.getPrivateDarknetCommentNote().compareTo(secondNode.getPrivateDarknetCommentNote());
+                                       }else
+                                               isSet=false;
                                }

-                               int statusDifference = 
firstNode.getStatusValue() - secondNode.getStatusValue();
-                               if (statusDifference != 0) {
-                                       return statusDifference;
+                               if(!isSet){
+                                       int statusDifference = 
firstNode.getStatusValue() - secondNode.getStatusValue();
+                                       if (statusDifference == 0) 
+                                               result = statusDifference;
+                                       else
+                                               result = 
firstNode.getName().compareToIgnoreCase(secondNode.getName());
                                }
-                               return 
firstNode.getName().compareToIgnoreCase(secondNode.getName());
+
+                               if(request.isParameterSet("inverse")){
+                                       isInversed = true;
+                                       return (result == 0 ? 0 : (result == 1 
? -1 : 1));
+                               }else{
+                                       isInversed = false;
+                                       return result;
+                               }
                        }
                });

@@ -346,20 +361,20 @@
                                HTMLNode peerTable = peerForm.addChild("table", 
"class", "darknet_connections");
                                HTMLNode peerTableHeaderRow = 
peerTable.addChild("tr");
                                peerTableHeaderRow.addChild("th");
-                               peerTableHeaderRow.addChild("th").addChild("a", 
"href", "?sortBy=status").addChild("#", "Status");
-                               peerTableHeaderRow.addChild("th").addChild("a", 
"href", "?sortBy=name").addChild("span", new String[] { "title", "style" }, new 
String[] { "The node's name. Click on the name link to send the node a N2NTM 
(Node To Node Text Message)", "border-bottom: 1px dotted; cursor: help;" }, 
"Name");
+                               peerTableHeaderRow.addChild("th").addChild("a", 
"href", (!isInversed ? "?sortBy=status&inversed=true" : 
"?sortBy=status")).addChild("#", "Status");
+                               peerTableHeaderRow.addChild("th").addChild("a", 
"href", (!isInversed ? "?sortBy=name&inversed=true" : 
"?sortBy=name")).addChild("span", new String[] { "title", "style" }, new 
String[] { "The node's name. Click on the name link to send the node a N2NTM 
(Node To Node Text Message)", "border-bottom: 1px dotted; cursor: help;" }, 
"Name");
                                if (advancedEnabled) {
-                                       
peerTableHeaderRow.addChild("th").addChild("a", "href", 
"?sortBy=address").addChild("span", new String[] { "title", "style" }, new 
String[] { "The node's network address as IP:Port", "border-bottom: 1px dotted; 
cursor: help;" }, "Address");
+                                       
peerTableHeaderRow.addChild("th").addChild("a", "href", (!isInversed ? 
"?sortBy=address&inversed=true" : "?sortBy=address")).addChild("span", new 
String[] { "title", "style" }, new String[] { "The node's network address as 
IP:Port", "border-bottom: 1px dotted; cursor: help;" }, "Address");
                                }
-                               peerTableHeaderRow.addChild("th").addChild("a", 
"href", "?sortBy=version").addChild("#", "Version");
+                               peerTableHeaderRow.addChild("th").addChild("a", 
"href", (!isInversed ? "?sortBy=version&inversed=true" : 
"?sortBy=version")).addChild("#", "Version");
                                if (advancedEnabled) {
-                                       
peerTableHeaderRow.addChild("th").addChild("a", "href", 
"?sortBy=location").addChild("#", "Location");
+                                       
peerTableHeaderRow.addChild("th").addChild("a", "href", (!isInversed ? 
"?sortBy=location&inversed=true" : "?sortBy=location")).addChild("#", 
"Location");
                                        
peerTableHeaderRow.addChild("th").addChild("span", new String[] { "title", 
"style" }, new String[] { "Other node busy? Display: Percentage of time the 
node is overloaded, Current wait time remaining (0=not overloaded)/total/last 
overload reason", "border-bottom: 1px dotted; cursor: help;" }, "Backoff");

                                        
peerTableHeaderRow.addChild("th").addChild("span", new String[] { "title", 
"style" }, new String[] { "Probability of the node rejecting a request due to 
overload or causing a timeout.", "border-bottom: 1px dotted; cursor: help;" }, 
"Overload Probability");
                                }
                                
peerTableHeaderRow.addChild("th").addChild("span", new String[] { "title", 
"style" }, new String[] { "How long since the node was connected or last seen", 
"border-bottom: 1px dotted; cursor: help;" }, "Connected\u00a0/\u00a0Idle");
-                               peerTableHeaderRow.addChild("th").addChild("a", 
"href", "?sortBy=privnote").addChild("span", new String[] { "title", "style" }, 
new String[] { "A private note concerning this peer", "border-bottom: 1px 
dotted; cursor: help;" }, "Private Note");
+                               peerTableHeaderRow.addChild("th").addChild("a", 
"href", (!isInversed ? "?sortBy=privnote&inversed=true" : 
"?sortBy=privnote")).addChild("span", new String[] { "title", "style" }, new 
String[] { "A private note concerning this peer", "border-bottom: 1px dotted; 
cursor: help;" }, "Private Note");

                                if(advancedEnabled) {
                                        peerTableHeaderRow.addChild("th", 
"%\u00a0Time Routable");


Reply via email to