Search in sources :

Example 1 with FolderTreeModel

use of org.olat.core.gui.control.generic.folder.FolderTreeModel in project OpenOLAT by OpenOLAT.

the class CmdMoveCopy method execute.

@Override
public Controller execute(FolderComponent fc, UserRequest ureq, WindowControl windowControl, Translator trans) {
    this.folderComponent = fc;
    this.translator = trans;
    this.fileSelection = new FileSelection(ureq, fc.getCurrentContainerPath());
    VelocityContainer main = new VelocityContainer("mc", VELOCITY_ROOT + "/movecopy.html", translator, this);
    main.contextPut("fileselection", fileSelection);
    // check if command is executed on a file list containing invalid filenames or paths
    if (fileSelection.getInvalidFileNames().size() > 0) {
        main.contextPut("invalidFileNames", fileSelection.getInvalidFileNames());
    }
    selTree = new MenuTree(null, "seltree", this);
    FolderTreeModel ftm = new FolderTreeModel(ureq.getLocale(), fc.getRootContainer(), true, false, true, fc.getRootContainer().canWrite() == VFSConstants.YES, new EditableFilter());
    selTree.setTreeModel(ftm);
    selectButton = LinkFactory.createButton(move ? "move" : "copy", main, this);
    cancelButton = LinkFactory.createButton("cancel", main, this);
    main.put("seltree", selTree);
    if (move) {
        main.contextPut("move", Boolean.TRUE);
    }
    setInitialComponent(main);
    return this;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) MenuTree(org.olat.core.gui.components.tree.MenuTree) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 2 with FolderTreeModel

use of org.olat.core.gui.control.generic.folder.FolderTreeModel 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);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) Versionable(org.olat.core.util.vfs.version.Versionable) VFSStatus(org.olat.core.util.vfs.VFSStatus) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 3 with FolderTreeModel

use of org.olat.core.gui.control.generic.folder.FolderTreeModel in project openolat by klemens.

the class CmdMoveCopy method execute.

@Override
public Controller execute(FolderComponent fc, UserRequest ureq, WindowControl windowControl, Translator trans) {
    this.folderComponent = fc;
    this.translator = trans;
    this.fileSelection = new FileSelection(ureq, fc.getCurrentContainerPath());
    VelocityContainer main = new VelocityContainer("mc", VELOCITY_ROOT + "/movecopy.html", translator, this);
    main.contextPut("fileselection", fileSelection);
    // check if command is executed on a file list containing invalid filenames or paths
    if (fileSelection.getInvalidFileNames().size() > 0) {
        main.contextPut("invalidFileNames", fileSelection.getInvalidFileNames());
    }
    selTree = new MenuTree(null, "seltree", this);
    FolderTreeModel ftm = new FolderTreeModel(ureq.getLocale(), fc.getRootContainer(), true, false, true, fc.getRootContainer().canWrite() == VFSConstants.YES, new EditableFilter());
    selTree.setTreeModel(ftm);
    selectButton = LinkFactory.createButton(move ? "move" : "copy", main, this);
    cancelButton = LinkFactory.createButton("cancel", main, this);
    main.put("seltree", selTree);
    if (move) {
        main.contextPut("move", Boolean.TRUE);
    }
    setInitialComponent(main);
    return this;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) MenuTree(org.olat.core.gui.components.tree.MenuTree) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 4 with FolderTreeModel

use of org.olat.core.gui.control.generic.folder.FolderTreeModel in project openolat by klemens.

the class CmdMoveCopy method getTarget.

public String getTarget() {
    FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
    String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
    return selectedPath;
}
Also used : FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel)

Example 5 with FolderTreeModel

use of org.olat.core.gui.control.generic.folder.FolderTreeModel in project OpenOLAT by OpenOLAT.

the class CmdMoveCopy method getTarget.

public String getTarget() {
    FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
    String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
    return selectedPath;
}
Also used : FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel)

Aggregations

FolderTreeModel (org.olat.core.gui.control.generic.folder.FolderTreeModel)6 FileSelection (org.olat.core.commons.modules.bc.FileSelection)2 FolderEvent (org.olat.core.commons.modules.bc.FolderEvent)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 MenuTree (org.olat.core.gui.components.tree.MenuTree)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 OlatRelPathImpl (org.olat.core.util.vfs.OlatRelPathImpl)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 VFSStatus (org.olat.core.util.vfs.VFSStatus)2 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)2 Versionable (org.olat.core.util.vfs.version.Versionable)2