예제 #1
0
 private void savePreferences(UserRequest ureq, String val) {
   // check if checkbox (dont askagain) is checked
   if (askagainCheckbox.isSelected(0)) {
     Preferences prefs = ureq.getUserSession().getGuiPreferences();
     prefs.put(WindowManager.class, "resume-prefs", val);
     prefs.save();
   }
 }
  /**
   * @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!
      }
    }
  }