Replaced the remove perm button image and added tooltip (issue #2338)
[pithos-web-client] / src / gr / grnet / pithos / web / client / PermissionsList.java
index d8b7bb4..c7e58d2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
  */
 package gr.grnet.pithos.web.client;
 
-import com.google.gwt.event.logical.shared.ValueChangeEvent;
-import com.google.gwt.event.logical.shared.ValueChangeHandler;
-import gr.grnet.pithos.web.client.FilePropertiesDialog.Images;
-import gr.grnet.pithos.web.client.foldertree.File;
-import gr.grnet.pithos.web.client.rest.GetCommand;
-import gr.grnet.pithos.web.client.rest.resource.PermissionHolder;
-import gr.grnet.pithos.web.client.rest.resource.UserResource;
-import gr.grnet.pithos.web.client.rest.resource.UserSearchResource;
+import gr.grnet.pithos.web.client.FilePermissionsDialog.Images;
 
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.user.client.DeferredCommand;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
 import com.google.gwt.user.client.ui.CheckBox;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import com.google.gwt.user.client.ui.PushButton;
+import com.google.gwt.user.client.ui.RadioButton;
 import com.google.gwt.user.client.ui.VerticalPanel;
 
 
@@ -72,18 +66,20 @@ public class PermissionsList extends Composite {
        
        final String owner;
        
-       private boolean hasChanges = false;
+       protected boolean hasChanges = false;
 
     private boolean readonly = false;
+    
+    Command changePermissionsCallback;
        
-       public PermissionsList(final Images theImages, Map<String, Boolean[]> thePermissions, String theOwner, boolean inheritsPermissions){
+       public PermissionsList(final Images theImages, Map<String, Boolean[]> thePermissions, String theOwner, boolean inheritsPermissions, Command _changePermissionsCallback){
+               changePermissionsCallback = _changePermissionsCallback;
                images = theImages;
                owner = theOwner;
                permissions =  new HashMap<String, Boolean[]>(thePermissions);
-        readonly = inheritsPermissions;
                permTable.setText(0, 0, "Users/Groups");
-               permTable.setText(0, 1, "Read");
-               permTable.setText(0, 2, "Write");
+               permTable.setText(0, 1, "Read Only");
+               permTable.setText(0, 2, "Read/Write");
                permTable.setText(0, 3, "");
                permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
                permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
@@ -112,6 +108,8 @@ public class PermissionsList extends Composite {
                permissions.put(user, new Boolean[] {Boolean.valueOf(read), Boolean.valueOf(write)});
                hasChanges = true;
         updatePermissionTable();
+        if (changePermissionsCallback != null)
+               changePermissionsCallback.execute();
        }
 
        /**
@@ -133,12 +131,12 @@ public class PermissionsList extends Composite {
             Boolean readP = userPerms[0];
             Boolean writeP = userPerms[1];
 
-                       CheckBox read = new CheckBox();
+                       RadioButton read = new RadioButton("permissions" + i);
                        read.setValue(readP != null ? readP : false);
             permTable.setWidget(i, 1, read);
             permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
 
-            CheckBox write = new CheckBox();
+            RadioButton write = new RadioButton("permissions" + i);
             write.setValue(writeP != null ? writeP : false);
             permTable.setWidget(i, 2, write);
             permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
@@ -149,13 +147,21 @@ public class PermissionsList extends Composite {
                     public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
                         Boolean[] ps = permissions.get(user);
                         ps[0] = booleanValueChangeEvent.getValue();
+                        ps[1] = !booleanValueChangeEvent.getValue();
+                        hasChanges = true;
+                        if (changePermissionsCallback != null)
+                               changePermissionsCallback.execute();
                     }
                 });
                 write.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                     @Override
                     public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
                         Boolean[] ps = permissions.get(user);
+                        ps[0] = !booleanValueChangeEvent.getValue();
                         ps[1] = booleanValueChangeEvent.getValue();
+                        hasChanges = true;
+                        if (changePermissionsCallback != null)
+                               changePermissionsCallback.execute();
                     }
                 });
                 PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() {
@@ -164,8 +170,11 @@ public class PermissionsList extends Composite {
                         permissions.remove(user);
                         updatePermissionTable();
                         hasChanges = true;
+                        if (changePermissionsCallback != null)
+                               changePermissionsCallback.execute();
                     }
                 });
+                removeButton.setTitle("Remove");
                 permTable.setWidget(i, 3, removeButton);
                 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
             }