Skip to content
Snippets Groups Projects
Commit aa08d659 authored by srosse's avatar srosse
Browse files

OO-1342: refactor the loading mechanism for the custom media controller with a...

OO-1342: refactor the loading mechanism for the custom media controller with a standard factory pattern
parent 2bffdd2f
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.controllers.linkchooser.CustomMediaChooserController;
import org.olat.core.commons.controllers.linkchooser.CustomMediaChooserFactory;
import org.olat.core.dispatcher.mapper.Mapper;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
......@@ -56,30 +56,28 @@ import de.bps.course.nodes.LLCourseNode;
*/
public class LLRunController extends BasicController {
private VelocityContainer runVC;
public LLRunController(UserRequest ureq, WindowControl wControl, ModuleConfiguration moduleConfig, LLCourseNode llCourseNode,
UserCourseEnvironment userCourseEnv, boolean showLinkComments) {
super(ureq, wControl);
this.runVC = this.createVelocityContainer("run");
final List<LLModel> linkList = (List<LLModel>) moduleConfig.get(LLCourseNode.CONF_LINKLIST);
this.runVC.contextPut("linkList", linkList);
this.runVC.contextPut("showLinkComments", Boolean.valueOf(showLinkComments));
VelocityContainer runVC = createVelocityContainer("run");
@SuppressWarnings("unchecked")
final List<LLModel> linkList = (List<LLModel>) moduleConfig.get(LLCourseNode.CONF_LINKLIST);
runVC.contextPut("linkList", linkList);
runVC.contextPut("showLinkComments", Boolean.valueOf(showLinkComments));
CourseEnvironment courseEnv = userCourseEnv.getCourseEnvironment();
VFSContainer courseContainer = courseEnv.getCourseFolderContainer();
Mapper customMapper = null;
if (CoreSpringFactory.containsBean(CustomMediaChooserController.class.getName())) {
CustomMediaChooserController customMediaChooserFactory = (CustomMediaChooserController) CoreSpringFactory.getBean(CustomMediaChooserController.class.getName());
customMapper = customMediaChooserFactory.getMapperInstance(courseContainer, null, null);
if (CoreSpringFactory.containsBean(CustomMediaChooserFactory.class.getName())) {
CustomMediaChooserFactory customMediaChooserFactory = (CustomMediaChooserFactory)CoreSpringFactory.getBean(CustomMediaChooserFactory.class.getName());
customMapper = customMediaChooserFactory.getMapperInstance();
}
String mapperID = courseEnv.getCourseResourceableId() + "/" + llCourseNode.getIdent();
String mapperBaseUrl = registerCacheableMapper(ureq, mapperID, new LLMapper(linkList, customMapper, courseContainer));
runVC.contextPut("mapperBaseUrl", mapperBaseUrl);
putInitialPanel(runVC);
}
......
......@@ -37,6 +37,7 @@ import org.olat.commons.calendar.model.KalendarEventLink;
import org.olat.commons.calendar.ui.components.KalendarRenderWrapper;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.controllers.linkchooser.CustomMediaChooserController;
import org.olat.core.commons.controllers.linkchooser.CustomMediaChooserFactory;
import org.olat.core.commons.controllers.linkchooser.URLChoosenEvent;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
......@@ -109,12 +110,12 @@ public class KalendarEntryDetailsController extends BasicController {
pane.addTab(translate("tab.links"), linkVC);
//custom media chooser
if (CoreSpringFactory.containsBean(CustomMediaChooserController.class.getName())) {
CustomMediaChooserController customMediaChooserFactory = (CustomMediaChooserController) CoreSpringFactory.getBean(CustomMediaChooserController.class.getName());
customMediaChooserCtr = customMediaChooserFactory.getInstance(ureq, wControl, null, null, null);
if (CoreSpringFactory.containsBean(CustomMediaChooserFactory.class.getName())) {
CustomMediaChooserFactory customMediaChooserFactory = (CustomMediaChooserFactory) CoreSpringFactory.getBean(CustomMediaChooserFactory.class.getName());
customMediaChooserCtr = customMediaChooserFactory.getInstance(ureq, wControl);
if (customMediaChooserCtr != null) {
listenTo(customMediaChooserCtr);
mediaLinksController = new MediaLinksController(ureq, wControl, kalendarEvent, customMediaChooserCtr);
mediaLinksController = new MediaLinksController(ureq, wControl, kalendarEvent, customMediaChooserFactory);
pane.addTab(customMediaChooserCtr.getTabbedPaneTitle(), mediaLinksController.getInitialComponent());
listenTo(mediaLinksController);
}
......
......@@ -31,9 +31,9 @@ import org.olat.commons.calendar.CalendarManager;
import org.olat.commons.calendar.model.KalendarEvent;
import org.olat.commons.calendar.model.KalendarEventLink;
import org.olat.core.commons.controllers.linkchooser.CustomMediaChooserController;
import org.olat.core.commons.controllers.linkchooser.CustomMediaChooserFactory;
import org.olat.core.commons.controllers.linkchooser.URLChoosenEvent;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
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.elements.FormLink;
......@@ -76,16 +76,16 @@ public class MediaLinksController extends FormBasicController {
private FormLayoutContainer linksContainer;
private CloseableModalController mediaDialogBox;
private CustomMediaChooserController mediaChooserController;
private CustomMediaChooserController customMediaChooserController;
public MediaLinksController(UserRequest ureq, WindowControl wControl, KalendarEvent kalendarEvent,
CustomMediaChooserController customMediaChooserController) {
CustomMediaChooserFactory customMediaChooserFactory) {
super(ureq, wControl, LAYOUT_VERTICAL);
setBasePackage(CalendarManager.class);
this.kalendarEvent = kalendarEvent;
this.customMediaChooserController = customMediaChooserController;
this.provider = customMediaChooserController.getClass().getSimpleName();
mediaChooserController = customMediaChooserFactory.getInstance(ureq, wControl);
listenTo(mediaChooserController);
this.provider = mediaChooserController.getClass().getSimpleName();
externalLinks = new ArrayList<LinkWrapper>();
List<KalendarEventLink> links = kalendarEvent.getKalendarEventLinks();
......@@ -204,11 +204,7 @@ public class MediaLinksController extends FormBasicController {
}
} else if (currentLink.getMediaButton().equals(source)) {
removeAsListenerAndDispose(mediaDialogBox);
removeAsListenerAndDispose(mediaChooserController);
mediaChooserController = customMediaChooserController.getInstance(ureq, getWindowControl(), null, null, "");
listenTo(mediaChooserController);
mediaDialogBox = new CloseableModalController(getWindowControl(), translate("choose"), mediaChooserController.getInitialComponent());
mediaDialogBox.activate();
listenTo(mediaDialogBox);
......@@ -216,18 +212,12 @@ public class MediaLinksController extends FormBasicController {
}
}
@Override
public void event(UserRequest ureq, Component source, Event event) {
super.event(ureq, source, event);
}
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if(source == mediaDialogBox) {
removeAsListenerAndDispose(mediaDialogBox);
removeAsListenerAndDispose(mediaChooserController);
mediaDialogBox = null;
mediaChooserController = null;
} else if(mediaChooserController == source) {
if(event instanceof URLChoosenEvent) {
URLChoosenEvent choosenEvent = (URLChoosenEvent)event;
......@@ -240,9 +230,7 @@ public class MediaLinksController extends FormBasicController {
}
mediaDialogBox.deactivate();
removeAsListenerAndDispose(mediaDialogBox);
removeAsListenerAndDispose(mediaChooserController);
mediaDialogBox = null;
mediaChooserController = null;
}
super.event(ureq, source, event);
}
......@@ -283,7 +271,7 @@ public class MediaLinksController extends FormBasicController {
//remove deleted links
for(Iterator<KalendarEventLink> it=links.iterator(); it.hasNext(); ) {
KalendarEventLink link = it.next();
if(provider.equals(link.getId()) && !usedUuids.contains(link.getId())) {
if(provider.equals(link.getProvider()) && !usedUuids.contains(link.getId())) {
it.remove();
}
}
......
......@@ -34,11 +34,8 @@ package org.olat.core.commons.controllers.linkchooser;
*
* @author Florian Gnägi, frentix GmbH, http://www.frentix.com
*/
import org.olat.core.dispatcher.mapper.Mapper;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.DefaultController;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.util.vfs.VFSContainer;
public abstract class CustomMediaChooserController extends DefaultController {
......@@ -51,28 +48,8 @@ public abstract class CustomMediaChooserController extends DefaultController {
super(wControl);
}
/**
* Factory method to create a custom media chooser controller from a (Spring)
* instance
*
* @param ureq
* @param wControl
* @param rootDir
* @param suffixes
* @param fileName
* @param userActivityLogger
* @return true if success, false if no success, e.g. because user has no
* access right to start this controller
*/
abstract public CustomMediaChooserController getInstance(UserRequest ureq, WindowControl wControl, VFSContainer rootDir,
String[] suffixes, String fileName);
//fxdiff
abstract public Mapper getMapperInstance(VFSContainer rootDir, String[] suffixes, String fileName);
/**
* @return Title for media chooser tabbed pane
*/
abstract public String getTabbedPaneTitle();
public abstract String getTabbedPaneTitle();
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <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 the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <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>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.commons.controllers.linkchooser;
import org.olat.core.dispatcher.mapper.Mapper;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.WindowControl;
/**
*
* Initial date: 04.12.2014<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public interface CustomMediaChooserFactory {
public Mapper getMapperInstance();
public CustomMediaChooserController getInstance(UserRequest ureq, WindowControl wControl);
}
......@@ -90,9 +90,9 @@ public class LinkChooserController extends BasicController {
// try to add custom media chooser from spring configuration.
// This one will be added as additional tab.
if (CoreSpringFactory.containsBean(CustomMediaChooserController.class.getName())) {
CustomMediaChooserController customMediaChooserFactory = (CustomMediaChooserController) CoreSpringFactory.getBean(CustomMediaChooserController.class.getName());
customMediaChooserCtr = customMediaChooserFactory.getInstance(ureq, wControl, rootDir, suffixes, fileName);
if (CoreSpringFactory.containsBean(CustomMediaChooserFactory.class.getName())) {
CustomMediaChooserFactory customMediaChooserFactory = (CustomMediaChooserFactory) CoreSpringFactory.getBean(CustomMediaChooserFactory.class.getName());
customMediaChooserCtr = customMediaChooserFactory.getInstance(ureq, wControl);
if (customMediaChooserCtr != null) {
listenTo(customMediaChooserCtr);
linkChooserTabbedPane.addTab(customMediaChooserCtr.getTabbedPaneTitle(), customMediaChooserCtr.getInitialComponent());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment