コード例 #1
0
  /** Update the permission map and then save it. */
  protected void beginApply() {
    setEnabled(false);
    for (Iterator itr = groups2Permissions.entrySet().iterator(); itr.hasNext(); ) {
      Map.Entry e = (Map.Entry) itr.next();

      WGroup g = (WGroup) e.getKey();
      Collection permGrants = (Collection) e.getValue();

      int row = rows.indexOf(g.getName());

      for (Iterator pgItr = permGrants.iterator(); pgItr.hasNext(); ) {
        WPermissionGrant pg = (WPermissionGrant) pgItr.next();

        int col = getPermissionColumn(pg.getPermission().getName());

        setGrant(row, col, pg);
      }
    }

    AbstractCallback callback =
        new AbstractCallback(errorPanel) {

          public void onCallFailure(Throwable caught) {
            super.onFailure(caught);
            setEnabled(true);
          }

          public void onCallSuccess(Object arg0) {
            errorPanel.setMessage(administrationConstants.permissionsSaved());
            setEnabled(true);
          }
        };
    applyPermissions(groups2Permissions, callback);
  }
コード例 #2
0
  protected void receiveGroups(Map groups2Permissions) {
    this.groups2Permissions = groups2Permissions;
    mainPanel.clear();

    ContentPanel cp = new FullContentPanel();
    cp.setHeading(administrationConstants.usersGroup());

    // add inline help string and widget
    //        cp.setTopComponent(new
    // InlineHelpPanel(galaxy.getRepositoryConstants().repo_Security_Tip(), 15));
    mainPanel.add(cp);

    table = createRowTable();
    cp.add(table);

    int col = 1;
    table.setWidget(0, 0, new Image("images/clearpixel.gif"));
    for (Iterator itr = permissions.iterator(); itr.hasNext(); ) {
      WPermission p = (WPermission) itr.next();
      table.setWidget(0, col, createTitleText(p.getDescription()));

      col++;
    }

    rows = new ArrayList<String>();
    for (Iterator itr = groups2Permissions.keySet().iterator(); itr.hasNext(); ) {
      rows.add(((WGroup) itr.next()).getName());
    }
    Collections.sort(rows);

    for (Iterator itr = groups2Permissions.entrySet().iterator(); itr.hasNext(); ) {
      Map.Entry e = (Map.Entry) itr.next();

      final WGroup role = (WGroup) e.getKey();
      final String groupName = role.getName();
      final Hyperlink hl = new Hyperlink(groupName, "groups/" + role.getId());

      int row = rows.indexOf(groupName) + 1;

      // certain groups should not be removed or edited via the GUI
      boolean isUberGroup = groupName.equals("Administrators") || groupName.equals("Anonymous");
      if (isUberGroup) {
        table.setWidget(row, 0, new Label(groupName));
      } else {
        table.setWidget(row, 0, hl);
      }

      Collection grants = (Collection) e.getValue();
      for (Iterator gItr = grants.iterator(); gItr.hasNext(); ) {
        WPermissionGrant pg = (WPermissionGrant) gItr.next();
        int permCol = getPermissionColumn(pg.getPermission().getName());
        if (permCol != -1) {
          Widget w = createGrantWidget(pg, isUberGroup);
          table.setWidget(row, permCol, w);
        }
      }
      row++;
    }

    // table.getFlexCellFormatter().setColSpan(rows.size() + 1, 0, col);

    SelectionListener listener =
        new SelectionListener<ComponentEvent>() {
          public void componentSelected(ComponentEvent ce) {
            Button btn = (Button) ce.getComponent();

            if (btn == applyButton) {
              beginApply();
            }
            if (btn == resetButton) {
              // Go back to the previously saved state.
              errorPanel.clearErrorMessage();
              doShowPage();
            }
          }
        };

    applyButton = new Button(administrationConstants.save(), listener);
    resetButton = new Button(administrationConstants.cancel(), listener);

    ButtonBar bb = new ButtonBar();
    bb.add(applyButton);
    bb.add(resetButton);
    bb.add(createHistoryButton(administrationConstants.newAdmin(), "groups/new"));

    // table.setWidget(rows.size() + 1, 0, bb);
    cp.add(bb);

    cp.layout(true);
  }