}//GEN-LAST:event_addOKButtonActionPerformed
private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
int curRow = permsTable.getSelectedRow();
Principal p = perms.getPrincipal(curRow);
SortedSet<Permission> ps = perms.getPerms(curRow);
Set<ActionDTO> aps = new HashSet<ActionDTO>(perms.getAllPerms());
edit.removeAllChildren();
edit.setUserObject(new PrincipalHolder(p));
// build the tree of actions
Map<Action, DefaultMutableTreeNode> actions =
new HashMap<Action, DefaultMutableTreeNode>();
while (!aps.isEmpty()) {
for (Iterator<ActionDTO> i = aps.iterator(); i.hasNext();) {
ActionDTO actionDTO = i.next();
Action action = actionDTO.getAction();
DefaultMutableTreeNode node = null;
if (action.getParent() == null) {
// top level action
node = new DefaultMutableTreeNode(new ActionHolder(action));
edit.add(node);
} else if (actions.containsKey(action.getParent())) {
// we found the parent of this action -- add it to
// the tree
node = new DefaultMutableTreeNode(new ActionHolder(action));
actions.get(action.getParent()).add(node);
}
if (node != null) {
i.remove();
actions.put(action, node);
// find the associated permission, if any
Permission search = new Permission(p, actionDTO, null);
SortedSet<Permission> tail = ps.tailSet(search);
if (!tail.isEmpty() && tail.first().equals(search)) {
ActionHolder ah = (ActionHolder) node.getUserObject();
ah.setAccess(tail.first().getAccess());
}
}
}
}
// reset the model on the tree
editPermsTree.setModel(new DefaultTreeModel(edit));
editPermPermCombo.setEnabled(false);
editPermPermCombo.setSelectedIndex(0);
editPermDescription.setText(BUNDLE.getString("Choose_Permission"));
// expand the tree
int row = 0;
while (row < editPermsTree.getRowCount()) {
editPermsTree.expandRow(row);
row++;
}
editPermsTree.setRootVisible(false);
String text = BUNDLE.getString("Edit_Permission_For");
text = MessageFormat.format(text, p.getId());
editPermsPrincipalLabel.setText(text);
editPermsDialog.pack();
editPermsDialog.setVisible(true);
editPermsTree.invalidate();