Search in sources :

Example 21 with FolderEvent

use of org.olat.core.commons.modules.bc.FolderEvent in project OpenOLAT by OpenOLAT.

the class FileLinkChooserController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == uploadCtr) {
        if (event instanceof FolderEvent) {
            FolderEvent folderEvent = (FolderEvent) event;
            if (isFileSuffixOk(folderEvent.getFilename())) {
                Size size = null;
                VFSItem item = folderEvent.getItem();
                String relPath;
                if (item != null) {
                    size = getSize(item, item.getName());
                    relPath = FileChooserUIFactory.getSelectedRelativeItemPath(folderEvent, rootDir, fileName);
                } else {
                    relPath = folderEvent.getFilename();
                }
                if (StringHelper.containsNonWhitespace(absolutePath)) {
                    relPath = absolutePath + relPath;
                }
                if (size != null) {
                    fireEvent(ureq, new URLChoosenEvent(relPath, null, null, null, size.getWidth(), size.getHeight()));
                } else {
                    fireEvent(ureq, new URLChoosenEvent(relPath));
                }
            } else {
                setErrorMessage(folderEvent.getFilename());
            }
        }
        if (event == Event.DONE_EVENT) {
            if (uploadCtr.getStatus() == FolderCommandStatus.STATUS_CANCELED) {
                fireEvent(ureq, Event.CANCELLED_EVENT);
            }
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        } else if (event == Event.FAILED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    } else if (source == fileChooserController) {
        if (event instanceof FileChoosenEvent) {
            FileChoosenEvent fileEvent = (FileChoosenEvent) event;
            VFSItem item = fileEvent.getSelectedItem();
            Size size = getSize(item, item.getName());
            String relPath = FileChooserUIFactory.getSelectedRelativeItemPath(fileEvent, rootDir, fileName);
            // notify parent controller
            if (StringHelper.containsNonWhitespace(absolutePath)) {
                relPath = absolutePath + relPath;
            }
            if (size != null) {
                fireEvent(ureq, new URLChoosenEvent(relPath, null, null, null, size.getWidth(), size.getHeight()));
            } else {
                fireEvent(ureq, new URLChoosenEvent(relPath));
            }
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        } else if (event == Event.FAILED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    }
}
Also used : Size(org.olat.core.commons.services.image.Size) VFSItem(org.olat.core.util.vfs.VFSItem) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) FileChoosenEvent(org.olat.core.commons.controllers.filechooser.FileChoosenEvent)

Example 22 with FolderEvent

use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.

the class VideoPosterEditController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == posterUploadForm || source == posterSelectionForm) {
        if (event instanceof FolderEvent) {
            VFSLeaf posterFile = (VFSLeaf) ((FolderEvent) event).getItem();
            if (source == posterUploadForm) {
                videoManager.setPosterframeResizeUploadfile(videoResource, posterFile);
                posterFile.delete();
            } else {
                videoManager.setPosterframe(videoResource, posterFile);
            }
            updatePosterImage(ureq, videoResource);
        }
        cmc.deactivate();
        cleanUp();
    } else if (cmc == source) {
        cleanUp();
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 23 with FolderEvent

use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.

the class VideoPosterSelectionForm method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (source instanceof Link) {
        Link button = (Link) source;
        VFSItem posterFile = tmpContainer.resolve((String) button.getUserObject());
        if (posterFile instanceof VFSLeaf) {
            fireEvent(ureq, new FolderEvent(FolderEvent.UPLOAD_EVENT, posterFile));
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItem(org.olat.core.util.vfs.VFSItem) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) Link(org.olat.core.gui.components.link.Link)

Example 24 with FolderEvent

use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.

the class VideoPosterUploadForm method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (posterField.isUploadSuccess()) {
        if (remainingSpace != -1) {
            if (posterField.getUploadFile().length() / 1024 > remainingSpace) {
                posterField.setErrorKey("QuotaExceeded", null);
                posterField.getUploadFile().delete();
                return;
            }
        } else {
            fireEvent(ureq, new FolderEvent(FolderEvent.UPLOAD_EVENT, posterField.moveUploadFileTo(metaDataFolder)));
        }
    }
}
Also used : FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 25 with FolderEvent

use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.

the class WikiMainController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    Wiki wiki = getWiki();
    if (wiki == null) {
        mainPanel.setContent(createVelocityContainer("deleted"));
        return;
    }
    // reload page from cache
    WikiPage page = wiki.getPage(pageId, true);
    // set recent page id to the page currently used
    this.pageId = page.getPageId();
    if (event instanceof TreeEvent) {
        TreeEvent te = (TreeEvent) event;
        String nodeId = te.getNodeId();
        if (navAZNode.getIdent().equals(nodeId)) {
            openAtoZPage(ureq, wiki);
        } else if (navChangesNode.getIdent().equals(nodeId)) {
            openLastChangesPage(ureq, wiki);
        } else if (navMainPageNode.getIdent().equals(nodeId)) {
            page = openIndexPage(ureq, wiki);
        } else if (wikiMenuNode.getIdent().equals(nodeId)) {
            page = openPage(ureq, WikiPage.WIKI_MENU_PAGE, wiki);
        } else {
            TreeNode node = wikiMenuModel.getNodeById(nodeId);
            if (node != null && node.getUserObject() instanceof String) {
                String link = (String) node.getUserObject();
                page = openPage(ureq, link, wiki);
            }
        }
        if (page != null) {
            this.pageId = page.getPageId();
        }
    } else if (source == versioningTableCtr) {
        /**
         ***********************************************************************
         * history table events
         ***********************************************************************
         */
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            if (te.getActionId().equals(ACTION_COMPARE)) {
                selectedPage = versioningTableModel.getObject(te.getRowId());
                diffs = wiki.getDiff(page, selectedPage.getVersion() - 1, selectedPage.getVersion());
                versioningContent.contextPut("diffs", diffs);
                versioningContent.remove(wikiVersionDisplayComp);
                versioningContent.contextPut("page", selectedPage);
            } else if (te.getActionId().equals(ACTION_SHOW)) {
                versioningContent.contextRemove("diffs");
                selectedPage = versioningTableModel.getObject(te.getRowId());
                selectedPage = wiki.loadVersion(selectedPage, selectedPage.getVersion());
                wikiVersionDisplayComp.setWikiContent(selectedPage.getContent());
                wikiVersionDisplayComp.setImageMapperUri(ureq, wikiContainer);
                versioningContent.put("versionDisplay", wikiVersionDisplayComp);
                versioningContent.contextPut("page", selectedPage);
            }
        }
    } else if (source == wikiUploadFileCtr) {
        if (event.getCommand().equals(FolderEvent.UPLOAD_EVENT)) {
            FolderEvent fEvent = (FolderEvent) event;
            createMediaMetadataFile(fEvent.getFilename(), ureq.getIdentity().getKey());
            updateFileAndLinkList(wiki);
        }
        cmc.deactivate();
        cleanUp();
    } else if (source == removePageDialogCtr) {
        if (DialogBoxUIFactory.isOkEvent(event)) {
            wiki.removePage(page);
            breadcrumpDropdown.removeComponent(page.getPageName());
            WikiManager.getInstance().deleteWikiPage(ores, page);
            page = wiki.getPage(WikiPage.WIKI_INDEX_PAGE);
            updatePageContext(ureq, page);
            tabs.setSelectedPane(ureq, 0);
        }
    } else if (source == mediaTableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            if (te.getActionId().equals(ACTION_DELETE_MEDIA)) {
                List<MediaFileElement> list = new ArrayList<MediaFileElement>(1);
                list.add(mediaFilesTableModel.getObject(te.getRowId()));
                deleteMediaFile(list, ureq);
            } else if (te.getActionId().equals(ACTION_SHOW_MEDIA)) {
                // show a selected file from the media folder
                MediaFileElement element = mediaFilesTableModel.getObject(te.getRowId());
                if (isImage(element.getFilename())) {
                    // show images inline
                    // as modal overlay
                    imageDisplay.contextPut("mediaElement", element);
                    imageDisplay.contextPut("imageUri", wikiArticleComp.getImageBaseUri());
                    removeAsListenerAndDispose(cmc);
                    cmc = new CloseableModalController(getWindowControl(), translate("close"), imageDisplay);
                    listenTo(cmc);
                    cmc.activate();
                } else {
                    deliverMediaFile(ureq, element.getFilename());
                }
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(ACTION_DELETE_MEDIAS)) {
                deleteMediaFile(mediaFilesTableModel.getObjects(tmse.getSelection()), ureq);
                updateFileAndLinkList(wiki);
            }
        }
    } else if (source == archiveWikiDialogCtr) {
        if (DialogBoxUIFactory.isOkEvent(event)) {
            WikiToCPResource rsrc = new WikiToCPResource(ores, getIdentity(), getTranslator());
            ureq.getDispatchResult().setResultingMediaResource(rsrc);
        }
    } else if (source == createArticleForm) {
        calloutCtrl.deactivate();
        String query = createArticleForm.getQuery();
        if (!StringHelper.containsNonWhitespace(query)) {
            query = WikiPage.WIKI_INDEX_PAGE;
        }
        page = wiki.findPage(query);
        pageId = page.getPageId();
        if (page.getPageName().equals(Wiki.NEW_PAGE)) {
            setTabsEnabled(false);
        }
        page.incrementViewCount();
        updatePageContext(ureq, page);
        if (!page.getPageName().startsWith("O_")) {
            Link pageLink = LinkFactory.createToolLink(page.getPageName(), "select-page", page.getPageName(), this);
            breadcrumpDropdown.addComponent(pageLink);
        }
        tabs.setSelectedPane(ureq, 0);
    } else if (source == wikiEditForm) {
        // set recent page id to the page currently used
        this.pageId = page.getPageId();
        boolean wantPreview = false;
        boolean wantSave = false;
        boolean wantClose = false;
        if (event == Event.CANCELLED_EVENT) {
            wantClose = true;
        } else if (event == Event.DONE_EVENT) {
            wantSave = true;
        } else if (event.getCommand().equals("save.and.close")) {
            wantClose = true;
            wantSave = true;
            event = Event.DONE_EVENT;
        } else if (event.getCommand().equals("preview")) {
            wantPreview = true;
            event = Event.DONE_EVENT;
        } else if (event.getCommand().equals("delete.page")) {
            String msg = translate("question", page.getPageName());
            removePageDialogCtr = activateOkCancelDialog(ureq, null, msg, removePageDialogCtr);
            return;
        } else if (event.getCommand().equals("media.upload")) {
            doUploadFiles(ureq);
            return;
        } else if (event.getCommand().equals("manage.media")) {
            doManageMedias(ureq, wiki);
            return;
        }
        boolean dirty = !wikiEditForm.getWikiContent().equals(page.getContent());
        if (wantPreview) {
            WikiPage preview = new WikiPage("temp");
            preview.setContent(wikiEditForm.getWikiContent());
            wikiVersionDisplayComp.setWikiContent(preview.getContent());
            editContent.put("versionDisplay", wikiVersionDisplayComp);
        }
        if (wantSave && dirty) {
            editContent.contextPut("isDirty", Boolean.valueOf(false));
            page.setContent(wikiEditForm.getWikiContent());
            page.setModifyAuthor(getIdentity().getKey().longValue());
            page.setUpdateComment(wikiEditForm.getUpdateComment());
            if (page.getInitalAuthor() == 0)
                page.setInitalAuthor(getIdentity().getKey().longValue());
            // changed
            if (page.getPageName().equals(WikiPage.WIKI_MENU_PAGE)) {
                updateWikiMenu(wiki);
            }
            WikiManager.getInstance().saveWikiPage(ores, page, true, wiki);
            // inform subscription context about changes
            NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
            updatePageContext(ureq, page);
        }
        if (dirty && wantPreview && !wantSave) {
            // wikiEditForm.setDirty(true);
            editContent.contextPut("isDirty", Boolean.valueOf(dirty));
        }
        if (wantClose) {
            tabs.setSelectedPane(ureq, 0);
            doReleaseEditLock();
            return;
        }
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) ArrayList(java.util.ArrayList) TreeEvent(org.olat.core.gui.components.tree.TreeEvent) TableEvent(org.olat.core.gui.components.table.TableEvent) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) Link(org.olat.core.gui.components.link.Link)

Aggregations

FolderEvent (org.olat.core.commons.modules.bc.FolderEvent)28 VFSItem (org.olat.core.util.vfs.VFSItem)14 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)8 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)6 ArrayList (java.util.ArrayList)4 Link (org.olat.core.gui.components.link.Link)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 OlatRelPathImpl (org.olat.core.util.vfs.OlatRelPathImpl)4 FileChoosenEvent (org.olat.core.commons.controllers.filechooser.FileChoosenEvent)2 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)2 OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 Size (org.olat.core.commons.services.image.Size)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)2 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)2 TreeEvent (org.olat.core.gui.components.tree.TreeEvent)2