use of org.olat.core.commons.controllers.linkchooser.URLChoosenEvent in project OpenOLAT by OpenOLAT.
the class FileCopyController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source instanceof FileLinkChooserController) {
if (event == Event.DONE_EVENT || event == Event.CANCELLED_EVENT) {
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else if (event instanceof URLChoosenEvent) {
URLChoosenEvent choosenEvent = (URLChoosenEvent) event;
String url = choosenEvent.getURL();
if (url.indexOf("://") < 0) {
VFSContainer cContainer = folderComponent.getExternContainerForCopy();
VFSItem item = cContainer.resolve(url);
if (item instanceof VFSLeaf) {
sourceLeaf = (VFSLeaf) item;
String filename = sourceLeaf.getName();
VFSContainer tContainer = folderComponent.getCurrentContainer();
newFile = tContainer.createChildLeaf(filename);
if (newFile == null) {
existingVFSItem = (VFSLeaf) tContainer.resolve(filename);
fileAlreadyExists(ureq);
} else {
finishUpload(ureq);
}
} else {
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
} else {
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
}
} else if (source == overwriteDialog) {
if (event instanceof ButtonClickedEvent) {
ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
if (buttonClickedEvent.getPosition() == 0) {
// ok
if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
// new version
String relPath = null;
if (existingVFSItem instanceof OlatRootFileImpl) {
relPath = ((OlatRootFileImpl) existingVFSItem).getRelPath();
}
int maxNumOfRevisions = FolderConfig.versionsAllowed(relPath);
if (maxNumOfRevisions == 0) {
// someone play with the configuration
// Overwrite...
String fileName = existingVFSItem.getName();
existingVFSItem.delete();
newFile = folderComponent.getCurrentContainer().createChildLeaf(fileName);
// ... and notify listeners.
finishUpload(ureq);
} else {
removeAsListenerAndDispose(commentVersionCtr);
boolean locked = vfsLockManager.isLocked(existingVFSItem);
commentVersionCtr = new VersionCommentController(ureq, getWindowControl(), locked, true);
listenTo(commentVersionCtr);
removeAsListenerAndDispose(commentVersionDialogBox);
commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
listenTo(commentVersionDialogBox);
commentVersionDialogBox.activate();
}
} else {
// if the file is locked, ask for unlocking it
if (vfsLockManager.isLocked(existingVFSItem)) {
removeAsListenerAndDispose(unlockCtr);
unlockCtr = new VersionCommentController(ureq, getWindowControl(), true, false);
listenTo(unlockCtr);
removeAsListenerAndDispose(unlockDialogBox);
unlockDialogBox = new CloseableModalController(getWindowControl(), translate("ok"), unlockCtr.getInitialComponent());
listenTo(unlockDialogBox);
unlockDialogBox.activate();
} else {
// Overwrite...
String fileName = existingVFSItem.getName();
existingVFSItem.delete();
newFile = folderComponent.getCurrentContainer().createChildLeaf(fileName);
// ... and notify listeners.
finishUpload(ureq);
}
}
} else if (buttonClickedEvent.getPosition() == 1) {
// not ok
// make newFile with the proposition of filename
newFile = folderComponent.getCurrentContainer().createChildLeaf(renamedFilename);
// ... and notify listeners.
finishUpload(ureq);
} else if (buttonClickedEvent.getPosition() == 2) {
// cancel
// cancel -> do nothing
} else {
throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
}
}
} else if (source == lockedFileDialog) {
if (event instanceof ButtonClickedEvent) {
ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
switch(buttonClickedEvent.getPosition()) {
case 0:
{
// ... and notify listeners.
newFile = existingVFSItem;
finishUpload(ureq);
break;
}
case 1:
{
// cancel
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
break;
}
default:
throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
}
}
} else if (source == commentVersionCtr) {
String comment = commentVersionCtr.getComment();
Roles roles = ureq.getUserSession().getRoles();
boolean locked = vfsLockManager.isLocked(existingVFSItem);
if (locked && !commentVersionCtr.keepLocked()) {
vfsLockManager.unlock(existingVFSItem, getIdentity(), roles);
}
commentVersionDialogBox.deactivate();
if (revisionListDialogBox != null) {
revisionListDialogBox.deactivate();
}
// ok, new version of the file
Versionable existingVersionableItem = (Versionable) existingVFSItem;
boolean ok = existingVersionableItem.getVersions().addVersion(ureq.getIdentity(), comment, sourceLeaf.getInputStream());
if (ok) {
newFile = existingVFSItem;
}
finishSuccessfullUpload(existingVFSItem.getName(), ureq);
} else if (source == unlockCtr) {
// Overwrite...
if (!unlockCtr.keepLocked()) {
vfsLockManager.unlock(existingVFSItem, getIdentity(), ureq.getUserSession().getRoles());
}
unlockDialogBox.deactivate();
newFile = existingVFSItem;
// ... and notify listeners.
finishSuccessfullUpload(existingVFSItem.getName(), ureq);
} else if (source == revisionListCtr) {
if (FolderCommandStatus.STATUS_CANCELED == revisionListCtr.getStatus()) {
revisionListDialogBox.deactivate();
// don't want to delete revisions
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else {
if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
revisionListDialogBox.deactivate();
Versionable versionable = (Versionable) existingVFSItem;
Versions versions = versionable.getVersions();
int maxNumOfRevisions = FolderConfig.versionsAllowed(null);
if (maxNumOfRevisions < 0 || maxNumOfRevisions > versions.getRevisions().size()) {
removeAsListenerAndDispose(commentVersionCtr);
boolean locked = vfsLockManager.isLocked(existingVFSItem);
commentVersionCtr = new VersionCommentController(ureq, getWindowControl(), locked, true);
listenTo(commentVersionCtr);
removeAsListenerAndDispose(commentVersionDialogBox);
commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
listenTo(commentVersionDialogBox);
commentVersionDialogBox.activate();
} else {
removeAsListenerAndDispose(revisionListCtr);
revisionListCtr = new RevisionListController(ureq, getWindowControl(), versionable, false);
listenTo(revisionListCtr);
removeAsListenerAndDispose(revisionListDialogBox);
revisionListDialogBox = new CloseableModalController(getWindowControl(), translate("delete"), revisionListCtr.getInitialComponent());
listenTo(revisionListDialogBox);
revisionListDialogBox.activate();
}
}
}
}
}
use of org.olat.core.commons.controllers.linkchooser.URLChoosenEvent in project openolat by klemens.
the class CalendarEntryDetailsController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == deleteCtr) {
if (event instanceof CalendarGUIDeleteEvent) {
doDelete((CalendarGUIDeleteEvent) event);
cmc.deactivate();
cleanUp();
fireEvent(ureq, Event.DONE_EVENT);
} else {
cmc.deactivate();
cleanUp();
}
} else if (source == activeLinkProvider) {
if (kalendarEvent.getCalendar() != null) {
fireEvent(ureq, Event.DONE_EVENT);
}
} else if (source == eventForm) {
if (event == Event.DONE_EVENT) {
doSave(ureq);
} else if ("delete".equals(event.getCommand())) {
doConfirmDelete(ureq);
} else if (event == Event.CANCELLED_EVENT) {
eventForm.setEntry(kalendarEvent);
// user canceled, finish workflow
fireEvent(ureq, Event.DONE_EVENT);
}
} else if (source == updateCtr) {
if (event instanceof CalendarGUIUpdateEvent) {
doUpdate((CalendarGUIUpdateEvent) event);
cmc.deactivate();
cleanUp();
fireEvent(ureq, Event.DONE_EVENT);
} else {
cmc.deactivate();
cleanUp();
}
} else if (source == customMediaChooserCtr) {
boolean doneSuccessfully = true;
if (event instanceof URLChoosenEvent) {
URLChoosenEvent urlEvent = (URLChoosenEvent) event;
String url = urlEvent.getURL();
List<KalendarEventLink> links = kalendarEvent.getKalendarEventLinks();
String provider = customMediaChooserCtr.getClass().getSimpleName();
String id = url;
String displayName = StringHelper.containsNonWhitespace(urlEvent.getDisplayName()) ? urlEvent.getDisplayName() : url;
String uri = url.contains("://") ? url : (Settings.getServerContextPathURI() + url);
String iconCssClass = urlEvent.getIconCssClass();
if (!StringHelper.containsNonWhitespace(iconCssClass)) {
iconCssClass = CSSHelper.createFiletypeIconCssClassFor(url);
}
links.add(new KalendarEventLink(provider, id, displayName, uri, iconCssClass));
Kalendar cal = kalendarEvent.getCalendar();
doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
}
if (doneSuccessfully) {
fireEvent(ureq, event);
} else {
showError("cal.error.save");
fireEvent(ureq, Event.FAILED_EVENT);
}
} else if (source == externalLinksController || source == mediaLinksController) {
// save externals links
Kalendar cal = kalendarEvent.getCalendar();
if (kalendarEvent.getCalendar() != null) {
boolean doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
if (doneSuccessfully) {
fireEvent(ureq, Event.DONE_EVENT);
} else {
showError("cal.error.save");
fireEvent(ureq, Event.FAILED_EVENT);
}
}
} else if (cmc == source) {
cleanUp();
}
}
use of org.olat.core.commons.controllers.linkchooser.URLChoosenEvent in project OpenOLAT by OpenOLAT.
the class CalendarEntryDetailsController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == deleteCtr) {
if (event instanceof CalendarGUIDeleteEvent) {
doDelete((CalendarGUIDeleteEvent) event);
cmc.deactivate();
cleanUp();
fireEvent(ureq, Event.DONE_EVENT);
} else {
cmc.deactivate();
cleanUp();
}
} else if (source == activeLinkProvider) {
if (kalendarEvent.getCalendar() != null) {
fireEvent(ureq, Event.DONE_EVENT);
}
} else if (source == eventForm) {
if (event == Event.DONE_EVENT) {
doSave(ureq);
} else if ("delete".equals(event.getCommand())) {
doConfirmDelete(ureq);
} else if (event == Event.CANCELLED_EVENT) {
eventForm.setEntry(kalendarEvent);
// user canceled, finish workflow
fireEvent(ureq, Event.DONE_EVENT);
}
} else if (source == updateCtr) {
if (event instanceof CalendarGUIUpdateEvent) {
doUpdate((CalendarGUIUpdateEvent) event);
cmc.deactivate();
cleanUp();
fireEvent(ureq, Event.DONE_EVENT);
} else {
cmc.deactivate();
cleanUp();
}
} else if (source == customMediaChooserCtr) {
boolean doneSuccessfully = true;
if (event instanceof URLChoosenEvent) {
URLChoosenEvent urlEvent = (URLChoosenEvent) event;
String url = urlEvent.getURL();
List<KalendarEventLink> links = kalendarEvent.getKalendarEventLinks();
String provider = customMediaChooserCtr.getClass().getSimpleName();
String id = url;
String displayName = StringHelper.containsNonWhitespace(urlEvent.getDisplayName()) ? urlEvent.getDisplayName() : url;
String uri = url.contains("://") ? url : (Settings.getServerContextPathURI() + url);
String iconCssClass = urlEvent.getIconCssClass();
if (!StringHelper.containsNonWhitespace(iconCssClass)) {
iconCssClass = CSSHelper.createFiletypeIconCssClassFor(url);
}
links.add(new KalendarEventLink(provider, id, displayName, uri, iconCssClass));
Kalendar cal = kalendarEvent.getCalendar();
doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
}
if (doneSuccessfully) {
fireEvent(ureq, event);
} else {
showError("cal.error.save");
fireEvent(ureq, Event.FAILED_EVENT);
}
} else if (source == externalLinksController || source == mediaLinksController) {
// save externals links
Kalendar cal = kalendarEvent.getCalendar();
if (kalendarEvent.getCalendar() != null) {
boolean doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
if (doneSuccessfully) {
fireEvent(ureq, Event.DONE_EVENT);
} else {
showError("cal.error.save");
fireEvent(ureq, Event.FAILED_EVENT);
}
}
} else if (cmc == source) {
cleanUp();
}
}
use of org.olat.core.commons.controllers.linkchooser.URLChoosenEvent in project openolat by klemens.
the class FileCopyController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source instanceof FileLinkChooserController) {
if (event == Event.DONE_EVENT || event == Event.CANCELLED_EVENT) {
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else if (event instanceof URLChoosenEvent) {
URLChoosenEvent choosenEvent = (URLChoosenEvent) event;
String url = choosenEvent.getURL();
if (url.indexOf("://") < 0) {
VFSContainer cContainer = folderComponent.getExternContainerForCopy();
VFSItem item = cContainer.resolve(url);
if (item instanceof VFSLeaf) {
sourceLeaf = (VFSLeaf) item;
String filename = sourceLeaf.getName();
VFSContainer tContainer = folderComponent.getCurrentContainer();
newFile = tContainer.createChildLeaf(filename);
if (newFile == null) {
existingVFSItem = (VFSLeaf) tContainer.resolve(filename);
fileAlreadyExists(ureq);
} else {
finishUpload(ureq);
}
} else {
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
} else {
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
}
} else if (source == overwriteDialog) {
if (event instanceof ButtonClickedEvent) {
ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
if (buttonClickedEvent.getPosition() == 0) {
// ok
if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
// new version
String relPath = null;
if (existingVFSItem instanceof OlatRootFileImpl) {
relPath = ((OlatRootFileImpl) existingVFSItem).getRelPath();
}
int maxNumOfRevisions = FolderConfig.versionsAllowed(relPath);
if (maxNumOfRevisions == 0) {
// someone play with the configuration
// Overwrite...
String fileName = existingVFSItem.getName();
existingVFSItem.delete();
newFile = folderComponent.getCurrentContainer().createChildLeaf(fileName);
// ... and notify listeners.
finishUpload(ureq);
} else {
removeAsListenerAndDispose(commentVersionCtr);
boolean locked = vfsLockManager.isLocked(existingVFSItem);
commentVersionCtr = new VersionCommentController(ureq, getWindowControl(), locked, true);
listenTo(commentVersionCtr);
removeAsListenerAndDispose(commentVersionDialogBox);
commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
listenTo(commentVersionDialogBox);
commentVersionDialogBox.activate();
}
} else {
// if the file is locked, ask for unlocking it
if (vfsLockManager.isLocked(existingVFSItem)) {
removeAsListenerAndDispose(unlockCtr);
unlockCtr = new VersionCommentController(ureq, getWindowControl(), true, false);
listenTo(unlockCtr);
removeAsListenerAndDispose(unlockDialogBox);
unlockDialogBox = new CloseableModalController(getWindowControl(), translate("ok"), unlockCtr.getInitialComponent());
listenTo(unlockDialogBox);
unlockDialogBox.activate();
} else {
// Overwrite...
String fileName = existingVFSItem.getName();
existingVFSItem.delete();
newFile = folderComponent.getCurrentContainer().createChildLeaf(fileName);
// ... and notify listeners.
finishUpload(ureq);
}
}
} else if (buttonClickedEvent.getPosition() == 1) {
// not ok
// make newFile with the proposition of filename
newFile = folderComponent.getCurrentContainer().createChildLeaf(renamedFilename);
// ... and notify listeners.
finishUpload(ureq);
} else if (buttonClickedEvent.getPosition() == 2) {
// cancel
// cancel -> do nothing
} else {
throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
}
}
} else if (source == lockedFileDialog) {
if (event instanceof ButtonClickedEvent) {
ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
switch(buttonClickedEvent.getPosition()) {
case 0:
{
// ... and notify listeners.
newFile = existingVFSItem;
finishUpload(ureq);
break;
}
case 1:
{
// cancel
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
break;
}
default:
throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
}
}
} else if (source == commentVersionCtr) {
String comment = commentVersionCtr.getComment();
Roles roles = ureq.getUserSession().getRoles();
boolean locked = vfsLockManager.isLocked(existingVFSItem);
if (locked && !commentVersionCtr.keepLocked()) {
vfsLockManager.unlock(existingVFSItem, getIdentity(), roles);
}
commentVersionDialogBox.deactivate();
if (revisionListDialogBox != null) {
revisionListDialogBox.deactivate();
}
// ok, new version of the file
Versionable existingVersionableItem = (Versionable) existingVFSItem;
boolean ok = existingVersionableItem.getVersions().addVersion(ureq.getIdentity(), comment, sourceLeaf.getInputStream());
if (ok) {
newFile = existingVFSItem;
}
finishSuccessfullUpload(existingVFSItem.getName(), ureq);
} else if (source == unlockCtr) {
// Overwrite...
if (!unlockCtr.keepLocked()) {
vfsLockManager.unlock(existingVFSItem, getIdentity(), ureq.getUserSession().getRoles());
}
unlockDialogBox.deactivate();
newFile = existingVFSItem;
// ... and notify listeners.
finishSuccessfullUpload(existingVFSItem.getName(), ureq);
} else if (source == revisionListCtr) {
if (FolderCommandStatus.STATUS_CANCELED == revisionListCtr.getStatus()) {
revisionListDialogBox.deactivate();
// don't want to delete revisions
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else {
if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
revisionListDialogBox.deactivate();
Versionable versionable = (Versionable) existingVFSItem;
Versions versions = versionable.getVersions();
int maxNumOfRevisions = FolderConfig.versionsAllowed(null);
if (maxNumOfRevisions < 0 || maxNumOfRevisions > versions.getRevisions().size()) {
removeAsListenerAndDispose(commentVersionCtr);
boolean locked = vfsLockManager.isLocked(existingVFSItem);
commentVersionCtr = new VersionCommentController(ureq, getWindowControl(), locked, true);
listenTo(commentVersionCtr);
removeAsListenerAndDispose(commentVersionDialogBox);
commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
listenTo(commentVersionDialogBox);
commentVersionDialogBox.activate();
} else {
removeAsListenerAndDispose(revisionListCtr);
revisionListCtr = new RevisionListController(ureq, getWindowControl(), versionable, false);
listenTo(revisionListCtr);
removeAsListenerAndDispose(revisionListDialogBox);
revisionListDialogBox = new CloseableModalController(getWindowControl(), translate("delete"), revisionListCtr.getInitialComponent());
listenTo(revisionListDialogBox);
revisionListDialogBox.activate();
}
}
}
}
}
Aggregations