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);
}
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 };
}
}
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));
}
}
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;
}
}
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);
}
}
Aggregations