Search in sources :

Example 1 with VFSRevisionMediaResource

use of org.olat.core.util.vfs.VFSRevisionMediaResource in project OpenOLAT by OpenOLAT.

the class RevisionListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == revisionListTableCtr) {
        if (event instanceof TableEvent) {
            TableEvent tEvent = (TableEvent) event;
            int row = tEvent.getRowId();
            if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
                MediaResource resource;
                if (row < versionedFile.getVersions().getRevisions().size()) {
                    // restore current, do nothing
                    VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
                    resource = new VFSRevisionMediaResource(version, true);
                } else {
                    resource = new VFSMediaResource((VFSLeaf) versionedFile);
                    ((VFSMediaResource) resource).setDownloadable(true);
                }
                ureq.getDispatchResult().setResultingMediaResource(resource);
            } else if (CMD_RESTORE.equals(tEvent.getActionId())) {
                if (row >= versionedFile.getVersions().getRevisions().size()) {
                    // restore current, do nothing
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
                    String comment = translate("version.restore.comment", new String[] { version.getRevisionNr() });
                    if (versionedFile.getVersions().restore(ureq.getIdentity(), version, comment)) {
                        status = FolderCommandStatus.STATUS_SUCCESS;
                        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                    } else {
                        status = FolderCommandStatus.STATUS_FAILED;
                        showError("version.restore.failed");
                        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                    }
                }
            }
        } else if (event instanceof TableMultiSelectEvent) {
            TableMultiSelectEvent tEvent = (TableMultiSelectEvent) event;
            if (CMD_CANCEL.equals(tEvent.getAction())) {
                status = FolderCommandStatus.STATUS_CANCELED;
                fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
            } else {
                List<VFSRevision> selectedVersions = getSelectedRevisions(tEvent.getSelection());
                if (!selectedVersions.isEmpty()) {
                    if (CMD_DELETE.equals(tEvent.getAction())) {
                        String numOfVersionToDelete = Integer.toString(selectedVersions.size());
                        confirmDeleteBoxCtr = activateYesNoDialog(ureq, null, translate("version.confirmDelete", new String[] { numOfVersionToDelete }), confirmDeleteBoxCtr);
                        confirmDeleteBoxCtr.setUserObject(selectedVersions);
                    }
                }
            }
        }
    } else if (source == confirmDeleteBoxCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            @SuppressWarnings("unchecked") List<VFSRevision> selectedVersions = (List<VFSRevision>) confirmDeleteBoxCtr.getUserObject();
            versionedFile.getVersions().delete(ureq.getIdentity(), selectedVersions);
            status = FolderCommandStatus.STATUS_SUCCESS;
        } else {
            status = FolderCommandStatus.STATUS_CANCELED;
        }
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) TableEvent(org.olat.core.gui.components.table.TableEvent) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) ArrayList(java.util.ArrayList) List(java.util.List) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 2 with VFSRevisionMediaResource

use of org.olat.core.util.vfs.VFSRevisionMediaResource in project openolat by klemens.

the class RevisionListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == revisionListTableCtr) {
        if (event instanceof TableEvent) {
            TableEvent tEvent = (TableEvent) event;
            int row = tEvent.getRowId();
            if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
                MediaResource resource;
                if (row < versionedFile.getVersions().getRevisions().size()) {
                    // restore current, do nothing
                    VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
                    resource = new VFSRevisionMediaResource(version, true);
                } else {
                    resource = new VFSMediaResource((VFSLeaf) versionedFile);
                    ((VFSMediaResource) resource).setDownloadable(true);
                }
                ureq.getDispatchResult().setResultingMediaResource(resource);
            } else if (CMD_RESTORE.equals(tEvent.getActionId())) {
                if (row >= versionedFile.getVersions().getRevisions().size()) {
                    // restore current, do nothing
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
                    String comment = translate("version.restore.comment", new String[] { version.getRevisionNr() });
                    if (versionedFile.getVersions().restore(ureq.getIdentity(), version, comment)) {
                        status = FolderCommandStatus.STATUS_SUCCESS;
                        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                    } else {
                        status = FolderCommandStatus.STATUS_FAILED;
                        showError("version.restore.failed");
                        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                    }
                }
            }
        } else if (event instanceof TableMultiSelectEvent) {
            TableMultiSelectEvent tEvent = (TableMultiSelectEvent) event;
            if (CMD_CANCEL.equals(tEvent.getAction())) {
                status = FolderCommandStatus.STATUS_CANCELED;
                fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
            } else {
                List<VFSRevision> selectedVersions = getSelectedRevisions(tEvent.getSelection());
                if (!selectedVersions.isEmpty()) {
                    if (CMD_DELETE.equals(tEvent.getAction())) {
                        String numOfVersionToDelete = Integer.toString(selectedVersions.size());
                        confirmDeleteBoxCtr = activateYesNoDialog(ureq, null, translate("version.confirmDelete", new String[] { numOfVersionToDelete }), confirmDeleteBoxCtr);
                        confirmDeleteBoxCtr.setUserObject(selectedVersions);
                    }
                }
            }
        }
    } else if (source == confirmDeleteBoxCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            @SuppressWarnings("unchecked") List<VFSRevision> selectedVersions = (List<VFSRevision>) confirmDeleteBoxCtr.getUserObject();
            versionedFile.getVersions().delete(ureq.getIdentity(), selectedVersions);
            status = FolderCommandStatus.STATUS_SUCCESS;
        } else {
            status = FolderCommandStatus.STATUS_CANCELED;
        }
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) TableEvent(org.olat.core.gui.components.table.TableEvent) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) ArrayList(java.util.ArrayList) List(java.util.List) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 3 with VFSRevisionMediaResource

use of org.olat.core.util.vfs.VFSRevisionMediaResource in project OpenOLAT by OpenOLAT.

the class DeletedFileListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deletedFilesListTableCtr) {
        if (event instanceof TableEvent) {
            TableEvent tEvent = (TableEvent) event;
            int row = tEvent.getRowId();
            if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
                VFSRevision version = getLastRevision(deletedFiles.get(row));
                MediaResource resource = new VFSRevisionMediaResource(version, true);
                ureq.getDispatchResult().setResultingMediaResource(resource);
            } else if (CMD_RESTORE.equals(tEvent.getActionId())) {
                VFSRevision version = getLastRevision(deletedFiles.get(row));
                if (VersionsManager.getInstance().restore(container, version)) {
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    status = FolderCommandStatus.STATUS_FAILED;
                // ERROR
                }
            }
        } else if (event instanceof TableMultiSelectEvent) {
            TableMultiSelectEvent tEvent = (TableMultiSelectEvent) event;
            if (CMD_CANCEL.equals(tEvent.getAction())) {
                status = FolderCommandStatus.STATUS_CANCELED;
                fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
            } else if (CMD_RESTORE.equals(tEvent.getAction())) {
                List<VFSRevision> selectedRevisions = getSelectedRevisions(tEvent.getSelection());
                boolean allOk = true;
                for (VFSRevision revision : selectedRevisions) {
                    allOk &= VersionsManager.getInstance().restore(container, revision);
                }
                if (allOk) {
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    status = FolderCommandStatus.STATUS_FAILED;
                }
            } else if (CMD_DELETE.equals(tEvent.getAction())) {
                List<Versions> versionsToDelete = getSelectedVersions(tEvent.getSelection());
                if (!versionsToDelete.isEmpty()) {
                    String msg = translate("version.del.confirm") + "<p>" + renderVersionsAsHtml(versionsToDelete) + "</p>";
                    // create dialog controller
                    dialogCtr = activateYesNoDialog(ureq, translate("version.del.header"), msg, dialogCtr);
                    dialogCtr.setUserObject(versionsToDelete);
                }
            }
        }
    } else if (source == dialogCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            @SuppressWarnings("unchecked") List<Versions> versionsToDelete = (List<Versions>) dialogCtr.getUserObject();
            VersionsManager.getInstance().deleteVersions(versionsToDelete);
            status = FolderCommandStatus.STATUS_SUCCESS;
            fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
        }
    }
}
Also used : Versions(org.olat.core.util.vfs.version.Versions) TableEvent(org.olat.core.gui.components.table.TableEvent) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) MediaResource(org.olat.core.gui.media.MediaResource) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with VFSRevisionMediaResource

use of org.olat.core.util.vfs.VFSRevisionMediaResource in project openolat by klemens.

the class DeletedFileListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deletedFilesListTableCtr) {
        if (event instanceof TableEvent) {
            TableEvent tEvent = (TableEvent) event;
            int row = tEvent.getRowId();
            if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
                VFSRevision version = getLastRevision(deletedFiles.get(row));
                MediaResource resource = new VFSRevisionMediaResource(version, true);
                ureq.getDispatchResult().setResultingMediaResource(resource);
            } else if (CMD_RESTORE.equals(tEvent.getActionId())) {
                VFSRevision version = getLastRevision(deletedFiles.get(row));
                if (VersionsManager.getInstance().restore(container, version)) {
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    status = FolderCommandStatus.STATUS_FAILED;
                // ERROR
                }
            }
        } else if (event instanceof TableMultiSelectEvent) {
            TableMultiSelectEvent tEvent = (TableMultiSelectEvent) event;
            if (CMD_CANCEL.equals(tEvent.getAction())) {
                status = FolderCommandStatus.STATUS_CANCELED;
                fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
            } else if (CMD_RESTORE.equals(tEvent.getAction())) {
                List<VFSRevision> selectedRevisions = getSelectedRevisions(tEvent.getSelection());
                boolean allOk = true;
                for (VFSRevision revision : selectedRevisions) {
                    allOk &= VersionsManager.getInstance().restore(container, revision);
                }
                if (allOk) {
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    status = FolderCommandStatus.STATUS_FAILED;
                }
            } else if (CMD_DELETE.equals(tEvent.getAction())) {
                List<Versions> versionsToDelete = getSelectedVersions(tEvent.getSelection());
                if (!versionsToDelete.isEmpty()) {
                    String msg = translate("version.del.confirm") + "<p>" + renderVersionsAsHtml(versionsToDelete) + "</p>";
                    // create dialog controller
                    dialogCtr = activateYesNoDialog(ureq, translate("version.del.header"), msg, dialogCtr);
                    dialogCtr.setUserObject(versionsToDelete);
                }
            }
        }
    } else if (source == dialogCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            @SuppressWarnings("unchecked") List<Versions> versionsToDelete = (List<Versions>) dialogCtr.getUserObject();
            VersionsManager.getInstance().deleteVersions(versionsToDelete);
            status = FolderCommandStatus.STATUS_SUCCESS;
            fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
        }
    }
}
Also used : Versions(org.olat.core.util.vfs.version.Versions) TableEvent(org.olat.core.gui.components.table.TableEvent) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) MediaResource(org.olat.core.gui.media.MediaResource) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)4 List (java.util.List)4 TableEvent (org.olat.core.gui.components.table.TableEvent)4 TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)4 MediaResource (org.olat.core.gui.media.MediaResource)4 VFSRevisionMediaResource (org.olat.core.util.vfs.VFSRevisionMediaResource)4 VFSRevision (org.olat.core.util.vfs.version.VFSRevision)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)2 Versions (org.olat.core.util.vfs.version.Versions)2