Example #1
0
  /**
   * @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 urequest, Controller source, Event event) {
    if (source == displayController) {
      if (event instanceof IQSubmittedEvent) {
        // Save results in case of test
        if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) {
          exposeUserTestDataToVC(urequest);
        }
        // Save results in case of questionnaire
        else if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY)) {
          exposeUserQuestionnaireDataToVC();

          if (displayContainerController != null) {
            displayContainerController.deactivate(urequest);
          } else {
            getWindowControl().pop();
          }
          OLATResourceable ores = OresHelper.createOLATResourceableInstance("test", -1l);
          addToHistory(urequest, ores, null);
        }
        // Don't save results in case of self-test
        // but do safe attempts !
        else if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_SELF)) {
          // am.incrementNodeAttempts(courseNode, urequest.getIdentity(), userCourseEnv);
        }
      } else if (event.equals(Event.DONE_EVENT)) {
        stopAssessment(urequest, event);
      } else if (IQEvent.TEST_PULLED.equals(event.getCommand())) {
        stopAssessment(urequest, event);
        showWarning("error.assessment.pulled");
      } else if (IQEvent.TEST_STOPPED.equals(event.getCommand())) {
        stopAssessment(urequest, event);
        showWarning("error.assessment.stopped");
      }
    }
  }
 @Override
 protected void event(UserRequest ureq, Controller source, Event event) {
   if (newMethodCtrl == source) {
     if (event.equals(Event.DONE_EVENT)) {
       OfferAccess newLink = newMethodCtrl.commitChanges();
       newLink = acService.saveOfferAccess(newLink);
       addConfiguration(newLink);
       fireEvent(ureq, Event.CHANGED_EVENT);
     }
     cmc.deactivate();
     cleanUp();
   } else if (editMethodCtrl == source) {
     if (event.equals(Event.DONE_EVENT)) {
       OfferAccess newLink = editMethodCtrl.commitChanges();
       newLink = acService.saveOfferAccess(newLink);
       replace(newLink);
       fireEvent(ureq, Event.CHANGED_EVENT);
     }
     cmc.deactivate();
     cleanUp();
   } else if (cmc == source) {
     cleanUp();
   } else {
     super.event(ureq, source, event);
   }
 }
  /**
   * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
   *     org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
   */
  @Override
  public void event(UserRequest ureq, Component source, Event event) {
    if (STATISTICS_FULL_RECALCULATION_TRIGGER_BUTTON.equals(event.getCommand())) {
      StatisticUpdateManager statisticUpdateManager = getStatisticUpdateManager();
      if (statisticUpdateManager == null) {
        log_.info("event: UpdateStatisticsJob configured, but no StatisticManager available");
      } else {

        String title = getTranslator().translate("statistics.fullrecalculation.really.title");
        String text = getTranslator().translate("statistics.fullrecalculation.really.text");
        dialogCtr_ = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), title, text);
        listenTo(dialogCtr_);
        dialogCtr_.activate();
      }
    } else if (STATISTICS_UPDATE_TRIGGER_BUTTON.equals(event.getCommand())) {
      StatisticUpdateManager statisticUpdateManager = getStatisticUpdateManager();
      if (statisticUpdateManager == null) {
        log_.info("event: UpdateStatisticsJob configured, but no StatisticManager available");
      } else {
        statisticUpdateManager.updateStatistics(false, getUpdateFinishedCallback());
        refreshUIState();
        getInitialComponent().setDirty(true);
      }
    }
  }
 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);
         UserDeletionManager.getInstance().setIdentityAsActiv(foundIdentity);
         updateUserList();
       }
     } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
       TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
       if (tmse.getAction().equals(ACTION_MULTISELECT_CHOOSE)) {
         handleDeleteButtonEvent(ureq, tmse);
       }
     }
   } else if (source == deleteConfirmController) {
     if (DialogBoxUIFactory.isOkEvent(event)) {
       List<String> errors = new ArrayList<String>();
       deleteIdentities(readyToDeleteIdentities, errors);
       if (errors.isEmpty()) {
         showInfo("deleted.feedback.msg");
       } else {
         StringBuilder sb = new StringBuilder();
         for (String error : errors) {
           if (sb.length() > 0) sb.append(", ");
           sb.append(error);
         }
         showWarning("error.delete", sb.toString());
       }
       initializeContent();
     }
   }
 }
 /**
  * @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 == assessmentOverviewCtr) {
     if (event.equals(IdentityAssessmentOverviewController.EVENT_NODE_SELECTED)) {
       AssessableCourseNode courseNode = assessmentOverviewCtr.getSelectedCourseNode();
       doEditNodeAssessment(ureq, courseNode);
     }
   } else if (source == assessmentEditCtr) {
     if (event.equals(Event.CANCELLED_EVENT)) {
       doIdentityAssessmentOverview(ureq, false);
     } else if (event.equals(Event.CHANGED_EVENT)) {
       doIdentityAssessmentOverview(ureq, true);
       fireEvent(ureq, Event.CHANGED_EVENT);
     }
   }
 }
Example #6
0
 /**
  * @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;
       LockEntry lockToRelease = locksTableModel.getObject(te.getRowId());
       dialogController =
           activateYesNoDialog(ureq, null, translate("lock.release.sure"), dialogController);
       dialogController.setUserObject(lockToRelease);
     }
   } else if (source == dialogController) {
     if (DialogBoxUIFactory.isYesEvent(event)) {
       LockEntry lockToRelease = (LockEntry) dialogController.getUserObject();
       MultiUserEvent mue = new LockRemovedEvent(lockToRelease);
       OLATResourceable lockEntryOres =
           OresHelper.createOLATResourceableInstance(LockEntry.class, 0l);
       CoordinatorManager.getInstance()
           .getCoordinator()
           .getEventBus()
           .fireEventToListenersOf(mue, lockEntryOres);
       CoordinatorManager.getInstance()
           .getCoordinator()
           .getLocker()
           .releaseLockEntry(lockToRelease);
       lockToRelease = null;
       resetTableModel();
     }
   }
 }
Example #7
0
 @Override
 public void event(Event event) {
   if (type == AssessmentInstance.QMD_ENTRY_TYPE_ASSESS) {
     if (event.getCommand().startsWith("ChatWindow")) {
       checkChats(null);
     }
   }
 }
 @Override
 protected void event(UserRequest ureq, Component source, Event event) {
   if (source == menuTree) {
     if (event.getCommand().equals(MenuTree.COMMAND_TREENODE_CLICKED)) {
       TreeNode selTreeNode = menuTree.getSelectedNode();
       String cmd = (String) selTreeNode.getUserObject();
       selectMenuItem(ureq, cmd);
     }
   }
 }
 @Override
 protected void event(UserRequest ureq, Controller source, Event event) {
   if (source == calloutCtrl
       && event.equals(CloseableCalloutWindowController.CLOSE_WINDOW_EVENT)) {
     removeAsListenerAndDispose(calloutCtrl);
     calloutCtrl = null;
   } else if (source == textEditCtrl && event == Event.DONE_EVENT) {
     // close callout, refresh artefact-details
     calloutCtrl.deactivate();
     removeAsListenerAndDispose(calloutCtrl);
     init(ureq);
   }
 }
  /**
   * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
   *     org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
   */
  @Override
  public void event(UserRequest ureq, Component source, Event event) {
    if (event.getCommand().equals("geometry")) {
      String p = ureq.getHttpReq().getParameter("p");
      if (p != null) {
        if (allGeometry.matcher(p).matches()) {
          Matcher m = parseGeometry.matcher(p);

          if (m.find()) offsetX = Integer.parseInt(m.group());
          if (m.find()) offsetY = Integer.parseInt(m.group());
          if (m.find()) width = Integer.parseInt(m.group());
          if (m.find()) height = Integer.parseInt(m.group());

          boolean dirt = wrapper.isDirty();
          wrapper.contextPut("width", width);
          wrapper.contextPut("height", height);
          wrapper.contextPut("offsetX", offsetX);
          wrapper.contextPut("offsetY", offsetY);
          wrapper.setDirty(dirt);
        } else if (posGeometry.matcher(p).matches()) {
          Matcher m = parseGeometry.matcher(p);

          if (m.find()) offsetX = Integer.parseInt(m.group());
          if (m.find()) offsetY = Integer.parseInt(m.group());

          boolean dirt = wrapper.isDirty();
          wrapper.contextPut("offsetX", offsetX);
          wrapper.contextPut("offsetY", offsetY);
          wrapper.setDirty(dirt);
        }
      }
    } else if (source == wrapper) {
      if (event.getCommand().equals("close")) {
        fireEvent(ureq, Event.DONE_EVENT);
      }
    }
  }
 /**
  * @see
  *     org.olat.core.gui.control.ControllerEventListener#dispatchEvent(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) {
   super.event(ureq, source, event);
   if (source == tableCtr) {
     if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
       TableEvent te = (TableEvent) event;
       String actionid = te.getActionId();
       if (actionid.equals(CMD_LAUNCH)) {
         int rowid = te.getRowId();
         Subscriber sub = notificationListModel.getSubscriberAt(rowid);
         if (actionid.equals(CMD_LAUNCH)) {
           NotificationUIFactory.launchSubscriptionResource(ureq, getWindowControl(), sub);
         }
       }
     }
   }
 }
 @Override
 protected void event(UserRequest ureq, Controller source, Event event) {
   if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
     TableMultiSelectEvent multiselectionEvent = (TableMultiSelectEvent) event;
     if (multiselectionEvent.getAction().equals(ACTION_MULTISELECT_CHOOSE)) {
       // sortedItems = tableDataModel.getObjects(multiselectionEvent.getSelection());
       sortedItems =
           tableController.getSelectedSortedObjects(
               multiselectionEvent.getSelection(), tableDataModel);
       if (sortedItems.size() == 0) {
         showWarning("portlet.sorting.manual.empty_sel");
       } else {
         fireEvent(ureq, event);
       }
     } else if (multiselectionEvent.getAction().equals(ACTION_MULTISELECT_CANCEL)) {
       fireEvent(ureq, Event.CANCELLED_EVENT);
     }
   }
 }
  /** Event-handling from controllers */
  @Override
  protected void event(final UserRequest ureq, final Controller source, final Event event) {
    if (source == cmc) {
      if (event.equals(CloseableModalController.CLOSE_MODAL_EVENT)) {
        removeAsListenerAndDispose(cmc);
        cmc = null;
        removeAsListenerAndDispose(uploadCtr);
        uploadCtr = null;
      }
    } else if (source == uploadCtr) {
      if (event instanceof NewCPPageEvent) {
        // TODO:GW Is it necessary to set component dirty?
        // getInitialComponent().setDirty(true);
        fireEvent(ureq, event);
      }
      // Dispose the cmc and the podcastFormCtr.
      cmc.deactivate();
      removeAsListenerAndDispose(cmc);
      cmc = null;
      removeAsListenerAndDispose(uploadCtr);
      uploadCtr = null;
    } else if (source == treeCtr) {
      // event from extJSTree (TreeController)
      if (event instanceof MoveTreeNodeEvent) {
        /** move * */
        final MoveTreeNodeEvent moveEvent = (MoveTreeNodeEvent) event;
        final String selectedNodeID = treeModel.getIdentifierForNodeID(moveEvent.getNodeId());

        currentPage = new CPPage(selectedNodeID, cp);

        final MoveTreeNodeEvent newmoveEvent =
            new MoveTreeNodeEvent(
                treeModel.getIdentifierForNodeID(moveEvent.getNodeId()),
                treeModel.getIdentifierForNodeID(moveEvent.getOldParentNodeId()),
                treeModel.getIdentifierForNodeID(moveEvent.getNewParentNodeId()),
                moveEvent.getPosition());

        final boolean success = movePage(newmoveEvent);
        // setResult is important. If sucess is not true, the ajax tree will
        // popup a dialog with error-msg
        moveEvent.setResult(success, "Error", "Error while moving node");

      } else if (event instanceof TreeNodeClickedEvent) {
        /** click * */
        TreeNodeClickedEvent clickedEvent = (TreeNodeClickedEvent) event;
        final String selectedNodeID = treeModel.getIdentifierForNodeID(clickedEvent.getNodeId());

        currentPage = new CPPage(selectedNodeID, cp);

        clickedEvent = new TreeNodeClickedEvent(currentPage.getIdentifier());
        fireEvent(ureq, clickedEvent);
      } else if (event instanceof TreeNodeModifiedEvent) {
        /** a node (name) has been modified * */
        fireEvent(ureq, event);
      }
    } else if (source == dialogCtr) {
      // event from dialog (really-delete-dialog)
      if (event != Event.CANCELLED_EVENT) {
        final int position = DialogBoxUIFactory.getButtonPos(event);

        // 0 = delete with resource
        // 1 = delete without resource
        // 2 = cancel
        if (position == 0 || position == 1) {
          boolean deleteResource = false;
          if (position == 0) {
            // Delete element including files
            deleteResource = true;
          }
          final String parentIdentifier = getParentIdentifier();

          // finally delete the page
          deletePage(currentPage.getIdentifier(), deleteResource);

          if (parentIdentifier != null) {
            contentCtr.displayPage(ureq, parentIdentifier);
          }
        } else {
          // Cancel dialog and close window.
        }
      }
    }
  }
  @Override
  public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableListParticipants) {
      if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
        TableEvent tableEvent = (TableEvent) event;
        // open window for choosen date to manage the enrolled users or manually add
        if (tableEvent.getActionId().equals(DENListTableDataModel.CHANGE_ACTION)) {
          selectedEvent = (KalendarEvent) listTableData.getObject(tableEvent.getRowId());
          List<Identity> participants = denManager.getEventParticipants(selectedEvent);
          participantsTableData = new DENParticipantsTableDataModel(participants);

          removeAsListenerAndDispose(tableManageParticipants);
          tableManageParticipants =
              denManager.createParticipantsTable(
                  ureq, getWindowControl(), getTranslator(), participantsTableData);
          listenTo(tableManageParticipants);

          removeAsListenerAndDispose(formManageParticipants);
          formManageParticipants = new DENManageParticipantsForm(ureq, getWindowControl());
          listenTo(formManageParticipants);

          participantsVC = createVelocityContainer("participants");
          SimpleText dateTitle =
              new SimpleText(
                  "dateTitle",
                  translate("dates.table.subject") + ": " + selectedEvent.getSubject());
          DateFormat df = new SimpleDateFormat();
          SimpleText dateTimeframe =
              new SimpleText(
                  "dateTimeframe",
                  translate("dates.table.date")
                      + ": "
                      + df.format(selectedEvent.getBegin())
                      + " - "
                      + df.format(selectedEvent.getEnd()));
          participantsVC.put("dateTitle", dateTitle);
          participantsVC.put("dateTimeframe", dateTimeframe);
          participantsVC.put("participantsTable", tableManageParticipants.getInitialComponent());
          participantsVC.put("addParticipants", formManageParticipants.getInitialComponent());

          removeAsListenerAndDispose(manageParticipantsModalCntrl);
          manageParticipantsModalCntrl =
              new CloseableModalController(
                  getWindowControl(),
                  "close",
                  participantsVC,
                  true,
                  translate("dates.table.participant.manage"));
          listenTo(manageParticipantsModalCntrl);

          manageParticipantsModalCntrl.activate();
        }
      } else {
        TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
        BitSet selection = tmse.getSelection();
        // delete all users from the selected dates
        if (tmse.getAction().equals(DENListTableDataModel.DELETE_ACTION)
            && selection.cardinality() > 0) {
          removed = denManager.getSelectedEventParticipants(dateList, selection);
          dateList =
              denManager.deleteParticipants(
                  ores, courseNode, denManager.getSelectedEventIDs(dateList, selection));
          listTableData.setObjects(dateList);
          // send notification mail
          createRemovedNotificationMail(ureq, dateList.get(0).getSubject());
        } else if (tmse.getAction().equals(DENListTableDataModel.MAIL_ACTION)
            && selection.cardinality() > 0) {
          // send email to all users from the selected dates
          List<Identity> participants =
              denManager.getSelectedEventParticipants(dateList, selection);
          createParticipantsMail(ureq, participants);
        } else if (selection.cardinality() == 0) {
          showWarning("participants.message.empty");
        }
      }
    } else if (source == formManageParticipants
        && event == DENManageParticipantsForm.ADD_PARTICIPANTS) {
      // open user search controller to manually add users in date
      removeAsListenerAndDispose(userSearchCntrl);
      userSearchCntrl = new UserSearchController(ureq, getWindowControl(), true, true);
      listenTo(userSearchCntrl);

      removeAsListenerAndDispose(userSearchCMC);
      userSearchCMC =
          new CloseableModalController(
              getWindowControl(), "close", userSearchCntrl.getInitialComponent());
      listenTo(userSearchCMC);

      userSearchCMC.activate();
    } else if (source == userSearchCntrl) {
      if (event == Event.CANCELLED_EVENT) {
        userSearchCMC.deactivate();
      } else {
        List<Identity> toAdd = null;
        added = new ArrayList<Identity>();
        if (event instanceof SingleIdentityChosenEvent) {
          SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
          Identity choosenIdentity = singleEvent.getChosenIdentity();
          toAdd = new ArrayList<Identity>();
          toAdd.add(choosenIdentity);
        } else if (event instanceof MultiIdentityChosenEvent) {
          MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
          toAdd = multiEvent.getChosenIdentities();
        }
        boolean showMessage = false;
        if (toAdd != null && toAdd.size() > 0) {
          for (Identity identity : toAdd) {
            status = denManager.doEnroll(identity, selectedEvent, ores, courseNode, true);
            if (!status.isEnrolled()
                && status.getErrorMessage().equals(DENStatus.ERROR_ALREADY_ENROLLED))
              showMessage = true;
            else added.add(identity);
          }
          if (showMessage) showWarning("enrollment.warning.manual");
          refreshTables();
        }
        userSearchCMC.deactivate();
        if (added.size() > 0) {
          // write notification mail
          createAddedNotificationMail(ureq, dateList.get(0).getSubject());
        }
      }

    } else if (source == tableManageParticipants) {
      if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
        TableEvent tableEvent = (TableEvent) event;
        // delete single user from event
        if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.REMOVE_ACTION)) {
          Identity identity = participantsTableData.getEntryAt(tableEvent.getRowId());
          status = denManager.cancelEnroll(identity, selectedEvent, ores, courseNode);
          if (!status.isCancelled()) showError();
          // send notification mail
          else {
            removed.clear();
            removed.add(identity);
            createRemovedNotificationMail(ureq, dateList.get(0).getSubject());
          }
          refreshTables();
          // write email to single user
        } else if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.MAIL_ACTION)) {
          List<Identity> participants = new ArrayList<Identity>();
          participants.add(participantsTableData.getEntryAt(tableEvent.getRowId()));
          createParticipantsMail(ureq, participants);
        }
      }
    } else if (source == addedNotificationCtr && event == Event.DONE_EVENT) {
      if (addedNotificationCtr.getMailTemplate() != null) {
        Identity sender = ureq.getIdentity();
        MailerResult result = new MailerResult();
        String metaId = UUID.randomUUID().toString().replace("-", "");
        MailContext context =
            new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailBundle[] bundles =
            mailManager.makeMailBundles(
                context, added, addedNotificationCtr.getMailTemplate(), sender, metaId, result);
        result.append(mailManager.sendMessage(bundles));
        if (addedNotificationCtr.getMailTemplate().getCpfrom()) {
          MailBundle ccBundles =
              mailManager.makeMailBundle(
                  context, sender, addedNotificationCtr.getMailTemplate(), sender, metaId, result);
          result.append(mailManager.sendMessage(ccBundles));
        }
        MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getLocale());
      }
      notificationCmc.deactivate();
      added.clear();
    } else if (source == removedNotificationCtr && event == Event.DONE_EVENT) {
      if (removedNotificationCtr.getMailTemplate() != null) {

        // fxdiff VCRP-16: intern mail system
        Identity sender = ureq.getIdentity();
        MailerResult result = new MailerResult();
        String metaId = UUID.randomUUID().toString().replace("-", "");
        MailContext context =
            new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailBundle[] bundles =
            mailManager.makeMailBundles(
                context, added, addedNotificationCtr.getMailTemplate(), sender, metaId, result);
        result.append(mailManager.sendMessage(bundles));
        if (addedNotificationCtr.getMailTemplate().getCpfrom()) {
          MailBundle ccBundle =
              mailManager.makeMailBundle(
                  context, sender, addedNotificationCtr.getMailTemplate(), sender, metaId, result);
          result.append(mailManager.sendMessage(ccBundle));
        }
        MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getLocale());
      }
      notificationCmc.deactivate();
      removed.clear();
    } else if (source == contactCtr) {
      notificationCmc.deactivate();
    }
  }
  /**
   * @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(final UserRequest ureq, final Controller source, final Event event) {
    final String cmd = event.getCommand();
    if (source == searchCtr) {
      if (cmd.equals(RepositoryTableModel.TABLE_ACTION_SELECT_ENTRY)) {
        // user selected entry to get a preview
        selectedRepositoryEntry = searchCtr.getSelectedEntry();
        final RepositoryEntry repositoryEntry = searchCtr.getSelectedEntry();
        final RepositoryHandler typeToLaunch =
            RepositoryHandlerFactory.getInstance().getRepositoryHandler(repositoryEntry);
        if (typeToLaunch == null) {
          final StringBuilder sb = new StringBuilder(translate("error.launch"));
          sb.append(": No launcher for repository entry: ");
          sb.append(repositoryEntry.getKey());
          throw new OLATRuntimeException(RepositoryDetailsController.class, sb.toString(), null);
        }
        // do skip the increment launch counter, this is only a preview!
        final OLATResourceable ores = repositoryEntry.getOlatResource();

        removeAsListenerAndDispose(previewCtr);
        previewCtr = typeToLaunch.createLaunchController(ores, null, ureq, getWindowControl());
        listenTo(previewCtr);

        removeAsListenerAndDispose(previewModalCtr);
        previewModalCtr =
            new CloseableModalController(
                getWindowControl(),
                translate("referencableSearch.preview.close"),
                previewCtr.getInitialComponent());
        listenTo(previewModalCtr);

        previewModalCtr.activate();

      } else if (cmd.equals(RepositoryTableModel.TABLE_ACTION_SELECT_LINK)) {
        // done, user selected a repo entry
        selectedRepositoryEntry = searchCtr.getSelectedEntry();
        fireEvent(ureq, EVENT_REPOSITORY_ENTRY_SELECTED);
      }
      initLinks();
    } else if (source == addController) {
      if (event.equals(Event.DONE_EVENT)) {
        cmc.deactivate();

        selectedRepositoryEntry = addController.getAddedEntry();
        fireEvent(ureq, EVENT_REPOSITORY_ENTRY_SELECTED);
        // info message
        final String message =
            translate(
                "message.entry.selected",
                new String[] {
                  addController.getAddedEntry().getDisplayname(),
                  addController.getAddedEntry().getResourcename()
                });
        getWindowControl().setInfo(message);
      } else if (event.equals(Event.CANCELLED_EVENT)) {
        cmc.deactivate();

      } else if (event.equals(Event.FAILED_EVENT)) {
        showError("add.failed");
      }
    }
  }
  /**
   * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
   *     org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
   */
  @Override
  public void event(UserRequest ureq, Component source, Event event) {
    if (source == onCommand) {
      // toggle on
      Preferences prefs = ureq.getUserSession().getGuiPreferences();
      prefs.put(CourseGlossaryToolLinkController.class, guiPrefsKey, Boolean.TRUE);
      prefs.save();
      // update gui
      mainVC.remove(onCommand);
      offCommand = LinkFactory.createLink("command.glossary.off", mainVC, this);
      offCommand.setTitle("command.glossary.off.alt");
      offCommand.setCustomEnabledLinkCSS("b_toolbox_toggle");
      // notify textmarker controller
      glossMarkupItmCtr.setTextMarkingEnabled(true);
      fireEvent(ureq, new Event("glossaryOn"));

    } else if (source == offCommand) {
      // toggle off
      Preferences prefs = ureq.getUserSession().getGuiPreferences();
      prefs.put(CourseGlossaryToolLinkController.class, guiPrefsKey, Boolean.FALSE);
      prefs.save();
      // update gui
      mainVC.remove(offCommand);
      onCommand = LinkFactory.createLink("command.glossary.on", mainVC, this);
      onCommand.setTitle("command.glossary.on.alt");
      onCommand.setCustomEnabledLinkCSS("b_toolbox_toggle");
      // notify textmarker controller
      glossMarkupItmCtr.setTextMarkingEnabled(false);
      fireEvent(ureq, new Event("glossaryOff"));
    } else if (source == mainVC && event.getCommand().equals("command.glossary")) {
      // start glossary in window
      final CourseConfig cc = courseEnvir.getCourseConfig(); // do not cache cc, not save

      // if glossary had been opened from LR as Tab before, warn user:
      DTabs dts = Windows.getWindows(ureq).getWindow(ureq).getDTabs();
      RepositoryEntry repoEntry =
          RepositoryManager.getInstance()
              .lookupRepositoryEntryBySoftkey(cc.getGlossarySoftKey(), false);
      DTab dt = dts.getDTab(repoEntry.getOlatResource());
      if (dt != null) {
        List<ContextEntry> entries =
            BusinessControlFactory.getInstance()
                .createCEListFromResourceType(allowGlossaryEditing ? "true" : "false");
        dts.activate(ureq, dt, entries);
      } else {
        ControllerCreator ctrlCreator =
            new ControllerCreator() {
              public Controller createController(UserRequest lureq, WindowControl lwControl) {
                GlossaryMainController glossaryController =
                    CourseGlossaryFactory.createCourseGlossaryMainRunController(
                        lwControl, lureq, cc, allowGlossaryEditing);
                listenTo(glossaryController);
                if (glossaryController == null) {
                  // happens in the unlikely event of a user who is in a course and
                  // now
                  // tries to access the glossary
                  String text = translate("error.noglossary");
                  return MessageUIFactory.createInfoMessage(lureq, lwControl, null, text);
                } else {
                  // use a one-column main layout
                  LayoutMain3ColsController layoutCtr =
                      new LayoutMain3ColsController(
                          lureq,
                          lwControl,
                          null,
                          null,
                          glossaryController.getInitialComponent(),
                          null);
                  // dispose glossary on layout dispose
                  layoutCtr.addDisposableChildController(glossaryController);
                  return layoutCtr;
                }
              }
            };

        ControllerCreator layoutCtrlr =
            BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, ctrlCreator);
        // open in new browser window
        openInNewBrowserWindow(ureq, layoutCtrlr);
        return; // immediate return after opening new browser window!
      }
    }
  }