@Override
public void event(UserRequest ureq, Controller source, Event event) {
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.rename(fileName);
// ... and notify listeners.
finishUpload(ureq);
} else {
commentVersionCtr = new VersionCommentController(ureq,getWindowControl(), askForLock(existingVFSItem, ureq), true);
listenTo(commentVersionCtr);
commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
commentVersionDialogBox.activate();
}
} else {
//if the file is locked, ask for unlocking it
if(existingVFSItem instanceof MetaTagged && ((MetaTagged)existingVFSItem).getMetaInfo().isLocked()) {
cleanUpOverwriteDialog();
unlockCtr = new VersionCommentController(ureq,getWindowControl(), true, false);
listenTo(unlockCtr);
unlockDialogBox = new CloseableModalController(getWindowControl(), translate("ok"), unlockCtr.getInitialComponent());
unlockDialogBox.activate();
} else {
// Overwrite...
String fileName = existingVFSItem.getName();
existingVFSItem.delete();
newFile.rename(fileName);
// ... and notify listeners.
finishUpload(ureq);
}
}
} else if (buttonClickedEvent.getPosition() == 1) { //not ok
// Upload renamed. Since we've already uploaded the file with a changed name, don't do anything much here...
this.fileOverwritten = true;
// ... and notify listeners.
finishUpload(ureq);
} else if (buttonClickedEvent.getPosition() == 2) { // cancel
// Cancel. Remove the new file since it has already been uploaded. Note that we don't have to explicitly close the
// dialog box since it closes itself whenever something gets clicked.
newFile.delete();
VersionsManager.getInstance().delete(newFile, true);//force delete the auto-versioning of this temp. file
} 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: {
//upload the file with a new name
this.fileOverwritten = true;
// ... and notify listeners.
finishUpload(ureq);
break;
}
case 1: {//cancel
newFile.delete();
VersionsManager.getInstance().delete(newFile, true);//force delete the auto-versioning of this temp. file
fireEvent(ureq, Event.CANCELLED_EVENT);
break;
}
default:
throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
}
}
} else if (source == commentVersionCtr) {
String comment = commentVersionCtr.getComment();
if(existingVFSItem instanceof MetaTagged) {