commit 9a849658ec2c2f94820bbcd241826672986befa5
Author: Christos KK Loverdos <loverdos@gmail.com>
Date:   Wed Jun 19 18:47:44 2013 +0300

    WIP Investigating #4035
    
    The selection is broken and this can be the root of the problem(s).
    
    Refs #4035

diff --git a/src/gr/grnet/pithos/web/client/FileList.java b/src/gr/grnet/pithos/web/client/FileList.java
index 2a9068d..a3075e3 100644
--- a/src/gr/grnet/pithos/web/client/FileList.java
+++ b/src/gr/grnet/pithos/web/client/FileList.java
@@ -258,9 +258,8 @@ public class FileList extends Composite {
 	        public boolean handlesSelection() {
 	            return false;
 	        }
-		})
-        {
-	         @Override
+		}) {
+            @Override
 	         public ImageResource getValue(File entity) {
 	             return getFileIcon(entity);
 	         }
@@ -280,11 +279,17 @@ public class FileList extends Composite {
 			public SafeHtml getValue(File object) {
 				SafeHtmlBuilder sb = new SafeHtmlBuilder();
 				sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
-				if (object.getContentType() != null && (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg"))) {
-        			sb.appendHtmlConstant("&nbsp;")
-                      .append(Templates.INSTANCE.viewLink(Pithos.getFileViewURL(object), object.getName()));
-				}
-				
+
+                final String contentType = object.getContentType();
+                if(contentType != null)
+                if(contentType.endsWith("png") ||
+                   contentType.endsWith("gif") ||
+                   contentType.endsWith("jpeg")) {
+
+                    sb.appendHtmlConstant("&nbsp;").
+                       append(Templates.INSTANCE.viewLink(Pithos.getFileViewURL(object), object.getName()));
+                }
+
 				return sb.toSafeHtml();
 			}
 			
@@ -361,12 +366,18 @@ public class FileList extends Composite {
 	                final int x = event.getNativeEvent().getClientX();
 	                final int y = event.getNativeEvent().getClientY();
 	                final Folder selectedFolder = app.getSelection();
+                    Pithos.LOG("FileList::ContextMenuHandler::onContextMenu(), selectedFolder=", selectedFolder);
 	                app.scheduleFolderHeadCommand(selectedFolder, new Command() {
 						
 						@Override
 						public void execute() {
 							final List<File> selectedFiles = getSelectedFiles();
-							Iterator<File> iter = selectedFiles.iterator();
+                            Pithos.LOG("FileList::ContextMenuHandler::onContextMenu()::scheduledHEAD(), selectedFolder=", selectedFolder);
+                            Pithos.LOG("FileList::ContextMenuHandler::onContextMenu()::scheduledHEAD(), ", selectedFiles.size(), " selectedFiles");
+                            for(File selectedFile : selectedFiles) {
+                                Pithos.LOG("FileList::ContextMenuHandler::onContextMenu()::scheduledHEAD(), selectedFile: ", selectedFile);
+                            }
+                            Iterator<File> iter = selectedFiles.iterator();
 							iterateFilesHeadCommand(iter, new Command() {
 								
 								@Override
@@ -388,6 +399,7 @@ public class FileList extends Composite {
 			
 			@Override
 			public void onSelectionChange(SelectionChangeEvent event) {
+                Pithos.LOG("FileList::selectionModel::onSelectionChange(", event, ")");
 				app.showRelevantToolbarButtons();
 			}
 		});
diff --git a/src/gr/grnet/pithos/web/client/Pithos.java b/src/gr/grnet/pithos/web/client/Pithos.java
index 99fe458..50bc85e 100644
--- a/src/gr/grnet/pithos/web/client/Pithos.java
+++ b/src/gr/grnet/pithos/web/client/Pithos.java
@@ -1447,7 +1447,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
     public void setError(Throwable t) {
         error = t;
-        LOG(t);
+        LOGError(t);
     }
 
     public void showRelevantToolbarButtons() {
@@ -1531,7 +1531,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                         displayError("System error heading folder: " + t.getMessage());
                     }
 
-                    LOG("Error heading folder", t);
+                    LOG("Error HEADing folder ", folder);
                     setError(t);
                 }
 
@@ -1545,7 +1545,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         }
     }
 
-    public void scheduleFileHeadCommand(File f, final Command callback) {
+    public void scheduleFileHeadCommand(final File f, final Command callback) {
         HeadRequest<File> headFile = new HeadRequest<File>(File.class, getStorageAPIURL(), f.getOwnerID(), f.getUri(), f) {
 
             @Override
@@ -1557,7 +1557,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
             @Override
             public void onError(Throwable t) {
-                LOG("Error heading file", t);
+                LOG("Error HEADing file", f);
                 setError(t);
                 if(t instanceof RestException) {
                     displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
diff --git a/src/gr/grnet/pithos/web/client/PithosSelectionEventManager.java b/src/gr/grnet/pithos/web/client/PithosSelectionEventManager.java
index 8c2da14..42b7220 100644
--- a/src/gr/grnet/pithos/web/client/PithosSelectionEventManager.java
+++ b/src/gr/grnet/pithos/web/client/PithosSelectionEventManager.java
@@ -36,17 +36,13 @@ package gr.grnet.pithos.web.client;
 
 
 
-import java.util.ArrayList;
-import java.util.List;
-
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.InputElement;
 import com.google.gwt.dom.client.NativeEvent;
-import com.google.gwt.view.client.CellPreviewEvent;
-import com.google.gwt.view.client.HasData;
-import com.google.gwt.view.client.MultiSelectionModel;
-import com.google.gwt.view.client.Range;
-import com.google.gwt.view.client.SelectionModel;
+import com.google.gwt.view.client.*;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * An implementation of {@link com.google.gwt.view.client.CellPreviewEvent.Handler} that adds selection
@@ -379,11 +375,13 @@ public void onCellPreview(CellPreviewEvent<T> event) {
    */
   protected void handleMultiSelectionEvent(CellPreviewEvent<T> event,
       SelectAction action, MultiSelectionModel<? super T> selectionModel) {
+    Pithos.LOG("handleMultiSelectionEvent(action=", action, ")");
     NativeEvent nativeEvent = event.getNativeEvent();
     String type = nativeEvent.getType();
     boolean rightclick = "mousedown".equals(type) && nativeEvent.getButton()==NativeEvent.BUTTON_RIGHT;
     SelectAction action1 = action;
     if(rightclick){
+        Pithos.LOG("handleMultiSelectionEvent(action=", action, "), rightclick");
     	boolean shift = nativeEvent.getShiftKey();
         boolean ctrlOrMeta = nativeEvent.getCtrlKey() || nativeEvent.getMetaKey();
         boolean clearOthers = (translator == null) ? !ctrlOrMeta
@@ -411,13 +409,16 @@ public void onCellPreview(CellPreviewEvent<T> event) {
       if (action == null || action == SelectAction.DEFAULT) {
         action1 = ctrlOrMeta ? SelectAction.TOGGLE : SelectAction.SELECT;
       }
+        Pithos.LOG("handleMultiSelectionEvent(action=", action, "), click, shift=", shift, ", ctrlOrMeta=", ctrlOrMeta, ", clearOthers=", clearOthers, ", action1=", action1);
       doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(),
           event.getValue(), action1, shift, clearOthers);
       if(ctrlOrMeta){
+          Pithos.LOG("handleMultiSelectionEvent(action=", action, "), click, ctrlOrMeta=true => cancelling event=", event);
     	  event.setCanceled(true);
       }
     } else if ("keyup".equals(type)) {
       int keyCode = nativeEvent.getKeyCode();
+        Pithos.LOG("handleMultiSelectionEvent(action=", action, "), keyup, keyCode=", keyCode, ", isSpaceBar=", keyCode == 32);
       if (keyCode == 32) {
         /*
          * Update selection when the space bar is pressed. The spacebar always
diff --git a/src/gr/grnet/pithos/web/client/foldertree/File.java b/src/gr/grnet/pithos/web/client/foldertree/File.java
index c1f120b..2b1348f 100644
--- a/src/gr/grnet/pithos/web/client/foldertree/File.java
+++ b/src/gr/grnet/pithos/web/client/foldertree/File.java
@@ -35,20 +35,21 @@
 
 package gr.grnet.pithos.web.client.foldertree;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
 import com.google.gwt.http.client.Header;
 import com.google.gwt.http.client.Response;
 import com.google.gwt.http.client.URL;
 import com.google.gwt.i18n.client.DateTimeFormat;
-import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
+import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONValue;
+import gr.grnet.pithos.web.client.Pithos;
 import gr.grnet.pithos.web.client.Resource;
 
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
 public class File extends Resource {
     private String name;
 
@@ -143,6 +144,7 @@ public class File extends Resource {
     }
 
     public void populate(Folder _parent, JSONObject o, String _owner, String _container) {
+        Pithos.LOG("File::populate(parent=", parent, ", o=", o, ", owner=", _owner, ", container=", _container, ")");
         this.parent = _parent;
         path = unmarshallString(o, "name");
         if (parent != null && parent.getPrefix().length() > 0)
@@ -223,6 +225,7 @@ public class File extends Resource {
     }
 
     private void populate(String _owner, Response response) {
+        Pithos.LOG("File::populate(owner=", _owner, ", response=", response, ")");
         this.ownerID = _owner;
         published = false;
         publicUri = null;
@@ -283,4 +286,9 @@ public class File extends Resource {
 	public void setName(String _name) {
 		name = _name;
 	}
+
+    @Override
+    public String toString() {
+        return "File(container="+container+", name="+name+", parent="+(parent == null ? parent : parent.getName())+", published="+published+")";
+    }
 }
diff --git a/src/gr/grnet/pithos/web/client/foldertree/Folder.java b/src/gr/grnet/pithos/web/client/foldertree/Folder.java
index c5d9166..206a165 100644
--- a/src/gr/grnet/pithos/web/client/foldertree/Folder.java
+++ b/src/gr/grnet/pithos/web/client/foldertree/Folder.java
@@ -35,14 +35,6 @@
 
 package gr.grnet.pithos.web.client.foldertree;
 
-import gr.grnet.pithos.web.client.Const;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.http.client.Response;
 import com.google.gwt.http.client.URL;
@@ -52,8 +44,11 @@ import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
 import com.google.gwt.json.client.JSONValue;
+import gr.grnet.pithos.web.client.Const;
 import gr.grnet.pithos.web.client.Resource;
 
+import java.util.*;
+
 public class Folder extends Resource {
     /*
      * The name of the folder. If the folder is a container this is its name. If it is a virtual folder this is the
@@ -325,6 +320,6 @@ public class Folder extends Resource {
 
     @Override
     public String toString() {
-        return "Folder(container="+container+", name="+name+", prefix="+prefix+")";
+        return "Folder(container="+container+", name="+name+", parent="+(parent == null ? parent : parent.getName())+", prefix="+prefix+")";
     }
 }
