// - 'navigation path' history
// - link selectionfires a leaf event
//
if (command.startsWith(CATENTRY_CHILD)) { // child clicked
int pos = Integer.parseInt(command.substring(CATENTRY_CHILD.length()));
CatalogEntry cur = (CatalogEntry) childCe.get(pos);
// put new as trail on stack
historyStack.add(cur);
updateToolAccessRights(ureq, cur, historyStack.indexOf(cur));
updateContent(ureq.getIdentity(), cur, historyStack.indexOf(cur));
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (command.startsWith(CATCMD_HISTORY)) { // history clicked
int pos = Integer.parseInt(command.substring(CATCMD_HISTORY.length()));
CatalogEntry cur = historyStack.get(pos);
historyStack = historyStack.subList(0, pos + 1);
updateToolAccessRights(ureq, cur, historyStack.indexOf(cur));
updateContent(ureq.getIdentity(), cur, historyStack.indexOf(cur));
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (command.startsWith(CATENTRY_LEAF)) { // link clicked
int pos = Integer.parseInt(command.substring(CATENTRY_LEAF.length()));
CatalogEntry cur = (CatalogEntry) childCe.get(pos);
RepositoryEntry repoEntry = cur.getRepositoryEntry();
if (repoEntry == null) throw new AssertException("a leaf did not have a repositoryentry! catalogEntry = key:" + cur.getKey()
+ ", title " + cur.getName());
// launch entry if launchable, otherwise offer it as download / launch
// it as non-html in browser
String displayName = cur.getName();
RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(repoEntry);
OLATResource ores = repoEntry.getOlatResource();
if (ores == null) throw new AssertException("repoEntry had no olatresource, repoKey = " + repoEntry.getKey());
if (repoEntry.getCanLaunch()) {
// we can create a controller and launch
// it in OLAT, e.g. if it is a
// content-packacking or a course
//was brasato:: DTabs dts = getWindowControl().getDTabs();
DTabs dts = (DTabs)Windows.getWindows(ureq).getWindow(ureq).getAttribute("DTabs");
DTab dt = dts.getDTab(ores);
if (dt == null) {
// does not yet exist -> create and add
dt = dts.createDTab(ores, displayName);
if (dt == null) return;
Controller launchController = ControllerFactory.createLaunchController(ores, null, ureq, dt.getWindowControl(), true);
dt.setController(launchController);
dts.addDTab(dt);
}
dts.activate(ureq, dt, null); // null: start with main entry point of controller
} else if (repoEntry.getCanDownload()) {
// else not launchable in olat, but downloadable -> send the document
// directly to browser but "downloadable" (pdf, word, excel)
MediaResource mr = handler.getAsMediaResource(ores);
RepositoryManager.getInstance().incrementDownloadCounter(repoEntry);
ureq.getDispatchResult().setResultingMediaResource(mr);
return;
} else { // neither launchable nor downloadable -> show details
//REVIEW:pb:replace EntryChangedEvent with a more specific event
fireEvent(ureq, new EntryChangedEvent(repoEntry, EntryChangedEvent.MODIFIED));
return;
}
} else if (command.startsWith(CATCMD_MOVE)) {
String s = command.substring(CATCMD_MOVE.length());
if (s.startsWith(CATENTRY_LEAF)) {
// move a resource in the catalog - moving of catalog leves is triggered by a toolbox action
int pos = Integer.parseInt(s.substring(CATENTRY_LEAF.length()));
linkMarkedToBeEdited = (CatalogEntry) childCe.get(pos);
removeAsListenerAndDispose(catEntryMoveController);
boolean ajax = getWindowControl().getWindowBackOffice().getWindowManager().isAjaxEnabled();
if (ajax) {
// fancy ajax tree
catEntryMoveController= new CatalogAjaxMoveController(ureq, getWindowControl(), linkMarkedToBeEdited);
} else {
// old-school selection tree
catEntryMoveController= new CatalogEntryMoveController(getWindowControl(), ureq, linkMarkedToBeEdited, getTranslator());
}
listenTo(catEntryMoveController);
removeAsListenerAndDispose(cmc);
cmc = new CloseableModalController(getWindowControl(), "close", catEntryMoveController.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
} else if (command.startsWith(CATCMD_REMOVE)) {
String s = command.substring(CATCMD_REMOVE.length());
if (s.startsWith(CATENTRY_LEAF)) {
int pos = Integer.parseInt(s.substring(CATENTRY_LEAF.length()));
linkMarkedToBeDeleted = (CatalogEntry) childCe.get(pos);
// create modal dialog
String[] trnslP = { linkMarkedToBeDeleted.getName() };
dialogDeleteLink = activateYesNoDialog(ureq, null, getTranslator().translate(NLS_DIALOG_MODAL_LEAF_DELETE_TEXT, trnslP), dialogDeleteLink);
return;
}
} else if (command.startsWith(CATCMD_EDIT)) {
String s = command.substring(CATCMD_EDIT.length());
if (s.startsWith(CATENTRY_LEAF)) {
int pos = Integer.parseInt(s.substring(CATENTRY_LEAF.length()));
linkMarkedToBeEdited = (CatalogEntry) childCe.get(pos);
repositoryEditDescriptionController = new RepositoryEditDescriptionController(ureq, getWindowControl(), linkMarkedToBeEdited.getRepositoryEntry(), false);
repositoryEditDescriptionController.addControllerListener(this);
// open form in dialog
removeAsListenerAndDispose(cmc);
cmc = new CloseableModalController(getWindowControl(), "close", repositoryEditDescriptionController.getInitialComponent(), true, translate("tools.edit.catalog.category"));
listenTo(cmc);
cmc.activate();
}
} else if (command.startsWith(CATCMD_DETAIL)) {
String s = command.substring(CATCMD_DETAIL.length());
if (s.startsWith(CATENTRY_LEAF)) {
int pos = Integer.parseInt(s.substring(CATENTRY_LEAF.length()));
CatalogEntry showDetailForLink = (CatalogEntry) childCe.get(pos);
RepositoryEntry repoEnt = showDetailForLink.getRepositoryEntry();
fireEvent(ureq, new EntryChangedEvent(repoEnt, EntryChangedEvent.MODIFIED));
//TODO [ingkr]
//getWindowControl().getDTabs().activateStatic(ureq, RepositorySite.class.getName(), RepositoryMainController.JUMPFROMEXTERN+RepositoryMainController.JUMPFROMCATALOG+repoEnt.getKey().toString());
return;
}
}
}
/*
* login link clicked
*/
else if (source == loginLink){
DispatcherAction.redirectToDefaultDispatcher(ureq.getHttpResp());
}
/*
* add/edit node
*/
else if (source == addEntryForm) {
// remove modal dialog
cmc.deactivate();
if (event == Form.EVNT_VALIDATION_OK) {
CatalogEntry ce = cm.createCatalogEntry();
addEntryForm.fillEntry(ce);
ce.setOwnerGroup(ManagerFactory.getManager().createAndPersistSecurityGroup());
ce.setRepositoryEntry(null);
ce.setParent(currentCatalogEntry);
// optimistic save: might fail in case the parent has been deleted in the meantime
cm.saveCatalogEntry(ce);
} else if (event == Form.EVNT_FORM_CANCELLED) {
// nothing to do
}
CatalogEntry reloaded = cm.loadCatalogEntry(currentCatalogEntry);
currentCatalogEntry = reloaded;// FIXME:pb:
updateContent(ureq.getIdentity(), currentCatalogEntry, currentCatalogEntryLevel);
updateToolAccessRights(ureq, currentCatalogEntry, currentCatalogEntryLevel);
// in any case, remove the lock
if (catModificationLock != null && catModificationLock.isSuccess()) {
CoordinatorManager.getCoordinator().getLocker().releaseLock(catModificationLock);
catModificationLock = null;
}
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (source == editEntryForm) {
// remove modal dialog
cmc.deactivate();
// optimistic save: might fail in case the current entry has been deleted
// in the meantime by someone else
CatalogEntry reloaded = (CatalogEntry) DBFactory.getInstance().loadObject(currentCatalogEntry);
currentCatalogEntry = reloaded;// FIXME:pb
if (event == Form.EVNT_VALIDATION_OK) {
editEntryForm.fillEntry(currentCatalogEntry);
cm.updateCatalogEntry(currentCatalogEntry);
// update the changed name in the history path
historyStack.remove(historyStack.size() - 1);
historyStack.add(currentCatalogEntry);
} else if (event == Form.EVNT_FORM_CANCELLED) {
// nothing to do
}
// in any case, remove the lock
if (catModificationLock != null && catModificationLock.isSuccess()) {
CoordinatorManager.getCoordinator().getLocker().releaseLock(catModificationLock);
catModificationLock = null;
}
updateContent(ureq.getIdentity(), currentCatalogEntry, currentCatalogEntryLevel);
}
/*
* admin submitted a new structure
*/
else if (source == addStructureForm) {
// remove modal dialog first
cmc.deactivate();
if (event == Form.EVNT_VALIDATION_OK) {
importStructure();
}
CatalogEntry newRoot = (CatalogEntry) cm.getRootCatalogEntries().get(0);
historyStack = new ArrayList<CatalogEntry>();
historyStack.add(newRoot);
updateContent(ureq.getIdentity(), newRoot, 0);
updateToolAccessRights(ureq, currentCatalogEntry, currentCatalogEntryLevel);
fireEvent(ureq, Event.CHANGED_EVENT);