From: Natasa Kapravelou Date: Thu, 20 Jan 2011 16:11:09 +0000 (+0200) Subject: Full names of the user(s) in the Permission list of a file are available during shown... X-Git-Tag: pithos/v0.7.8~323^2~14^2~22^2~90^2~2 X-Git-Url: https://code.grnet.gr/git/pithos/commitdiff_plain/50b82d9d81979966c9e3803362a8c60ccb9566d8 Full names of the user(s) in the Permission list of a file are available during showning the Properties dialog box. --- diff --git a/src/gr/ebs/gss/client/PermissionsList.java b/src/gr/ebs/gss/client/PermissionsList.java index 8488b4a..db7b319 100644 --- a/src/gr/ebs/gss/client/PermissionsList.java +++ b/src/gr/ebs/gss/client/PermissionsList.java @@ -19,13 +19,19 @@ package gr.ebs.gss.client; import gr.ebs.gss.client.FilePropertiesDialog.Images; +import gr.ebs.gss.client.rest.GetCommand; import gr.ebs.gss.client.rest.resource.PermissionHolder; +import gr.ebs.gss.client.rest.resource.UserResource; +import gr.ebs.gss.client.rest.resource.UserSearchResource; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; +import com.google.gwt.core.client.GWT; 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.user.client.ui.AbstractImagePrototype; import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.Composite; @@ -42,16 +48,25 @@ import com.google.gwt.user.client.ui.VerticalPanel; public class PermissionsList extends Composite { int selectedRow = -1; - int permissionCount=-1; + + int permissionCount = -1; + Set permissions = null; + final Images images; + final VerticalPanel permPanel = new VerticalPanel(); + final FlexTable permTable = new FlexTable(); + final String owner; + PermissionHolder toRemove = null; + private boolean hasChanges = false; + private boolean hasAddition = false; - + public PermissionsList(final Images theImages, Set thePermissions, String anOwner){ images = theImages; owner = anOwner; @@ -78,13 +93,91 @@ public class PermissionsList extends Composite { public void updateTable(){ + copySetAndContinue(permissions); + } + + public void updatePermissionsAccordingToInput(){ int i=1; + for(PermissionHolder dto : permissions){ + /*if(dto.getId() == null) + hasChanges =true;*/ + CheckBox r = (CheckBox) permTable.getWidget(i, 1); + CheckBox w = (CheckBox) permTable.getWidget(i, 2); + CheckBox m = (CheckBox) permTable.getWidget(i, 3); + if(dto.isRead() != r.getValue() || dto.isWrite() != w.getValue() || dto.isModifyACL() != m.getValue()) + hasChanges = true; + dto.setRead(r.getValue()); + dto.setWrite(w.getValue()); + dto.setModifyACL(m.getValue()); + i++; + } + } + + /** + * Retrieve the permissions. + * + * @return the permissions + */ + public Set getPermissions() { + return permissions; + } + + public void addPermission(PermissionHolder permission){ + permissions.add(permission); + hasAddition = true; + } + /** + * Copies the input Set to a new Set + * @param input + */ + private void copySetAndContinue(Set input){ + Set copiedInput = new HashSet(); + for(PermissionHolder dto : input) { + copiedInput.add(dto); + } + handleFullNames(copiedInput); + } + + /** + * Examines whether or not the user's full name exists in the + * userFullNameMap in the GSS.java for every element of the input list. + * If the user's full name does not exist in the map then a request is being made + * for the specific username. + * + * @param filesInput + */ + private void handleFullNames(Set aPermissions){ + if(aPermissions.isEmpty()){ + showPermissionTable(); + return; + } + + final PermissionHolder dto = aPermissions.iterator().next(); + + if(GSS.get().findUserFullName(dto.getUser()) != null){ + if(aPermissions.size() >= 1){ + aPermissions.remove(dto); + handleFullNames(aPermissions); + }else{ + showPermissionTable(); + } + }else{ + findFullNameAndUpdate(aPermissions); + } + } + + /** + * Shows the table + * + * @param aPermissions + */ + private void showPermissionTable(){ + int i = 1; if(toRemove != null){ permissions.remove(toRemove); toRemove = null; } for(final PermissionHolder dto : permissions){ - PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() { @Override public void onClick(ClickEvent event) { @@ -93,16 +186,18 @@ public class PermissionsList extends Composite { hasChanges = true; } }); - - if(dto.getUser() !=null) - if(dto.getUser()!=null && dto.getUser().equals(owner)){ + + if(dto.getUser() != null){ + if(dto.getUser() != null && dto.getUser().equals(owner)){ permTable.setHTML(i, 0, "" + AbstractImagePrototype.create(images.permUser()).getHTML() + " Owner"); removeButton.setVisible(false); + }else{ + permTable.setHTML(i, 0, "" + AbstractImagePrototype.create(images.permUser()).getHTML() + " "+ GSS.get().findUserFullName(dto.getUser()) + ""); } - else - permTable.setHTML(i, 0, "" + AbstractImagePrototype.create(images.permUser()).getHTML() + " "+ GSS.get().getUserFullName(dto.getUser()) +""); - else if(dto.getGroup() != null) - permTable.setHTML(i, 0, "" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " "+dto.getGroup()+""); + }else if(dto.getGroup() != null){ + permTable.setHTML(i, 0, "" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " "+ dto.getGroup() + ""); + } + CheckBox read = new CheckBox(); read.setValue(dto.isRead()); CheckBox write = new CheckBox(); @@ -114,6 +209,7 @@ public class PermissionsList extends Composite { write.setEnabled(false); modify.setEnabled(false); } + permTable.setWidget(i, 1, read); permTable.setWidget(i, 2, write); permTable.setWidget(i, 3, modify); @@ -122,45 +218,57 @@ public class PermissionsList extends Composite { permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER); permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER); permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER); - i++; - } - for(; i getPermissions() { - return permissions; - } - public void addPermission(PermissionHolder permission){ - permissions.add(permission); - hasAddition = true; - } + private void findFullNameAndUpdate(final Set aPermissions){ + final PermissionHolder dto = aPermissions.iterator().next(); + String path = GSS.get().getApiPath() + "users/" + dto.getUser(); + GetCommand gg = new GetCommand(UserSearchResource.class, path, false,null) { + @Override + public void onComplete() { + final UserSearchResource result = getResult(); + for (UserResource user : result.getUsers()){ + String username = user.getUsername(); + String userFullName = user.getName(); + GSS.get().putUserToMap(username, userFullName); + if(aPermissions.size() >= 1){ + aPermissions.remove(dto); + if(aPermissions.isEmpty()){ + showPermissionTable(); + return; + } + handleFullNames(aPermissions); + } + } + } + @Override + public void onError(Throwable t) { + GSS.get().displayError("Unable to fetch user's full name from the given username " + dto.getUser()); + if(aPermissions.size() >= 1){ + aPermissions.remove(dto); + if(aPermissions.isEmpty()){ + showPermissionTable(); + return; + } + handleFullNames(aPermissions); + } + } + }; + DeferredCommand.addCommand(gg); + + } }