dialog.setContent(addPermissionPanel);
dialog.setCallback(new IDialogCallback() {
public void okPressed() {
for (int i = 0; i < addPrincipalListBox.getItemCount(); i++) {
if (addPrincipalListBox.isItemSelected(i)) {
Permission newPerm = new Permission();
newPerm.setPermissibleObject(permissibleObject);
SecurityPrincipal principal = fetchedUsers.get(addPrincipalListBox.getItemText(i));
if (principal == null) {
principal = fetchedGroups.get(addPrincipalListBox.getItemText(i));
}
newPerm.setSecurityPrincipal(principal);
permissions.add(newPerm);
dirty = true;
populateUI();
if (principalListBox.getItemCount() > 0) {
principalListBox.setSelectedIndex(principalListBox.getItemCount() - 1);
}
populatePermissionPanel();
}
}
}
public void cancelPressed() {
}
});
dialog.center();
}
});
Button removeButton = new Button("Remove...");
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String principalName = principalListBox.getValue(principalListBox.getSelectedIndex());
Permission permission = null;
for (Permission mypermission : permissions) {
if (showUserPerms && mypermission.getSecurityPrincipal() instanceof User) {
User user = (User) mypermission.getSecurityPrincipal();
if (principalName.equalsIgnoreCase(user.getUsername())) {
permission = mypermission;
break;
}
} else if (showGroupPerms && mypermission.getSecurityPrincipal() instanceof UserGroup) {
UserGroup group = (UserGroup) mypermission.getSecurityPrincipal();
if (principalName.equalsIgnoreCase(group.getName())) {
permission = mypermission;
break;
}
}
}
permissions.remove(permission);
dirty = true;
populateUI();
if (principalListBox.getItemCount() > 0) {
principalListBox.setSelectedIndex(principalListBox.getItemCount() - 1);
}
populatePermissionPanel();
}
});
Button newButton = new Button("New...");
newButton.setCommand(new CreateGroupCommand(AuthenticationHandler.getInstance().getUser(), new IGenericCallback<UserGroup>() {
public void invoke(UserGroup group) {
dirty = true;
Permission newPerm = new Permission();
newPerm.setPermissibleObject(permissibleObject);
newPerm.setSecurityPrincipal(group);
permissions.add(newPerm);
fetchedGroups.put(group.getName(), group);
populateUI();
if (principalListBox.getItemCount() > 0) {
principalListBox.setSelectedIndex(principalListBox.getItemCount() - 1);