private void userSelectionChanged() {
    List<ProxyPentahoUser> selectedUsers = usersList.getSelectedObjects();
    if (selectedUsers.size() == 1) {
      userDetailsPanel.setUser(selectedUsers.get(0));
      List<ProxyPentahoRole> roleList =
          Arrays.asList(UserAndRoleMgmtService.instance().getRoles(selectedUsers.get(0)));
      assignedRolesList.setObjects(roleList);
    } else {
      userDetailsPanel.setUser(null);
      List<ProxyPentahoRole> emptyRoleList = Collections.emptyList();
      assignedRolesList.setObjects(emptyRoleList);
    }
    userDetailsPanel.setEnabled(selectedUsers.size() == 1);
    updateUserBtn.setEnabled(selectedUsers.size() == 1);

    if (selectedUsers.size() > 0) {
      deleteUserBtn.setEnabled(true);
    } else {
      deleteUserBtn.setEnabled(false);
    }

    if (selectedUsers.size() == 1) {
      addRoleAssignmentBtn.setEnabled(true);
    } else {
      addRoleAssignmentBtn.setEnabled(false);
    }

    userDetailsPanel.getUserNameTextBox().setEnabled(false);
    assignedRoleSelectionChanged();
  }
 private void assignedRoleSelectionChanged() {
   if (assignedRolesList.getSelectedObjects().size() > 0) {
     deleteRoleAssignmentBtn.setEnabled(true);
   } else {
     deleteRoleAssignmentBtn.setEnabled(false);
   }
 }
  private void unassignSelectedRoles() {
    List<ProxyPentahoUser> selectedUsers = usersList.getSelectedObjects();
    if (selectedUsers.size() == 1) {
      ArrayList<ProxyPentahoRole> assignedRoles = new ArrayList<ProxyPentahoRole>();
      assignedRoles.addAll(
          Arrays.asList(UserAndRoleMgmtService.instance().getRoles(selectedUsers.get(0))));
      final List<ProxyPentahoRole> rolesToUnassign = assignedRolesList.getSelectedObjects();
      assignedRoles.removeAll(rolesToUnassign);

      AsyncCallback<Object> callback =
          new AsyncCallback<Object>() {
            public void onSuccess(Object result) {
              assignedRolesList.removeObjects(rolesToUnassign);
            }

            public void onFailure(Throwable caught) {
              MessageDialogBox messageDialog =
                  new MessageDialogBox(
                      ExceptionParser.getErrorHeader(caught.getMessage()),
                      ExceptionParser.getErrorMessage(
                          caught.getMessage(), Messages.getString("errorUnassigningRoles")),
                      false,
                      false,
                      true); //$NON-NLS-1$
              messageDialog.center();
            }
          };
      UserAndRoleMgmtService.instance()
          .setRoles(
              selectedUsers.get(0),
              (ProxyPentahoRole[]) assignedRoles.toArray(new ProxyPentahoRole[0]),
              callback);
    }
  }
 public void onPopupClosed(PopupPanel sender, boolean autoClosed) {
   if (roleAssignmentsDialog.getRoleAssignmentsModified()) {
     List<ProxyPentahoRole> roleList =
         Arrays.asList(
             UserAndRoleMgmtService.instance().getRoles(roleAssignmentsDialog.getUser()));
     assignedRolesList.setObjects(roleList);
     assignedRoleSelectionChanged();
   }
 }
  public VerticalPanel buildAssignedRolesPanel() {
    DockPanel headerDockPanel = new DockPanel();

    VerticalPanel fieldsetPanel = new VerticalPanel();

    Label label = new Label(Messages.getString("assignedRoles")); // $NON-NLS-1$
    Label spacer = new Label(""); // $NON-NLS-1$

    headerDockPanel.add(label, DockPanel.WEST);
    headerDockPanel.setCellWidth(label, "100%"); // $NON-NLS-1$
    headerDockPanel.add(deleteRoleAssignmentBtn, DockPanel.EAST);
    VerticalPanel spacer2 = new VerticalPanel();
    spacer2.setWidth("2"); // $NON-NLS-1$
    headerDockPanel.add(spacer2, DockPanel.EAST);
    headerDockPanel.add(addRoleAssignmentBtn, DockPanel.EAST);

    headerDockPanel.add(spacer, DockPanel.WEST);
    headerDockPanel.setCellWidth(spacer, "100%"); // $NON-NLS-1$

    DockPanel assignedRolesPanel = new DockPanel();
    assignedRolesPanel.add(headerDockPanel, DockPanel.NORTH);
    assignedRolesPanel.add(assignedRolesList, DockPanel.CENTER);
    assignedRolesPanel.setCellHeight(assignedRolesList, "100%"); // $NON-NLS-1$
    assignedRolesPanel.setCellWidth(assignedRolesList, "100%"); // $NON-NLS-1$
    assignedRolesList.setHeight("100%"); // $NON-NLS-1$
    assignedRolesList.setWidth("100%"); // $NON-NLS-1$

    assignedRolesList.addChangeListener(this);
    deleteRoleAssignmentBtn.addClickListener(this);
    addRoleAssignmentBtn.addClickListener(this);

    fieldsetPanel.add(assignedRolesPanel);
    assignedRolesPanel.setWidth("100%"); // $NON-NLS-1$
    assignedRolesPanel.setHeight("100%"); // $NON-NLS-1$
    return fieldsetPanel;
  }
 public void onClick(Widget sender) {
   if (sender == updateUserBtn) {
     updateUserDetails(sender);
   } else if (sender == deleteUserBtn) {
     if (usersList.getSelectedObjects().size() > 0) {
       confirmDeleteUsersDialog.center();
     }
   } else if (sender == addUserBtn) {
     addNewUser();
   } else if (sender == deleteRoleAssignmentBtn) {
     if (assignedRolesList.getSelectedObjects().size() > 0) {
       confirmRemoveRoleAssignmentDialog.center();
     }
   } else if (sender == addRoleAssignmentBtn) {
     List<ProxyPentahoUser> selectedUsers = usersList.getSelectedObjects();
     if (selectedUsers.size() == 1) {
       modifyRoleAssignments(selectedUsers.get(0));
     }
   }
 }