Package org.olat.repository

Source Code of org.olat.repository.RepositoyUIFactory

/**
* 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.repository;

import org.olat.core.commons.fullWebApp.LayoutMain3ColsController;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.generic.layout.MainLayoutController;
import org.olat.core.gui.control.generic.messages.MessageUIFactory;
import org.olat.core.gui.translator.Translator;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.context.BusinessControlFactory;
import org.olat.core.id.context.ContextEntry;
import org.olat.core.logging.AssertException;
import org.olat.core.util.Util;
import org.olat.repository.handlers.RepositoryHandler;
import org.olat.repository.handlers.RepositoryHandlerFactory;

/**
* Description:<br>
* TODO: patrickb Class Description for RepositoyUIFactory
*
* <P>
* Initial Date:  03.12.2007 <br>
* @author patrickb
*/
public class RepositoyUIFactory {

  /**
   * Create a launch sontroller used to launch the given repo entry.
   * @param re
   * @param initialViewIdentifier if null the default view will be started, otherwise a controllerfactory type dependant view will be activated (subscription subtype)
   * @param ureq
   * @param wControl
   * @return null if no entry was found, a no access message controller if not allowed to launch or the launch
   * controller if successful.
   */
  public static MainLayoutController createLaunchController(RepositoryEntry re, String initialViewIdentifier, UserRequest ureq, WindowControl wControl) {
    if (re == null) return null;
    RepositoryManager rm = RepositoryManager.getInstance();
    if (!rm.isAllowedToLaunch(ureq, re)) {
      Translator trans = Util.createPackageTranslator(RepositoyUIFactory.class, ureq.getLocale());
      String text = trans.translate("launch.noaccess");
      Controller c = MessageUIFactory.createInfoMessage(ureq, wControl, null, text);
     
      // use on column layout
      LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, wControl, null, null, c.getInitialComponent(), null);
      layoutCtr.addDisposableChildController(c); // dispose content on layout dispose
      return layoutCtr;
    }
    rm.incrementLaunchCounter(re);
    RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
 
   
    // build up the context path
    OLATResourceable businessOres = re;
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(businessOres);
    WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl)
 
    MainLayoutController ctrl = handler.getLaunchController(re.getOlatResource(), initialViewIdentifier, ureq, bwControl);
    if (ctrl == null) throw new AssertException("could not create controller for repositoryEntry "+re);
    if (ctrl instanceof MainLayoutController) {
      return ctrl;     
    } else {
      // add layout wrapper
      LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, wControl, null, null, ctrl.getInitialComponent(), null);
      layoutCtr.addDisposableChildController(ctrl); // dispose content on layout dispose
      return layoutCtr;
    }
  }

}
TOP

Related Classes of org.olat.repository.RepositoyUIFactory

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.