Search in sources :

Example 1 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent 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 TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project OpenOLAT by OpenOLAT.

the class MailListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            int rowid = te.getRowId();
            DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(rowid);
            if (CMD_READ.equals(actionid)) {
                if (outbox && StringHelper.containsNonWhitespace(mail.getMetaId()) && !mail.getMetaId().equals(metaId)) {
                    selectMetaMail(ureq, mail.getMetaId());
                } else {
                    selectMail(ureq, mail.getKey());
                }
            } else if (CMD_PROFILE.equals(actionid)) {
                DBMailRecipient from = mail.getFrom();
                if (from != null && from.getRecipient() != null) {
                    contextResolver.open(ureq, getWindowControl(), "[Identity:" + from.getRecipient().getKey() + "]");
                }
            } else if (CMD_MARK_TOGGLE.equals(actionid)) {
                mail = mailManager.toggleMarked(mail, getIdentity());
                replaceInModel(mail);
            } else if (CMD_READ_TOGGLE.equals(actionid)) {
                mail = mailManager.toggleRead(mail, getIdentity());
                replaceInModel(mail);
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            // Multiselect events
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            BitSet selectedMails = tmse.getSelection();
            if (selectedMails.isEmpty()) {
                tableVC.setDirty(true);
                showWarning("mail.action.emtpy");
                return;
            }
            String actionid = tmse.getAction();
            if (CMD_DELETE.equals(actionid)) {
                String title = translate("mail.confirm.delete.title");
                int selected = selectedMails.cardinality();
                String text;
                if (selected == 1) {
                    text = translate("mail.confirm.delete.single.text");
                } else {
                    text = translate("mail.confirm.delete.multi.text", selected + "");
                }
                deleteConfirmationBox = activateYesNoDialog(ureq, title, text, deleteConfirmationBox);
                deleteConfirmationBox.setUserObject(selectedMails);
            } else if (CMD_SEND_REAL_MAIL.equals(actionid)) {
                for (int i = selectedMails.nextSetBit(0); i >= 0; i = selectedMails.nextSetBit(i + 1)) {
                    DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(i);
                    MailerResult result = forwardToMyRealMail(mail);
                    if (result.getReturnCode() != MailerResult.OK) {
                        MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), getLocale());
                    } else {
                        showInfo("mail.action.send.real.success", mail.getSubject());
                    }
                }
                reloadModel();
            } else if (CMD_MARK_MARKED.equals(actionid) || CMD_MARK_UNMARKED.equals(actionid)) {
                for (int i = selectedMails.nextSetBit(0); i >= 0; i = selectedMails.nextSetBit(i + 1)) {
                    DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(i);
                    mailManager.setMarked(mail, CMD_MARK_MARKED.equals(actionid), getIdentity());
                }
                reloadModel();
            } else if (CMD_MARK_READ.equals(actionid) || CMD_MARK_UNREAD.equals(actionid)) {
                for (int i = selectedMails.nextSetBit(0); i >= 0; i = selectedMails.nextSetBit(i + 1)) {
                    DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(i);
                    mailManager.setRead(mail, CMD_MARK_READ.equals(actionid), getIdentity());
                }
                reloadModel();
            }
        } else if (TableController.EVENT_FILTER_SELECTED == event) {
            MailDataModel dataModel = (MailDataModel) tableCtr.getTableDataModel();
            MailContextShortName filter = (MailContextShortName) tableCtr.getActiveFilter();
            dataModel.filter(filter);
            tableCtr.setTableDataModel(dataModel);
        } else if (TableController.EVENT_NOFILTER_SELECTED == event) {
            MailDataModel dataModel = (MailDataModel) tableCtr.getTableDataModel();
            dataModel.filter(null);
            tableCtr.setTableDataModel(dataModel);
        }
    } else if (source == mailCtr) {
        backFromMail();
    } else if (source == metaMailCtr) {
        removeAsListenerAndDispose(metaMailCtr);
        metaMailCtr = null;
        mainVC.put(MAIN_CMP, tableVC);
    } else if (source == deleteConfirmationBox) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            BitSet deleteMails = (BitSet) deleteConfirmationBox.getUserObject();
            for (int i = deleteMails.nextSetBit(0); i >= 0; i = deleteMails.nextSetBit(i + 1)) {
                DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(i);
                // reload the message
                mail = mailManager.getMessageByKey(mail.getKey());
                boolean deleteMetaMail = outbox && !StringHelper.containsNonWhitespace(metaId);
                mailManager.delete(mail, getIdentity(), deleteMetaMail);
            // Do not remove from model to prevent concurrent modification
            // exception, instead just reload model afterwards
            }
            reloadModel();
        }
    } else {
        super.event(ureq, source, event);
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) MailerResult(org.olat.core.util.mail.MailerResult) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) BitSet(java.util.BitSet) DBMailLight(org.olat.core.util.mail.model.DBMailLight) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Example 3 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project OpenOLAT by OpenOLAT.

the class SelectionForm method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) {
                int rowid = te.getRowId();
                UserDeletionManager.getInstance().setIdentityAsActiv(tdm.getObject(rowid));
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(ACTION_MULTISELECT_CHOOSE)) {
                handleEmailButtonEvent(ureq, tmse);
            }
        }
        initializeContent();
    } else if (source == deleteUserMailCtr) {
        if (event == Event.DONE_EVENT) {
            String warningMessage = UserDeletionManager.getInstance().sendUserDeleteEmailTo(selectedIdentities, deleteUserMailCtr.getMailTemplate(), deleteUserMailCtr.isTemplateChanged(), KEY_EMAIL_SUBJECT, KEY_EMAIL_BODY, ureq.getIdentity(), getTranslator());
            cmc.deactivate();
            if (deleteUserMailCtr.getMailTemplate() != null) {
                // when mailtemplate is null, user decides to send no email => no status message
                if (warningMessage.length() > 0) {
                    this.showWarning("delete.email.announcement.warning.header", warningMessage);
                } else {
                    this.showInfo("selection.feedback.msg");
                }
            }
            initializeContent();
        } else if (event == Event.CANCELLED_EVENT) {
            cmc.deactivate();
        } else {
            throw new RuntimeException("unknown event ::" + event.getCommand());
        }
    } else if (source == selectionForm) {
        if (event == Event.DONE_EVENT) {
            UserDeletionManager.getInstance().setLastLoginDuration(selectionForm.getLastLoginDuration());
            UserDeletionManager.getInstance().setDeleteEmailDuration(selectionForm.getDeleteEmailDuration());
            initializeContent();
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
        cmc.deactivate();
        removeAsListenerAndDispose(selectionForm);
        removeAsListenerAndDispose(cmc);
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent)

Example 4 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project OpenOLAT by OpenOLAT.

the class UserSearchController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) {
                int rowid = te.getRowId();
                Identity foundIdentity = tdm.getObject(rowid);
                foundIdentities.add(foundIdentity);
                // Tell parentController that a subject has been found
                fireEvent(ureq, new SingleIdentityChosenEvent(foundIdentity));
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(ACTION_MULTISELECT_CHOOSE)) {
                foundIdentities = tdm.getObjects(tmse.getSelection());
                fireEvent(ureq, new MultiIdentityChosenEvent(foundIdentities));
            }
        }
    } else if (source == autocompleterC) {
        if (event instanceof EntriesChosenEvent) {
            EntriesChosenEvent ece = (EntriesChosenEvent) event;
            List<String> res = ece.getEntries();
            // if we get the event, we have a result or an incorrect selection see OLAT-5114 -> check for empty
            String mySel = res.isEmpty() ? null : (String) res.get(0);
            if ((mySel == null) || mySel.trim().equals("")) {
                getWindowControl().setWarning(translate("error.search.form.notempty"));
                return;
            }
            // default not found
            Long key = -1l;
            try {
                key = Long.valueOf(mySel);
                if (key > 0) {
                    Identity chosenIdent = BaseSecurityManager.getInstance().loadIdentityByKey(key);
                    // No need to check for null, exception is thrown when identity does not exist which really
                    // should not happen at all.
                    // Tell that an identity has been chosen
                    fireEvent(ureq, new SingleIdentityChosenEvent(chosenIdent));
                }
            } catch (NumberFormatException e) {
                getWindowControl().setWarning(translate("error.no.user.found"));
                return;
            }
        }
    } else if (source == searchform) {
        if (event == Event.DONE_EVENT) {
            // form validation was ok
            doSearch(ureq);
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) ArrayList(java.util.ArrayList) List(java.util.List) Identity(org.olat.core.id.Identity) MultiIdentityChosenEvent(org.olat.basesecurity.events.MultiIdentityChosenEvent) EntriesChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent)

Example 5 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project OpenOLAT by OpenOLAT.

the class WaitingGroupController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Controller sourceController, Event event) {
    if (sourceController == tableCtr) {
        if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            // Multiselect events
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(COMMAND_MOVE_USER_WAITINGLIST)) {
                if (tmse.getSelection().isEmpty()) {
                    getWindowControl().setWarning(translate("msg.selectionempty"));
                } else {
                    List<Identity> objects = identitiesTableModel.getIdentities(tmse.getSelection());
                    toTransfer = objects;
                    removeAsListenerAndDispose(transferMailCtr);
                    transferMailCtr = new MailNotificationEditController(getWindowControl(), ureq, transferUserMailTempl, true, mandatoryEmail, true);
                    listenTo(transferMailCtr);
                    removeAsListenerAndDispose(cmc);
                    cmc = new CloseableModalController(getWindowControl(), translate("close"), transferMailCtr.getInitialComponent());
                    listenTo(cmc);
                    cmc.activate();
                    // don't execute super method
                    return;
                }
            }
        }
    } else if (sourceController == transferMailCtr) {
        if (event == Event.DONE_EVENT) {
            // fetch configured mail template and finish this controller workflow
            MailTemplate customTransferTemplate = transferMailCtr.getMailTemplate();
            cmc.deactivate();
            IdentitiesMoveEvent identitiesMoveEvent = new IdentitiesMoveEvent(toTransfer);
            identitiesMoveEvent.setMailTemplate(customTransferTemplate);
            fireEvent(ureq, identitiesMoveEvent);
            StringBuilder infoMessage = new StringBuilder();
            for (Identity identity : identitiesMoveEvent.getNotMovedIdentities()) {
                String fullName = userManager.getUserDisplayName(identity);
                infoMessage.append(translate("msg.alreadyinwaiitinggroup", fullName)).append("<br />");
            }
            // report any errors on screen
            if (infoMessage.length() > 0)
                getWindowControl().setInfo(infoMessage.toString());
            // don't execute super method
            return;
        } else if (event == Event.CANCELLED_EVENT) {
            cmc.deactivate();
            // don't execute super method
            return;
        } else {
            throw new RuntimeException("unknown event ::" + event.getCommand());
        }
    }
    // it is no WaitingGroupController event, forward it to super class GroupController
    super.event(ureq, sourceController, event);
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) MailNotificationEditController(org.olat.core.util.mail.MailNotificationEditController)

Aggregations

TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)48 TableEvent (org.olat.core.gui.components.table.TableEvent)40 ArrayList (java.util.ArrayList)34 List (java.util.List)34 Identity (org.olat.core.id.Identity)18 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)16 BitSet (java.util.BitSet)12 SingleIdentityChosenEvent (org.olat.basesecurity.events.SingleIdentityChosenEvent)10 MultiIdentityChosenEvent (org.olat.basesecurity.events.MultiIdentityChosenEvent)8 UserRequest (org.olat.core.gui.UserRequest)6 WindowControl (org.olat.core.gui.control.WindowControl)6 ControllerCreator (org.olat.core.gui.control.creator.ControllerCreator)6 PopupBrowserWindow (org.olat.core.gui.control.generic.popup.PopupBrowserWindow)6 MailNotificationEditController (org.olat.core.util.mail.MailNotificationEditController)6 MailTemplate (org.olat.core.util.mail.MailTemplate)6 UserInfoMainController (org.olat.user.UserInfoMainController)6 MediaResource (org.olat.core.gui.media.MediaResource)4 AssertException (org.olat.core.logging.AssertException)4 MailerResult (org.olat.core.util.mail.MailerResult)4 VFSRevisionMediaResource (org.olat.core.util.vfs.VFSRevisionMediaResource)4