Search in sources :

Example 1 with UserGroup

use of net.sourceforge.processdash.team.group.UserGroup in project processdash by dtuma.

the class UserGroupEditor method addGroupToListAndSelect.

private void addGroupToListAndSelect(UserGroup add) {
    for (int i = 0; i < groups.size(); i++) {
        UserGroup g = (UserGroup) groups.get(i);
        if (add.compareTo(g) < 0) {
            groups.add(i, add);
            groupList.setSelectedValue(add, true);
            return;
        }
    }
    groups.addElement(add);
    groupList.setSelectedValue(add, true);
}
Also used : UserGroup(net.sourceforge.processdash.team.group.UserGroup)

Example 2 with UserGroup

use of net.sourceforge.processdash.team.group.UserGroup in project processdash by dtuma.

the class UserGroupEditor method promptForName.

private Object[] promptForName(String resKey, String resArg, String defaultName, boolean isCustom, boolean showCustom) {
    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[] typePanel = null;
    JRadioButton sharedOption, customOption = null;
    if (showCustom) {
        String typePrompt = resources.getString("Type_Prompt");
        Border indent = BorderFactory.createEmptyBorder(0, 20, 0, 0);
        sharedOption = new JRadioButton(resources.getString("Type_Shared"));
        sharedOption.setBorder(indent);
        customOption = new JRadioButton(resources.getString("Type_Custom"));
        customOption.setBorder(indent);
        if (readOnlyCode != null) {
            sharedOption.setEnabled(false);
            sharedOption.setToolTipText("<html><div style='width:250px'>" + resources.getHTML(resKey + "_Error." + readOnlyCode) + "</div></html>");
            new ToolTipTimingCustomizer().install(sharedOption);
            isCustom = true;
        }
        ButtonGroup bg = new ButtonGroup();
        bg.add(sharedOption);
        bg.add(customOption);
        (isCustom ? customOption : sharedOption).setSelected(true);
        typePanel = new Object[] { " ", typePrompt, sharedOption, customOption };
    }
    Object message = new Object[] { prompt, nameField, typePanel, 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;
        }
        // when renaming, if they did not alter the value, abort.
        if (defaultName != null && name.equals(defaultName))
            return null;
        // make a note of whether this is a custom group.
        boolean custom = showCustom ? customOption.isSelected() : isCustom;
        // if they entered a duplicate name, display an error
        for (int i = groups.size(); i-- > 0; ) {
            UserGroup g = (UserGroup) groups.get(i);
            if (g.isCustom() == custom && g.getDisplayName().equals(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 values the user selected.
        return new Object[] { name, custom };
    }
}
Also used : JRadioButton(javax.swing.JRadioButton) ToolTipTimingCustomizer(net.sourceforge.processdash.ui.lib.ToolTipTimingCustomizer) ButtonGroup(javax.swing.ButtonGroup) JTextField(javax.swing.JTextField) Border(javax.swing.border.Border) UserGroup(net.sourceforge.processdash.team.group.UserGroup)

Example 3 with UserGroup

use of net.sourceforge.processdash.team.group.UserGroup in project processdash by dtuma.

the class GroupFilterMenu method setSelectedItem.

public void setSelectedItem(UserFilter selection) {
    if (selection instanceof UserGroup) {
        UserGroup g = (UserGroup) selection;
        setIcon(groupIcon);
        setText(g.toString());
    } else if (selection instanceof UserGroupMember) {
        UserGroupMember m = (UserGroupMember) selection;
        setIcon(personIcon);
        setText(m.toString());
    }
    boolean isChange = !NullSafeObjectUtils.EQ(selectedItem, selection);
    this.selectedItem = selection;
    if (isChange) {
        for (ChangeListener l : listeners.getListeners(ChangeListener.class)) l.stateChanged(new ChangeEvent(this));
    }
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) UserGroupMember(net.sourceforge.processdash.team.group.UserGroupMember) UserGroup(net.sourceforge.processdash.team.group.UserGroup)

Example 4 with UserGroup

use of net.sourceforge.processdash.team.group.UserGroup in project processdash by dtuma.

the class GroupPermissionEditor method editPermission.

@Override
public Map<String, String> editPermission(GroupPermission p, Component parent, boolean isAdd) {
    // retrieve the list of shared groups known to this dashboard. Custom
    // groups are not included, because they can't form the basis of a
    // meaningful cross-user permission grant.
    Vector<UserGroup> groups = new Vector<UserGroup>();
    UserGroupManager mgr = UserGroupManager.getInstance();
    for (UserGroup g : mgr.getGroups().values()) {
        if (!g.isCustom())
            groups.add(g);
    }
    // sort the list, and insert "Everyone" at the beginning.
    Collections.sort(groups);
    groups.add(0, UserGroup.EVERYONE);
    // retrieve the group named in the given permission. If it was a
    // "missing" permission, it will come back with the custom flag set.
    // In that case, add it to the list we'll display in the combo box.
    UserGroup currentGroup = p.getGroup();
    if (currentGroup.isCustom())
        groups.add(currentGroup);
    // create a combo box for selecting a group
    JComboBox<UserGroup> cb = new JComboBox<UserGroup>(groups);
    cb.setSelectedItem(currentGroup);
    // display a user interface for selecting a group
    String title = UserGroupEditor.resources.getString(isAdd ? "Add_Permission" : "Edit_Permission");
    String prompt = p.getSpec().getResources().getString("Edit_Prompt");
    Object[] message = { prompt, BoxUtils.hbox(20, cb) };
    int userChoice = JOptionPane.showConfirmDialog(parent, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    // otherwise return null to indicate that they cancelled the operation.
    if (userChoice == JOptionPane.OK_OPTION) {
        UserGroup selected = (UserGroup) cb.getSelectedItem();
        return Collections.singletonMap(GROUP_PARAM, selected.getId());
    } else {
        return null;
    }
}
Also used : UserGroupManager(net.sourceforge.processdash.team.group.UserGroupManager) JComboBox(javax.swing.JComboBox) Vector(java.util.Vector) UserGroup(net.sourceforge.processdash.team.group.UserGroup)

Example 5 with UserGroup

use of net.sourceforge.processdash.team.group.UserGroup in project processdash by dtuma.

the class UserGroupEditor method saveMembershipChanges.

private void saveMembershipChanges() {
    if (currentlyEditing != null && memberList.isDirty()) {
        UserGroup updated = new UserGroup(currentlyEditing.getDisplayName(), //
        currentlyEditing.getId(), currentlyEditing.isCustom(), memberList.getSelectedMembers());
        groupsToSave.remove(currentlyEditing);
        groupsToSave.add(updated);
        memberList.clearDirty();
        int pos = groups.indexOf(currentlyEditing);
        currentlyEditing = updated;
        groups.set(pos, updated);
    }
}
Also used : UserGroup(net.sourceforge.processdash.team.group.UserGroup)

Aggregations

UserGroup (net.sourceforge.processdash.team.group.UserGroup)7 Border (javax.swing.border.Border)2 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 Vector (java.util.Vector)1 ButtonGroup (javax.swing.ButtonGroup)1 DefaultListModel (javax.swing.DefaultListModel)1 JButton (javax.swing.JButton)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 JRadioButton (javax.swing.JRadioButton)1 JScrollPane (javax.swing.JScrollPane)1