Package org.olat.modules.glossary

Source Code of org.olat.modules.glossary.GlossaryMorphServiceSettingsController

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) 1999-2008 at frentix GmbH, Switzerland, http://www.frentix.com
* <p>
*/
package org.olat.modules.glossary;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.olat.core.commons.modules.glossary.GlossaryItemManager;
import org.olat.core.commons.modules.glossary.GlossaryModule;
import org.olat.core.commons.modules.glossary.morphService.MorphologicalService;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.FormItemContainer;
import org.olat.core.gui.components.form.flexible.FormUIFactory;
import org.olat.core.gui.components.form.flexible.elements.SingleSelection;
import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
import org.olat.core.gui.components.form.flexible.impl.FormEvent;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.WindowControl;
import org.olat.resource.OLATResource;

/**
* Description:<br>
* choose a morphological Service from available ones configured in spring-config
*
* <P>
* Initial Date:  16.01.2009 <br>
* @author Roman Haag, frentix GmbH, roman.haag@frentix.com
*/
public class GlossaryMorphServiceSettingsController<FlexionServiceManager> extends FormBasicController {

  private SingleSelection selectMS;
  private OLATResource olatresource;

  public GlossaryMorphServiceSettingsController(UserRequest ureq, WindowControl control, OLATResource resource) {
    super(ureq, control);
    this.olatresource = resource;
   
    initForm(ureq);
  }

  /**
   * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formInnerEvent(org.olat.core.gui.UserRequest, org.olat.core.gui.components.form.flexible.FormItem, org.olat.core.gui.components.form.flexible.impl.FormEvent)
   */
  @Override
  protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source==selectMS){
      Properties glossProps = GlossaryItemManager.getInstance().getGlossaryConfig(
          GlossaryManager.getInstance().getGlossaryRootFolder(olatresource));
      if (!selectMS.getSelectedKey().equals(glossProps.getProperty(GlossaryItemManager.MS_KEY))){
        //change occurred
        glossProps.setProperty(GlossaryItemManager.MS_KEY, selectMS.getSelectedKey());
        GlossaryItemManager.getInstance().setGlossaryConfig(
            GlossaryManager.getInstance().getGlossaryRootFolder(olatresource), glossProps);
      }
     
    }
  } 

  @Override
  protected void formOK(UserRequest ureq) {
    // saved in innerEvent
   
  }

  @Override
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("settings.title");
    setFormDescription("settings.intro");
   
    List<MorphologicalService> morphServices = GlossaryModule.getMorphologicalServices();
    String[] msKeys = new String[morphServices.size()+1];
    String[] msValues = new String[morphServices.size()+1];
    String[] msCSS = new String[morphServices.size()+1];
    msKeys[0] = GlossaryItemManager.NO_MS_VALUE;
    msValues[0] = translate("settings.no.morph.service");
    if (morphServices!=null){
      int i=1;
      for (Iterator iterator = morphServices.iterator(); iterator.hasNext();) {
        MorphologicalService fsMgr = (MorphologicalService) iterator.next();
        msKeys[i] = fsMgr.getMorphServiceIdentifier();
        msValues[i] = fsMgr.getMorphServiceDescriptor();
        i++;
      }
    }
   
    selectMS = uifactory.addDropdownSingleselect("morph.service", formLayout, msKeys, msValues, msCSS);
    Properties glossProps = GlossaryItemManager.getInstance().getGlossaryConfig(
        GlossaryManager.getInstance().getGlossaryRootFolder(olatresource));
    String configuredKey = glossProps.getProperty(GlossaryItemManager.MS_KEY);
    if (Arrays.asList(msKeys).contains(configuredKey)){
      selectMS.select(configuredKey, true);
    }
    selectMS.addActionListener(listener, FormEvent.ONCHANGE);
   
   
  }


  @Override
  protected void doDispose() {
    // nothing   
  }
 
 

}
TOP

Related Classes of org.olat.modules.glossary.GlossaryMorphServiceSettingsController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.