Search in sources :

Example 1 with Role

use of net.sourceforge.processdash.tool.perm.Role in project processdash by dtuma.

the class RolesEditor method createUI.

private Component createUI() {
    // create the roles button panel
    JPanel roleButtons = new JPanel(new GridLayout(2, 2, 5, 5));
    roleButtons.add(new JButton(new AddRoleAction()));
    roleButtons.add(new JButton(new CopyRoleAction()));
    roleButtons.add(new JButton(new RenameRoleAction()));
    roleButtons.add(new JButton(new DeleteRoleAction()));
    // create the permissions button panel
    JPanel permButtons = new JPanel(new GridLayout(1, 4, 5, 5));
    permButtons.add(new JButton(new AddPermissionAction()));
    permButtons.add(new JButton(new EditPermissionAction()));
    permButtons.add(new JButton(new DeletePermissionAction()));
    permButtons.add(new JButton(new RevertPermissionsAction()));
    // read the known roles, and add them to a list
    roles = new DefaultListModel();
    for (Role r : PermissionsManager.getInstance().getAllRoles()) roles.addElement(r);
    rolesList = new JList(roles);
    rolesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    rolesList.addListSelectionListener(new RoleSelectionHandler());
    JScrollPane rsp = new JScrollPane(rolesList);
    int prefHeight = Math.max(rolesList.getCellBounds(0, 0).height * 15 + 6, 200);
    rsp.setPreferredSize(new Dimension(200, prefHeight));
    // create an object for editing the permissions in the selected role
    permissionList = new PermissionList();
    permissionList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    permissionList.getSelectionModel().addListSelectionListener(new PermissionSelectionHandler());
    JScrollPane psp = new JScrollPane(permissionList);
    psp.setPreferredSize(new Dimension(450, prefHeight));
    // create titles to display on the dialog
    JLabel rolesTitle = new JLabel(resources.getString("Roles_Header"));
    JLabel permissionsTitle = new JLabel(resources.getString("Permissions_Header"));
    Font f = rolesTitle.getFont();
    f = f.deriveFont(f.getSize2D() * 1.5f);
    rolesTitle.setFont(f);
    permissionsTitle.setFont(f);
    Border b = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black);
    rolesTitle.setBorder(b);
    permissionsTitle.setBorder(b);
    // arrange the components onto a panel
    GridBagLayout layout = new GridBagLayout();
    userInterface = new JPanel(layout);
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = c.gridy = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    layout.addLayoutComponent(rolesTitle, c);
    userInterface.add(rolesTitle);
    c.gridx = 2;
    Component comp = BoxUtils.hbox(new JOptionPaneTweaker.MakeResizable(), new JOptionPaneTweaker.DisableKeys());
    layout.addLayoutComponent(comp, c);
    userInterface.add(comp);
    c.gridx = 1;
    c.insets = new Insets(0, 10, 0, 0);
    layout.addLayoutComponent(permissionsTitle, c);
    userInterface.add(permissionsTitle);
    c.gridx = 0;
    c.gridy = 1;
    c.gridheight = 2;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(10, 20, 0, 0);
    if (editable) {
        layout.addLayoutComponent(roleButtons, c);
        userInterface.add(roleButtons);
    }
    c.gridy = 3;
    c.gridheight = 1;
    c.weightx = c.weighty = 1.0;
    layout.addLayoutComponent(rsp, c);
    userInterface.add(rsp);
    c.gridx = c.gridy = 1;
    c.weightx = c.weighty = 0;
    c.insets = new Insets(10, 30, 0, 0);
    if (editable) {
        layout.addLayoutComponent(permButtons, c);
        userInterface.add(permButtons);
    }
    c.gridy = 2;
    c.gridheight = 2;
    c.weightx = 3.0;
    c.weighty = 1.0;
    layout.addLayoutComponent(psp, c);
    userInterface.add(psp);
    // load the preferred size of the window
    try {
        String[] size = Settings.getVal(SIZE_PREF).split(",");
        Dimension d = new Dimension(Integer.parseInt(size[0]), Integer.parseInt(size[1]));
        userInterface.setPreferredSize(d);
    } catch (Exception e) {
    }
    return userInterface;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) Font(java.awt.Font) GridLayout(java.awt.GridLayout) Component(java.awt.Component) JScrollPane(javax.swing.JScrollPane) JOptionPaneTweaker(net.sourceforge.processdash.ui.lib.JOptionPaneTweaker) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Role(net.sourceforge.processdash.tool.perm.Role) Border(javax.swing.border.Border) JList(javax.swing.JList)

Example 2 with Role

use of net.sourceforge.processdash.tool.perm.Role in project processdash by dtuma.

the class RolesEditor method promptForName.

private String promptForName(String resKey, String resArg, String defaultName) {
    String title = resources.getString(resKey + "_Title");
    String prompt;
    if (resArg == null)
        prompt = resources.getString(resKey + "_Prompt");
    else
        prompt = resources.format(resKey + "_Prompt_FMT", resArg);
    JTextField nameField = new JTextField(defaultName);
    Object message = new Object[] { prompt, nameField, new JOptionPaneTweaker.GrabFocus(nameField) };
    PROMPT: while (true) {
        // prompt the user for the new name
        nameField.selectAll();
        int userChoice = JOptionPane.showConfirmDialog(userInterface, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (userChoice != JOptionPane.OK_OPTION)
            return null;
        // if they did not enter a name, display an error
        String name = nameField.getText().trim();
        if (!StringUtils.hasValue(name)) {
            JOptionPane.showMessageDialog(userInterface, resources.getString("Name_Missing"), resources.getString("Name_Error_Title"), JOptionPane.ERROR_MESSAGE);
            continue PROMPT;
        }
        // if the name included a comma, display an error
        if (name.indexOf(',') != -1) {
            JOptionPane.showMessageDialog(userInterface, resources.getString("No_Comma"), resources.getString("Name_Error_Title"), JOptionPane.ERROR_MESSAGE);
            continue PROMPT;
        }
        // when renaming, if they did not alter the value, abort.
        if (defaultName != null && name.equalsIgnoreCase(defaultName))
            return (name.equals(defaultName) ? null : name);
        // if they entered a duplicate name, display an error
        for (int i = roles.size(); i-- > 0; ) {
            Role r = roles.get(i);
            if (r.getName().equalsIgnoreCase(name)) {
                JOptionPane.showMessageDialog(userInterface, resources.format("Name_Duplicate_FMT", name), resources.getString("Name_Error_Title"), JOptionPane.ERROR_MESSAGE);
                continue PROMPT;
            }
        }
        // all seems OK. Return the name the user selected.
        return name;
    }
}
Also used : Role(net.sourceforge.processdash.tool.perm.Role) JTextField(javax.swing.JTextField)

Example 3 with Role

use of net.sourceforge.processdash.tool.perm.Role in project processdash by dtuma.

the class RolesReport method writeContents.

@Override
protected void writeContents() throws IOException {
    String title = resources.getHTML("RolesReport.Title");
    out.println("<html><head>");
    out.println("<title>" + title + "</title>");
    out.println("<style>");
    out.println("    h2 { margin-bottom: 0px }");
    out.println("    ul { margin-top: 0px }");
    out.println("</style>");
    out.println("</head><body>");
    out.println("<h1>" + title + "</h1>");
    out.println(resources.getHTML("RolesReport.Header"));
    for (Role r : PermissionsManager.getInstance().getAllRoles()) {
        // print the name of the role as a heading
        out.print("<h2>");
        out.print(HTMLUtils.escapeEntities(r.getName()));
        out.println("</h2>");
        // print a list of the permissions in the role
        out.println("<ul>");
        boolean sawItem = false;
        for (Permission p : r.getPermissions()) {
            if (!p.isInactive()) {
                printPermissionItem(p);
                sawItem = true;
            }
        }
        // if no permissions were found, print a "no permission" bullet
        if (!sawItem)
            out.print("<li><i>" + resources.getHTML("No_Permission") + "</i></li>");
        out.println("</ul>");
    }
    out.println("</body></html>");
}
Also used : Role(net.sourceforge.processdash.tool.perm.Role) Permission(net.sourceforge.processdash.tool.perm.Permission)

Example 4 with Role

use of net.sourceforge.processdash.tool.perm.Role in project processdash by dtuma.

the class WbsPermissionSettingsWriter method writeTeamSettings.

@Override
public void writeTeamSettings(String projectID, XmlSerializer xml) throws IOException {
    // start a <roles> tag
    xml.startTag(null, ROLES_TAG);
    // gather the list of users known to this team dashboard
    List<User> allUsers = getAllUsers();
    Set<String> usersToWrite = new HashSet();
    for (User u : allUsers) usersToWrite.add(u.getUsername());
    // write data for each role
    for (Role r : getAllRoles()) writeRoleSettings(xml, r, allUsers, usersToWrite);
    // write an empty role for users with no WBS permissions
    if (!usersToWrite.isEmpty())
        writeEmptyRole(xml, usersToWrite);
    // end the </roles> tag
    xml.endTag(null, ROLES_TAG);
}
Also used : Role(net.sourceforge.processdash.tool.perm.Role) User(net.sourceforge.processdash.tool.perm.User) HashSet(java.util.HashSet)

Example 5 with Role

use of net.sourceforge.processdash.tool.perm.Role in project processdash by dtuma.

the class EditableUser method setRoleNames.

/**
     * Change the set of roles that are assigned to this user.
     * 
     * @param roleNames
     *            a comma-separated list of role names. These will be resolved
     *            (in a case-insensitive manner) against the list of roles known
     *            to this dataset.
     */
public void setRoleNames(String roleNames) {
    if (roleNames == null || roleNames.trim().length() == 0) {
        setRoleIDs(Collections.EMPTY_LIST);
    } else {
        List<String> roleIDs = new ArrayList<String>();
        for (String oneName : roleNames.split(",")) {
            Role r = PermissionsManager.getInstance().getRoleByName(oneName.trim());
            if (r != null && !roleIDs.contains(r.getId()))
                roleIDs.add(r.getId());
        }
        setRoleIDs(roleIDs);
    }
}
Also used : Role(net.sourceforge.processdash.tool.perm.Role) ArrayList(java.util.ArrayList)

Aggregations

Role (net.sourceforge.processdash.tool.perm.Role)7 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 GridLayout (java.awt.GridLayout)1 Insets (java.awt.Insets)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DefaultListModel (javax.swing.DefaultListModel)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTextField (javax.swing.JTextField)1 Border (javax.swing.border.Border)1 Permission (net.sourceforge.processdash.tool.perm.Permission)1 User (net.sourceforge.processdash.tool.perm.User)1