public void event(UserRequest ureq, Component source, Event event) {
if (source == selectionTree) {
TreeEvent te = (TreeEvent) event;
if (te.getCommand().equals(TreeEvent.COMMAND_TREENODE_CLICKED)) {
GenericTreeNode node = (GenericTreeNode) selectionTree.getSelectedNode();
CatalogManager cm = CatalogManager.getInstance();
Long newParentId = Long.parseLong(node.getIdent());
CatalogEntry newParent = cm.loadCatalogEntry(newParentId);
// check first if this repo entry is already attached to this new parent
List<CatalogEntry> existingChildren = cm.getChildrenOf(newParent);
for (CatalogEntry existingChild : existingChildren) {
RepositoryEntry existingRepoEntry = existingChild.getRepositoryEntry();
if (existingRepoEntry != null && existingRepoEntry.equalsByPersistableKey(toBeAddedEntry)) {
showError("catalog.tree.add.already.exists", toBeAddedEntry.getDisplayname());
return;
}
}
CatalogEntry newEntry = cm.createCatalogEntry();
newEntry.setRepositoryEntry(toBeAddedEntry);
newEntry.setName(toBeAddedEntry.getDisplayname());
newEntry.setDescription(toBeAddedEntry.getDescription());
newEntry.setType(CatalogEntry.TYPE_LEAF);
newEntry.setOwnerGroup(ManagerFactory.getManager().createAndPersistSecurityGroup());
// save entry
cm.addCatalogEntry(newParent, newEntry);
fireEvent(ureq, Event.DONE_EVENT);
} else if (te.getCommand().equals(TreeEvent.COMMAND_CANCELLED)) {
fireEvent(ureq, Event.CANCELLED_EVENT);
}