Package org.olat.test

Source Code of org.olat.test.GUIDemoMainController

/**
* 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) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.test;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.olat.basesecurity.ManagerFactory;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.tree.GenericTreeNode;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.ControllerEventListener;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.generic.ajax.autocompletion.AutoCompleterController;
import org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent;
import org.olat.core.gui.control.generic.ajax.autocompletion.ListProvider;
import org.olat.core.gui.control.generic.ajax.autocompletion.ListReceiver;
import org.olat.core.gui.control.generic.layout.GenericMainController;
import org.olat.core.id.Identity;
import org.olat.core.id.User;
import org.olat.core.id.UserConstants;

/**
* Description:<br>
* GUIDemoMainController shows GuiDemo-Controllers configured in olat_extensions.xml
*
* <P>
* Initial Date:  11.09.2007 <br>
* @author Lavinia Dumitrescu
* @author refactored to use GenericMainController by Roman Haag, frentix GmbH
*/
public class GUIDemoMainController extends GenericMainController {
   
  public GUIDemoMainController(UserRequest ureq, WindowControl wControl) {
    super(ureq,wControl);

    GenericTreeNode gtn = new GenericTreeNode();
    gtn.setTitle("Autocompletion");
    gtn.setUserObject("guidemo-autocompletion");
    gtn.setAltText("Input field autocompletion");
    addChildNodeToAppend(gtn);
   
    init(ureq);
  }
 

  @Override
  protected Controller handleOwnMenuTreeEvent(Object uobject, final UserRequest ureq) {
    if (uobject.equals("guidemo-autocompletion")) {
      // for a demo of autocompletion, do a user search
      ListProvider provider = new ListProvider() {
        public void getResult(String searchValue, ListReceiver receiver) {
          Map<String, String> userProperties = new HashMap<String, String>();
          userProperties.put(UserConstants.FIRSTNAME, searchValue);
          userProperties.put(UserConstants.LASTNAME, searchValue);
          userProperties.put(UserConstants.EMAIL, searchValue);
          // FIXME:fg:cg: 13.03.08: User-Properties problem with undefine properties;
//          userProperties.put(UserConstants.INSTITUTIONALEMAIL, searchValue);
//          userProperties.put(UserConstants.INSTITUTIONALUSERIDENTIFIER, searchValue);
          List res = ManagerFactory.getManager().getVisibleIdentitiesByPowerSearch(searchValue, userProperties, false, null, null, null,
              null, null);
          for (Iterator it_res = res.iterator(); it_res.hasNext();) {
            Identity ident = (Identity) it_res.next();
            User u = ident.getUser();
            String login = ident.getName();
            //String first = u.getProperty(UserConstants.FIRSTNAME, ureq.getLocale());
            //String last = u.getProperty(UserConstants.LASTNAME, ureq.getLocale());
            receiver.addEntry(login, login +" "+login);
          }         
        }};
       
      Controller c = new AutoCompleterController(ureq, getWindowControl(), provider, "-no user found-", false);
     
      // for demo only, normally use in parent controller
      c.addControllerListener(new ControllerEventListener() {
        public void dispatchEvent(UserRequest ureq, Controller source, Event event) {
          EntriesChosenEvent ece = (EntriesChosenEvent) event;
          String sel = ece.getEntries().toString();
          getWindowControl().setInfo("selected entrie(s):"+sel);
         
        }});
      return c;
    }
    return null;
 
 
}
TOP

Related Classes of org.olat.test.GUIDemoMainController

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.