Merge branch 'packaging' into debian
[pithos-web-client] / src / gr / grnet / pithos / web / client / PermissionsAddDialog.java
index 96f3a80..55aaec6 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
@@ -34,8 +34,6 @@
  */
 package gr.grnet.pithos.web.client;
 
-import com.google.gwt.user.client.ui.TextBox;
-
 import gr.grnet.pithos.web.client.grouptree.Group;
 
 import java.util.List;
@@ -51,8 +49,9 @@ import com.google.gwt.user.client.ui.CheckBox;
 import com.google.gwt.user.client.ui.DialogBox;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
-import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.RadioButton;
+import com.google.gwt.user.client.ui.TextBox;
 import com.google.gwt.user.client.ui.VerticalPanel;
 
 public class PermissionsAddDialog extends DialogBox {
@@ -61,9 +60,9 @@ public class PermissionsAddDialog extends DialogBox {
 
        private ListBox groupBox = new ListBox();
 
-       private CheckBox read = new CheckBox();
+       private RadioButton read = new RadioButton("permissions");
 
-       private CheckBox write = new CheckBox();
+       private RadioButton write = new RadioButton("permissions");
 
        private PermissionsList permList;
 
@@ -76,7 +75,7 @@ public class PermissionsAddDialog extends DialogBox {
                userAdd = _userAdd;
                permList = _permList;
 
-               Anchor close = new Anchor();
+               Anchor close = new Anchor("close");
                close.addStyleName("close");
                close.addClickHandler(new ClickHandler() {
                        
@@ -96,8 +95,8 @@ public class PermissionsAddDialog extends DialogBox {
 
         final FlexTable permTable = new FlexTable();
         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.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
         permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
         permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
@@ -110,7 +109,8 @@ public class PermissionsAddDialog extends DialogBox {
                 groupBox.addItem(group.getName(), group.getName());
             permTable.setWidget(1, 0, groupBox);
         }
-
+                
+        read.setValue(true);
         permTable.setWidget(1, 1, read);
         permTable.setWidget(1, 2, write);
 
@@ -121,7 +121,7 @@ public class PermissionsAddDialog extends DialogBox {
 
         final Button ok = new Button("OK", new ClickHandler() {
             @Override
-            public void onClick(@SuppressWarnings("unused") ClickEvent event) {
+            public void onClick(ClickEvent event) {
                 addPermission();
                 hide();
             }
@@ -140,13 +140,17 @@ public class PermissionsAddDialog extends DialogBox {
         String selected = null;
                if (userAdd) {
                        selected = userBox.getText();
-               } else {
+               } else if (groupBox.getSelectedIndex() > -1) {
                        String groupName = groupBox.getValue(groupBox.getSelectedIndex());
-            selected = app.getUsername() + ":" + groupName;
+                       selected = app.getUsername() + ":" + groupName;
                }
         if (permList.getPermissions().get(selected) != null) {
             return;
         }
+        if (selected == null || selected.length() == 0 || selected.equals(app.getUsername() + ":")) {
+               app.displayError("You have to select o username or group");
+               return;
+        }
                boolean readValue = read.getValue();
                boolean writeValue = write.getValue();