use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.
the class CmdMoveCopy method doMove.
private void doMove(UserRequest ureq) {
FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
if (selectedPath == null) {
abortFailed(ureq, "failed");
return;
}
VFSStatus vfsStatus = VFSConstants.SUCCESS;
VFSContainer rootContainer = folderComponent.getRootContainer();
VFSItem vfsItem = rootContainer.resolve(selectedPath);
if (vfsItem == null || (vfsItem.canWrite() != VFSConstants.YES)) {
abortFailed(ureq, "failed");
return;
}
// copy the files
VFSContainer target = (VFSContainer) vfsItem;
List<VFSItem> sources = getSanityCheckedSourceItems(target, ureq);
if (sources == null)
return;
boolean targetIsRelPath = (target instanceof OlatRelPathImpl);
for (VFSItem vfsSource : sources) {
if (targetIsRelPath && (target instanceof OlatRelPathImpl) && (vfsSource instanceof MetaTagged)) {
// copy the metainfo first
MetaInfo meta = ((MetaTagged) vfsSource).getMetaInfo();
if (meta != null) {
meta.moveCopyToDir((OlatRelPathImpl) target, move);
}
}
VFSItem targetFile = target.resolve(vfsSource.getName());
if (vfsSource instanceof VFSLeaf && targetFile != null && targetFile instanceof Versionable && ((Versionable) targetFile).getVersions().isVersioned()) {
// add a new version to the file
((Versionable) targetFile).getVersions().addVersion(null, "", ((VFSLeaf) vfsSource).getInputStream());
} else {
vfsStatus = target.copyFrom(vfsSource);
}
if (vfsStatus != VFSConstants.SUCCESS) {
String errorKey = "failed";
if (vfsStatus == VFSConstants.ERROR_QUOTA_EXCEEDED)
errorKey = "QuotaExceeded";
abortFailed(ureq, errorKey);
return;
}
if (move) {
// if move, delete the source. Note that meta source
// has already been delete (i.e. moved)
vfsSource.delete();
}
}
// after a copy or a move, notify the subscribers
VFSSecurityCallback secCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
if (secCallback != null) {
SubscriptionContext subsContext = secCallback.getSubscriptionContext();
if (subsContext != null) {
NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
}
}
fireEvent(ureq, new FolderEvent(move ? FolderEvent.MOVE_EVENT : FolderEvent.COPY_EVENT, fileSelection.renderAsHtml()));
notifyFinished(ureq);
}
use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.
the class CmdCreateFile method event.
public void event(UserRequest ureq, Controller source, Event event) {
if (source == editorCtr) {
if (event == Event.DONE_EVENT) {
// we're done, notify listerers
fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FILE_EVENT, fileName));
notifyFinished(ureq);
} else if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
}
}
}
use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.
the class CmdCreateFolder method formOK.
@Override
protected void formOK(UserRequest ureq) {
// create the folder
String name = textElement.getValue();
VFSContainer currentContainer = folderComponent.getCurrentContainer();
VFSItem item = currentContainer.createChildContainer(name);
if (item instanceof OlatRelPathImpl) {
// update meta data
MetaInfo meta = metaInfoFactory.createMetaInfoFor((OlatRelPathImpl) item);
meta.setAuthor(ureq.getIdentity());
meta.write();
status = FolderCommandStatus.STATUS_FAILED;
fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FOLDER_EVENT, folderName));
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else {
status = FolderCommandStatus.STATUS_FAILED;
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
}
use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.
the class CmdDelete method event.
public void event(UserRequest ureq, Controller source, Event event) {
if (source == dialogCtr) {
if (DialogBoxUIFactory.isYesEvent(event)) {
// do delete
VFSContainer currentContainer = folderComponent.getCurrentContainer();
List<String> files = fileSelection.getFiles();
if (files.size() == 0) {
// sometimes, browser sends empty form data...
getWindowControl().setError(translator.translate("failed"));
status = FolderCommandStatus.STATUS_FAILED;
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
}
for (String file : files) {
VFSItem item = currentContainer.resolve(file);
if (item != null && (item.canDelete() == VFSConstants.YES)) {
if (item instanceof MetaTagged) {
// delete all meta info
MetaInfo meta = ((MetaTagged) item).getMetaInfo();
if (meta != null) {
meta.deleteAll();
}
}
// delete the item itself
item.delete();
} else {
getWindowControl().setWarning(translator.translate("del.partial"));
}
}
String confirmationText = fileSelection.renderAsHtml();
fireEvent(ureq, new FolderEvent(FolderEvent.DELETE_EVENT, confirmationText));
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
} else {
// abort
status = FolderCommandStatus.STATUS_CANCELED;
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
}
}
}
use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.
the class CmdZip method formOK.
/**
* Creates a zipFile by using ZipUtil and fires Event.DONE_EVENT if successful.
*
* @see org.olat.core.commons.modules.bc.commands.AbstractCreateItemForm#formOK(org.olat.core.gui.UserRequest)
*/
@Override
protected void formOK(UserRequest ureq) {
String name = textElement.getValue();
if (!name.toLowerCase().endsWith(".zip")) {
name += ".zip";
}
VFSItem zipFile = currentContainer.createChildLeaf(name);
if (zipFile == null) {
fireEvent(ureq, Event.FAILED_EVENT);
return;
}
List<VFSItem> vfsFiles = new ArrayList<VFSItem>();
for (String fileName : selection.getFiles()) {
VFSItem item = currentContainer.resolve(fileName);
if (item != null) {
vfsFiles.add(item);
}
}
if (!ZipUtil.zip(vfsFiles, (VFSLeaf) zipFile, true)) {
// cleanup zip file
zipFile.delete();
status = FolderCommandStatus.STATUS_FAILED;
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
} else {
if (zipFile instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) zipFile).getMetaInfo();
if (info != null) {
info.setAuthor(ureq.getIdentity());
info.write();
}
}
fireEvent(ureq, new FolderEvent(FolderEvent.ZIP_EVENT, selection.renderAsHtml()));
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
}
Aggregations