diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/BasicFormFragment.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/BasicFormFragment.java deleted file mode 100644 index 1c8936b3137ca94b674ca75ce331ee9acd8f2b5d..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/BasicFormFragment.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * <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.gui.components.form.flexible.impl; - -import org.olat.core.CoreSpringFactory; -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.components.form.flexible.FormItemContainer; -import org.olat.core.gui.components.form.flexible.FormUIFactory; -import org.olat.core.gui.control.Controller; -import org.olat.modules.IModuleConfiguration; - -/** - * Base class for implementing {@link IFormFragment} - * - * <p>Initial date: May 6, 2016 - * @author lmihalkovic, http://www.frentix.com - */ -public abstract class BasicFormFragment implements IFormFragment { - - protected IFormFragmentHost host; - protected IFormFragmentContainer container; - - public BasicFormFragment() { - CoreSpringFactory.autowireObject(this); - } - - @Override - public final void initFormFragment(UserRequest ureq, IFormFragmentContainer container, Controller listener, IModuleConfiguration config) { - FormItemContainer formLayout = container.formItemsContainer(); - - this.container = container; - this.host = container.getFragmentHostInterface(); - - initFormFragment(formLayout, listener, ureq, config); - } - - protected abstract void initFormFragment(FormItemContainer formLayout, Controller listener, UserRequest ureq, IModuleConfiguration config); - - protected FormUIFactory uifactory() { - return container.getFragmentHostInterface().getUIFactory(); - } - - @Override - public void readConfiguration(UserRequest ureq, IModuleConfiguration moduleConfiguration) { - // do nothing by default - } - -} diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormBasicController.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormBasicController.java index f12ed9fa050eaffb54e457b8388f20928ed95a99..a5a7223ab0cade0182eb4bf6168b78e69e944120 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormBasicController.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormBasicController.java @@ -25,11 +25,6 @@ */ package org.olat.core.gui.components.form.flexible.impl; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; - import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.form.flexible.FormItem; @@ -72,7 +67,7 @@ import org.olat.core.logging.activity.ThreadLocalUserActivityLoggerInstaller; * * @author patrickb */ -public abstract class FormBasicController extends BasicController implements IFormFragmentContainer { +public abstract class FormBasicController extends BasicController { public static final int LAYOUT_DEFAULT = 0; @@ -91,8 +86,6 @@ public abstract class FormBasicController extends BasicController implements IFo protected StackedPanel initialPanel; - private List<FragmentRef> fragments; - protected final FormUIFactory uifactory = FormUIFactory.getInstance(); public FormBasicController(UserRequest ureq, WindowControl wControl) { @@ -367,7 +360,6 @@ public abstract class FormBasicController extends BasicController implements IFo @Override protected void event(UserRequest ureq,Controller source, Event event) { - routeEventToFragments(ureq, source, event); super.event(ureq, source, event); } @@ -378,7 +370,6 @@ public abstract class FormBasicController extends BasicController implements IFo */ @Override public void event(UserRequest ureq, Component source, Event event) { - routeEventToFragments(ureq, source, event); if (source == mainForm.getInitialComponent()) { // general form events if (event == org.olat.core.gui.components.form.Form.EVNT_VALIDATION_OK) { @@ -649,126 +640,11 @@ public abstract class FormBasicController extends BasicController implements IFo disposableFormItem.dispose(); } } - - forEachFragment(fragment -> { - // do nothing for now - }); } }, getUserActivityLogger()); } - // ------------------------------------------------------------------------ - // IFormFragmentContainer implementation - - /** - * A lifecycle method used to signal the controller that it should read the contents - * of its configuration and apply it to its view. The idea is that the structure of a - * form can be created separately from assigning contents to its fields. - * <p>This is particularly useful when dealing with fragments which know how to - * load/store data from a given configuration themselves. - * @param ureq - */ - public void readFormData(UserRequest ureq) { - // do nothing by default - } - - /** - * A lifecycle used to signal the form controller that it should visit the view's - * content and save all relevant data into its current configuration. - * <p>This is particularly useful when dealing with fragments which know how to - * load/store data from a given configuration themselves. - * @param ureq - */ - public void storeFormData(UserRequest ureq) { - // do nothing by default - } - - @Override - public IFormFragmentHost getFragmentHostInterface() { - // this is to document the missing method implementation in a subclass - throw new IllegalStateException("In order to host from fragments the controller must override getFragmentHostInterface(): " + this.getClass().getSimpleName() ); - } - - private static class FragmentRef extends WeakReference<IFormFragment>{ - public FragmentRef(IFormFragment referent) { - super(referent); - } - } - - @Override public void setNeedsLayout() { flc.setDirty(true); } - - @Override - public void registerFormFragment(IFormFragment fragment) { - if(fragments == null) { - fragments = new ArrayList<>(5); - } - fragments.add(new FragmentRef(fragment)); - } - - @Override - public FormItemContainer formItemsContainer() { - return flc; - } - - // Helpers - @Override - protected void fireEvent(UserRequest ureq, Event event) { - super.fireEvent(ureq, event); - } - - // Redefinition of a the super method to provide access with the same - // package (this is required for the Form Fragments) - @Override - protected Controller listenTo(Controller controller) { - return super.listenTo(controller); - } - - @Override - public void forEachFragment(Consumer<IFormFragment> handler) { - if(fragments == null) return; - - fragments.stream() - .filter(ref -> ref.get() != null) - .forEach(ref -> { - IFormFragment frag = ref.get(); - if (frag != null) { - handler.accept(frag); - } - }); - } - - protected boolean routeEventToFragments(UserRequest ureq, Component source, Event event) { - if(fragments == null) return false; - - // implement shortcut?! - Boolean processed = - fragments.stream() - .reduce(Boolean.FALSE - , (t, u) -> { - IFormFragment frag = u.get(); - return frag == null ? Boolean.FALSE : frag.processEvent(ureq, source, event); - }, (t, u) -> t & u) - ; - return processed; - } - - - protected boolean routeEventToFragments(UserRequest ureq, Controller source, Event event) { - if(fragments == null) return false; - - // implement shortcut?! - Boolean processed = - fragments.stream() - .reduce(Boolean.FALSE - , (t, u) -> { - IFormFragment frag = u.get(); - return frag == null ? Boolean.FALSE : frag.processEvent(ureq, source, event); - }, (t, u) -> t & u) - ; - return processed; - } - } \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragment.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragment.java deleted file mode 100644 index 647b54c717051cd95fe6f4b60f2b8e9fd562e029..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragment.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * <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.gui.components.form.flexible.impl; - -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.control.Controller; -import org.olat.core.gui.control.Disposable; -import org.olat.core.gui.control.Event; -import org.olat.modules.IModuleConfiguration; - -/** - * A form fragment is a simple abstraction that allows composing {@code Form} instances from - * reusable groups of fields. This is a lighter weight level of reuse than to embed entire - * forms inside containing forms. In the case of fragments, there is a single controller - * managing multiple fragments. - * - * <p>Fragments are hosted by a {@link IFormFragmentContainer}. - * - * <p>Initial date: May 6, 2016<br> - * @author lmihalkovic, http://www.frentix.com - */ -public interface IFormFragment extends Disposable { - - // this is here for compatibility to help migrate chunks of existing code into fragments - default void initForm(IFormFragmentContainer container, Controller _listener, UserRequest ureq, IModuleConfiguration config) { - this.initFormFragment(ureq, container, _listener, config); - this.validateFormLogic(ureq); - } - - /** - * This method must be implemented by fragments however it is not recommended that form - * fragment hosts call it directly. Instead fragment hosts should directly call {@code initForm} - * which will ensure that all initialization is performed in a single step - * - * @param ureq - * @param formLayout - * @param listener - */ - void initFormFragment(UserRequest ureq, IFormFragmentContainer container, Controller listener, IModuleConfiguration config); - - /** - * @see FormBasicController#validateFormLogic(UserRequest) - * @return - */ - boolean validateFormLogic(UserRequest ureq); - - void readConfiguration(UserRequest ureq, IModuleConfiguration moduleConfiguration); - void storeConfiguration(UserRequest ureq, IModuleConfiguration moduleConfiguration); - - default void refreshContents() { - // do nothing by default - } - - /** - * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, - * org.olat.core.gui.control.Controller, - * org.olat.core.gui.control.Event) - * @return true if the event was processed, false otherwise - */ - default boolean processEvent(UserRequest ureq, Controller source, Event event) { - return false; - } - - /** - * @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) - * @return true if the event was processed, false otherwise - */ - default boolean processEvent(UserRequest ureq, Component source, Event event) { - return false; - } - - /** - * called if an element inside of form triggered an event - * - * @param source - * @param event - * @return true if the event was processed, false otherwise - */ - default boolean processFormEvent(UserRequest ureq, FormItem source, FormEvent event) { - return false; - } - -} diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentContainer.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentContainer.java deleted file mode 100644 index e66d1507071a6b0bd1982ceb06f0e06ed419877b..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentContainer.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * <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.gui.components.form.flexible.impl; - -import java.util.function.Consumer; - -import org.olat.core.gui.components.form.flexible.FormItemContainer; - -/** - * Interface implemented by a visual element (usually a Form controller) that can contain - * one or more {@link IFormFragment} instances - * - * <p>Initial date: May 6, 2016<br> - * @author lmihalkovic, http://www.frentix.com - */ -public interface IFormFragmentContainer { - - /** - * Return an instance of the interface used - * @return - */ - default IFormFragmentHost getFragmentHostInterface() { - return null; - } - - /** - * Called by a hosted fragment to tell its container that the current presentation - * no longer accurately reflects the current internal state of the fragment. The - * container would generally use this information to trigger a re-evaluation of its - * layout - */ - void setNeedsLayout(); - - /** - * Used by the fragment in order to add contents to the visual presentation of the - * container - * - * @return - */ - FormItemContainer formItemsContainer(); - - /** - * Used for registering the existance of a fragment with the underlying form controller - * - * @param fragment - */ - void registerFormFragment(IFormFragment fragment); - - /** - * This method can be used to perform an operation on all the fragments currently hosted - * by this container - * - * @param handler - */ - void forEachFragment(Consumer<IFormFragment> handler); - -} diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentController.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentController.java deleted file mode 100644 index b0fa7d7b88e19d45f8c032389fa2840b8110f1a1..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentController.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * <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.gui.components.form.flexible.impl; - -import java.util.function.Consumer; - -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.control.Controller; -import org.olat.core.gui.control.Event; -import org.olat.core.gui.control.WindowControl; - -/** - * A {@link IFormFragment} requires access to a controller. This interface represents the very - * minimal set of features it expects from its controller. This subset corresponds strictly with - * the features offered by a {@link FormBasicController} and in most cases the fragment controller - * will be the form controller itself. Nonetheless this interface is here to guaranty that a - * fragment will be truly reusable by isolating it from the internal details of more powerful - * form controller. - * - * <p>Initial date: May 6, 2016<br> - * @author lmihalkovic, http://www.frentix.com - */ -public interface IFormFragmentController { - void removeAsListenerAndDispose(Controller controller); - WindowControl getWindowControl(); - void listenTo(Controller controller); - void setFormCanSubmit(boolean canSubmit); - void fireEvent(UserRequest ureq, Event event); - - - /** - * A helper method to help adapt an existing {@link FormBasicController} instance to - * the subset of features exposed by a {@link IFormFragmentController}. - * - * @param delegate the form controller to be adapted - * @param canSubmitHandler a handler to be invoked when the fragment wants to change the overall readiness state of the form - * @return - */ - public static IFormFragmentController fragmentControllerAdapter(final FormBasicController delegate, final Consumer<Boolean> canSubmitHandler) { - return new IFormFragmentController() { - @Override - public void setFormCanSubmit(boolean canSubmit) { - canSubmitHandler.accept(canSubmit); - } - - @Override - public void removeAsListenerAndDispose(Controller controller) { - delegate.removeAsListenerAndDispose(controller); - } - - @Override - public void listenTo(Controller controller) { - delegate.listenTo(controller); - } - - @Override - public WindowControl getWindowControl() { - return delegate.getWindowControlForDebug(); - } - - @Override - public void fireEvent(UserRequest ureq, Event event) { - delegate.fireEvent(ureq, event); - } - }; - } -} diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentHost.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentHost.java deleted file mode 100644 index e678e22130f6273bd26fb34e4056b71f6a93bc88..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/IFormFragmentHost.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * <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.gui.components.form.flexible.impl; - -import org.olat.core.gui.components.form.flexible.FormUIFactory; -import org.olat.core.gui.translator.Translator; - -/** - * The interface implemented by a {@link IFormFragmentContainer} to provide the {@link IFormFragment} - * with controller over its runtime behavior. - * - * <p>Initial date: May 6, 2016<br> - * @author lmihalkovic, http://www.frentix.com - */ -public interface IFormFragmentHost { - - /** - * Return a {@link Translator} instance that can provide a translation specific to where the - * fragment is used, or a default translation associated with the fragment itself. - * - * @return - */ - Translator getFragmentTranslator(); - - /** - * Return a {@link FormUIFactory} instance that may have been tweaked to enforce certain - * behavior specific to where the fragment is being embedded - * @return - */ - default FormUIFactory getUIFactory() { - return FormUIFactory.getInstance(); - } - - /** - * Return the controller instance to be used by the fragment for event handling - * - * @return - */ - IFormFragmentController getFragmentController(); - -} diff --git a/src/main/java/org/olat/course/nodes/MembersCourseNode.java b/src/main/java/org/olat/course/nodes/MembersCourseNode.java index b6e1cd71fadbe1ac044cd28a5dadc32bb90d65bd..f09c31e6944704a90e6e2c061eacb1889802cf71 100644 --- a/src/main/java/org/olat/course/nodes/MembersCourseNode.java +++ b/src/main/java/org/olat/course/nodes/MembersCourseNode.java @@ -34,7 +34,6 @@ import org.olat.course.ICourse; import org.olat.course.editor.CourseEditorEnv; import org.olat.course.editor.NodeEditController; import org.olat.course.editor.StatusDescription; -import org.olat.course.editor.formfragments.MembersSelectorFormFragment; import org.olat.course.nodes.info.InfoCourseNodeEditController; import org.olat.course.nodes.members.MembersCourseNodeEditController; import org.olat.course.nodes.members.MembersCourseNodeRunController; @@ -42,9 +41,7 @@ import org.olat.course.nodes.members.MembersPeekViewController; import org.olat.course.run.navigation.NodeRunConstructionResult; import org.olat.course.run.userview.NodeEvaluation; import org.olat.course.run.userview.UserCourseEnvironment; -import org.olat.modules.IModuleConfiguration; import org.olat.modules.ModuleConfiguration; -import org.olat.modules.ModuleProperty; import org.olat.repository.RepositoryEntry; @@ -66,28 +63,29 @@ public class MembersCourseNode extends AbstractAccessableCourseNode { //Config keys public static final String CONFIG_KEY_SHOWOWNER = "showOwner"; - private static final String CONFIG_KEY_SHOWCOACHES = "showCoaches"; - private static final String CONFIG_KEY_SHOWPARTICIPANTS = "showParticpants"; + public static final String CONFIG_KEY_SHOWCOACHES = "showCoaches"; + public static final String CONFIG_KEY_SHOWPARTICIPANTS = "showParticpants"; + + public static final String CONFIG_KEY_COACHES_ALL = "members_CoachesAll"; + public static final String CONFIG_KEY_PARTICIPANTS_ALL = "members_ParticipantsAll"; - public static final String CONFIG_KEY_EMAIL_FUNCTION = "emailFunction"; public static final String CONFIG_KEY_DOWNLOAD_FUNCTION = "downloadFunction"; public static final String EMAIL_FUNCTION_ALL = "all"; public static final String EMAIL_FUNCTION_COACH_ADMIN = "coachAndAdmin"; - - public static final ModuleProperty<Boolean> CONFIG_KEY_COACHES_ALL = new ModuleProperty<Boolean>(MembersSelectorFormFragment.CONFIG_KEY_COACHES_ALL){}; - public static final ModuleProperty<Boolean> CONFIG_KEY_COACHES_COURSE = new ModuleProperty<Boolean>(MembersSelectorFormFragment.CONFIG_KEY_COACHES_COURSE, false){}; - public static final ModuleProperty<String> CONFIG_KEY_COACHES_GROUP = new ModuleProperty<String>(MembersSelectorFormFragment.CONFIG_KEY_COACHES_GROUP){}; - public static final ModuleProperty<List<Long>> CONFIG_KEY_COACHES_GROUP_ID = new ModuleProperty<List<Long>>(MembersSelectorFormFragment.CONFIG_KEY_COACHES_GROUP_ID){}; - public static final ModuleProperty<String> CONFIG_KEY_COACHES_AREA = new ModuleProperty<String>(MembersSelectorFormFragment.CONFIG_KEY_COACHES_AREA){}; - public static final ModuleProperty<List<Long>> CONFIG_KEY_COACHES_AREA_IDS = new ModuleProperty<List<Long>>(MembersSelectorFormFragment.CONFIG_KEY_COACHES_AREA_IDS){}; - public static final ModuleProperty<Boolean> CONFIG_KEY_PARTICIPANTS_ALL = new ModuleProperty<Boolean>(MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_ALL){}; - public static final ModuleProperty<Boolean> CONFIG_KEY_PARTICIPANTS_COURSE = new ModuleProperty<Boolean>(MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_COURSE){}; - public static final ModuleProperty<String> CONFIG_KEY_PARTICIPANTS_GROUP = new ModuleProperty<String>(MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_GROUP){}; - public static final ModuleProperty<List<Long>> CONFIG_KEY_PARTICIPANTS_GROUP_ID = new ModuleProperty<List<Long>>(MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_GROUP_ID){}; - public static final ModuleProperty<String> CONFIG_KEY_PARTICIPANTS_AREA = new ModuleProperty<String>(MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_AREA){}; - public static final ModuleProperty<List<Long>> CONFIG_KEY_PARTICIPANTS_AREA_ID = new ModuleProperty<List<Long>>(MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_AREA_ID){}; + public static final String CONFIG_KEY_COACHES_COURSE = "members_CourseCoaches"; + public static final String CONFIG_KEY_COACHES_GROUP = "members_GroupCoaches"; + public static final String CONFIG_KEY_COACHES_GROUP_ID = "members_GroupCoachesIds"; + public static final String CONFIG_KEY_COACHES_AREA = "members_AreaCoaches"; + public static final String CONFIG_KEY_COACHES_AREA_IDS = "members_AreaCoachesIds"; + + public static final String CONFIG_KEY_PARTICIPANTS_COURSE = "members_CourseParticipants"; + public static final String CONFIG_KEY_PARTICIPANTS_GROUP = "members_GroupParticipants"; + public static final String CONFIG_KEY_PARTICIPANTS_GROUP_ID = "members_GroupParticipantsIds"; + public static final String CONFIG_KEY_PARTICIPANTS_AREA = "members_AreaParticipants"; + public static final String CONFIG_KEY_PARTICIPANTS_AREA_ID = "members_AreaParticipantsIds"; + public MembersCourseNode() { super(TYPE); @@ -148,28 +146,11 @@ public class MembersCourseNode extends AbstractAccessableCourseNode { @Override public Controller createPeekViewRunController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne) { return new MembersPeekViewController(ureq, wControl, userCourseEnv, this.getModuleConfiguration()); - - //TODO check if this is the desired -// updateModuleConfigDefaults(false); -// -// // Use normal view as peekview -// Controller controller; -// Roles roles = ureq.getUserSession().getRoles(); -// if (roles.isGuestOnly()) { -// Translator trans = Util.createPackageTranslator(CourseNode.class, ureq.getLocale()); -// String title = trans.translate("guestnoaccess.title"); -// String message = trans.translate("guestnoaccess.message"); -// controller = MessageUIFactory.createInfoMessage(ureq, wControl, title, message); -// } else { -// controller = new MembersCourseNodeRunController(ureq, wControl, userCourseEnv, this.getModuleConfiguration()); -// } -// return controller; } @Override public void updateModuleConfigDefaults(boolean isNewNode) { ModuleConfiguration config = getModuleConfiguration(); - IModuleConfiguration membersFrag = IModuleConfiguration.fragment("members", config); int version = config.getConfigurationVersion(); if(isNewNode){ config.setBooleanEntry(CONFIG_KEY_SHOWOWNER, false); @@ -194,11 +175,11 @@ public class MembersCourseNode extends AbstractAccessableCourseNode { } if(version < 4) { if(config.getBooleanEntry(CONFIG_KEY_SHOWCOACHES)) { - membersFrag.set(CONFIG_KEY_COACHES_ALL, true); + config.set(CONFIG_KEY_COACHES_ALL, true); config.remove(CONFIG_KEY_SHOWCOACHES); } if(config.getBooleanEntry(CONFIG_KEY_SHOWPARTICIPANTS)) { - membersFrag.set(CONFIG_KEY_PARTICIPANTS_ALL, true); + config.set(CONFIG_KEY_PARTICIPANTS_ALL, true); config.remove(CONFIG_KEY_SHOWPARTICIPANTS); } config.setConfigurationVersion(4); diff --git a/src/main/java/org/olat/course/nodes/co/COConfigForm.java b/src/main/java/org/olat/course/nodes/co/COConfigForm.java index b7db6fb229984292f31bee608b9caeb466a4e5d5..12a65e42c18a01831ee71ceff188547f89c0c555 100755 --- a/src/main/java/org/olat/course/nodes/co/COConfigForm.java +++ b/src/main/java/org/olat/course/nodes/co/COConfigForm.java @@ -33,22 +33,16 @@ 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.SelectionElement; import org.olat.core.gui.components.form.flexible.elements.TextElement; -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.components.form.flexible.impl.FormLayoutContainer; -import org.olat.core.gui.components.form.flexible.impl.IFormFragmentController; -import org.olat.core.gui.components.form.flexible.impl.IFormFragmentHost; import org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; -import org.olat.core.gui.translator.Translator; import org.olat.core.util.StringHelper; -import org.olat.core.util.Util; import org.olat.core.util.mail.MailHelper; -import org.olat.course.editor.formfragments.MembersSelectorFormFragment; +import org.olat.course.nodes.members.ui.group.MembersSelectorFormFragment; import org.olat.course.run.userview.UserCourseEnvironment; -import org.olat.modules.IModuleConfiguration; import org.olat.modules.ModuleConfiguration; /** @@ -58,76 +52,89 @@ import org.olat.modules.ModuleConfiguration; * @author Felix Jost * @author Dirk Furrer */ -public class COConfigForm extends FormBasicController { +public class COConfigForm extends MembersSelectorFormFragment { private SelectionElement wantEmail; - private TextElement teArElEmailToAdresses; - private SelectionElement wantOwners; - + private TextElement teArElEmailToAdresses; private TextElement teElSubject; private TextElement teArElBody; - - // -- -// private SelectionElement wantCoaches; -// private SingleSelection coachesChoice; -// private FormLink chooseGroupCoachesLink; -// private GroupSelectionController groupChooseCoaches; -// private StaticTextElement easyGroupCoachSelectionList; -// private FormLink chooseAreasCoachesLink; -// private AreaSelectionController areaChooseCoaches; -// private StaticTextElement easyAreaCoachSelectionList; - - // -- -// private SelectionElement wantParticipants; -// private SingleSelection participantsChoice; -// private FormLink chooseGroupParticipantsLink; -// private GroupSelectionController groupChooseParticipants; -// private StaticTextElement easyGroupParticipantsSelectionList; -// private FormLink chooseAreasParticipantsLink; -// private AreaSelectionController areaChooseParticipants; -// private StaticTextElement easyAreaParticipantsSelectionList; - // -- - - private final MembersSelectorFormFragment membersFragment; private FormItemContainer recipentsContainer; - private FormSubmit subm; - -// private CloseableModalController cmc; - - private List<String> eList; - private ModuleConfiguration config; -// private CourseEditorEnv cev; - -// @Autowired -// private BGAreaManager areaManager; -// @Autowired -// private BusinessGroupService businessGroupService; + private FormSubmit submitButton; + private List<String> eList; /** * Form constructor * * @param name The form name * @param config The module configuration - * @param withCancel true: cancel button is rendered, false: no cancel button */ - protected COConfigForm(UserRequest ureq, WindowControl wControl, ModuleConfiguration config, UserCourseEnvironment uce) { - super(ureq, wControl); - this.config = config; -// this.cev = uce.getCourseEditorEnv(); - - membersFragment = new MembersSelectorFormFragment(uce.getCourseEditorEnv()); - registerFormFragment(membersFragment); // register with parent for proper lifecycle handling - initForm(ureq); - validateFormLogic(ureq); + protected COConfigForm(UserRequest ureq, WindowControl wControl, + ModuleConfiguration config, UserCourseEnvironment uce) { + super(ureq, wControl, uce.getCourseEditorEnv(), config); + } + + @Override + protected String getConfigKeyCoachesGroup() { + return COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP; + } + + @Override + protected String getConfigKeyCoachesGroupIds() { + return COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP_ID; + } + + @Override + protected String getConfigKeyCoachesArea() { + return COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA; + } + + @Override + protected String getConfigKeyCoachesAreaIds() { + return COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA_IDS; + } + + @Override + protected String getConfigKeyCoachesCourse() { + return COEditController.CONFIG_KEY_EMAILTOCOACHES_COURSE; + } + + @Override + protected String getConfigKeyCoachesAll() { + return COEditController.CONFIG_KEY_EMAILTOCOACHES_ALL; + } + + @Override + protected String getConfigKeyParticipantsGroup() { + return COEditController.CONFIG_KEY_EMAILTOPARTICIPANTS_GROUP; + } + + @Override + protected String getConfigKeyParticipantsArea() { + return COEditController.CONFIG_KEY_EMAILTOPARTICIPANTS_AREA; + } + + @Override + protected String getConfigKeyParticipantsGroupIds() { + return COEditController.CONFIG_KEY_EMAILTOPARTICIPANTS_GROUP_ID; + } + + @Override + protected String getConfigKeyParticipantsAreaIds() { + return COEditController.CONFIG_KEY_EMAILTOPARTICIPANTS_AREA_ID; + } + + @Override + protected String getConfigKeyParticipantsCourse() { + return COEditController.CONFIG_KEY_EMAILTOPARTICIPANTS_COURSE; } @Override - public void storeFormData(UserRequest ureq) { - membersFragment.storeConfiguration(ureq, IModuleConfiguration.fragment("emailTo", "", config)); + protected String getConfigKeyParticipantsAll() { + return COEditController.CONFIG_KEY_EMAILTOPARTICIPANTS_ALL; } /** @@ -137,7 +144,7 @@ public class COConfigForm extends FormBasicController { protected boolean validateFormLogic(UserRequest ureq) { boolean isOK = true; - if (!membersFragment.sendToCoaches() && !membersFragment.sendToPartips() && !wantEmail.isSelected(0) && !sendToOwners()) { + if (!sendToCoaches() && !sendToPartips() && !wantEmail.isSelected(0) && !sendToOwners()) { recipentsContainer.setErrorKey("no.recipents.specified", null); isOK = false; } @@ -174,13 +181,8 @@ public class COConfigForm extends FormBasicController { } } - return isOK - & membersFragment.validateFormLogic(ureq) - & super.validateFormLogic(ureq); + return isOK & super.validateFormLogic(ureq); } - - - /** * @return the message subject @@ -207,53 +209,23 @@ public class COConfigForm extends FormBasicController { return wantOwners.isSelected(0); } - @Override - protected void formOK(UserRequest ureq) { - fireEvent (ureq, Event.DONE_EVENT); - } - - @Override - public IFormFragmentHost getFragmentHostInterface() { - return new IFormFragmentHost() { - final Translator parent = COConfigForm.this.getTranslator(); - final Translator delegate = Util.createPackageTranslator(MembersSelectorFormFragment.class, parent.getLocale(), parent); - final IFormFragmentController adapter = IFormFragmentController.fragmentControllerAdapter(COConfigForm.this, canSubmit -> { - subm.setEnabled(canSubmit); - }); - - @Override - public Translator getFragmentTranslator() { - return delegate; - } - - @Override - public IFormFragmentController getFragmentController() { - return adapter; - } - }; - } - @Override protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { Boolean ownerSelection = config.getBooleanSafe(COEditController.CONFIG_KEY_EMAILTOOWNERS); -// Boolean coacheSelection = config.getBooleanSafe(COEditController.CONFIG_KEY_EMAILTOCOACHES_ALL) || config.getBooleanSafe(COEditController.CONFIG_KEY_EMAILTOCOACHES_COURSE) || config.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP) != null || config.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA) != null; - setFormTitle("header", null); setFormContextHelp("Administration and Organisation#_mail"); //for displaying error message in case neither group stuff nor email is selected - recipentsContainer = FormLayoutContainer.createHorizontalFormLayout( - "recipents", getTranslator() - ); - formLayout.add(recipentsContainer); + recipentsContainer = FormLayoutContainer.createHorizontalFormLayout("recipents", getTranslator()); + formLayout.add(recipentsContainer); wantEmail = uifactory.addCheckboxesHorizontal("wantEmail", "message.want.email", formLayout, new String[]{"xx"}, new String[]{null}); wantEmail.addActionListener(FormEvent.ONCLICK); // External recipients - eList = (List<String>) config.get(COEditController.CONFIG_KEY_EMAILTOADRESSES); + eList = config.getList(COEditController.CONFIG_KEY_EMAILTOADRESSES, String.class); String emailToAdresses = ""; if (eList != null) { emailToAdresses = StringHelper.formatIdentitesAsEmailToString(eList, "\n"); @@ -271,8 +243,7 @@ public class COConfigForm extends FormBasicController { wantOwners.addActionListener(FormEvent.ONCLICK); // include existing fragment - IModuleConfiguration emailToFrag = IModuleConfiguration.fragment("emailTo", "", config); - membersFragment.initFormFragment(ureq, this, this, emailToFrag); + super.initForm(formLayout, listener, ureq); //subject String mS = (String) config.get(COEditController.CONFIG_KEY_MSUBJECT_DEFAULT); @@ -284,14 +255,13 @@ public class COConfigForm extends FormBasicController { String mBody = (mB != null) ? mB : ""; teArElBody = uifactory.addRichTextElementForStringDataMinimalistic("mBody", "message.body", mBody, 8, 60, formLayout, getWindowControl()); - subm = uifactory.addFormSubmitButton("save", formLayout); - - + submitButton = uifactory.addFormSubmitButton("save", formLayout); update(); } - private void update () { - membersFragment.refreshContents(); + @Override + protected void update() { + super.update(); teArElEmailToAdresses.setVisible(wantEmail.isSelected(0)); teArElEmailToAdresses.clearError(); @@ -306,23 +276,28 @@ public class COConfigForm extends FormBasicController { @Override protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { - /*boolean processed = */this.membersFragment.processFormEvent(ureq, source, event); - + super.formInnerEvent(ureq, source, event); update(); } @Override protected void event(UserRequest ureq, Controller source, Event event) { - subm.setEnabled(true); - + submitButton.setEnabled(true); // the parent takes care of dealing with fragments super.event(ureq, source, event); - } @Override - protected void doDispose() { - membersFragment.dispose(); + protected void setFormCanSubmit(boolean enable) { + submitButton.setEnabled(enable); + } + + @Override + protected void storeConfiguration(ModuleConfiguration config) { + super.storeConfiguration(config); + config.setBooleanEntry(COEditController.CONFIG_KEY_EMAILTOOWNERS, sendToOwners()); + config.set(COEditController.CONFIG_KEY_EMAILTOADRESSES, getEmailList()); + config.set(COEditController.CONFIG_KEY_MSUBJECT_DEFAULT, getMSubject()); + config.set(COEditController.CONFIG_KEY_MBODY_DEFAULT, getMBody()); } - } \ No newline at end of file diff --git a/src/main/java/org/olat/course/nodes/co/COEditController.java b/src/main/java/org/olat/course/nodes/co/COEditController.java index 549c22741698ef34e74202cc019a8899b65a1249..ddd43b22e0998f521d72da251f28d88d7379c6b1 100755 --- a/src/main/java/org/olat/course/nodes/co/COEditController.java +++ b/src/main/java/org/olat/course/nodes/co/COEditController.java @@ -27,7 +27,6 @@ package org.olat.course.nodes.co; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; -import org.olat.core.gui.components.panel.Panel; import org.olat.core.gui.components.tabbedpane.TabbedPane; import org.olat.core.gui.components.velocity.VelocityContainer; import org.olat.core.gui.control.Controller; @@ -40,7 +39,6 @@ import org.olat.course.assessment.AssessmentHelper; import org.olat.course.condition.Condition; import org.olat.course.condition.ConditionEditController; import org.olat.course.editor.NodeEditController; -import org.olat.course.editor.formfragments.MembersSelectorFormFragment; import org.olat.course.nodes.COCourseNode; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.modules.ModuleConfiguration; @@ -66,29 +64,29 @@ public class COEditController extends ActivateableTabbableDefaultController impl public static final String CONFIG_KEY_EMAILTOGROUPS = "emailToGroups"; /** config key: to email addresses to be extracted from specified learn areas */ - public static final String CONFIG_KEY_EMAILTOCOACHES_AREA = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_COACHES_AREA; + public static final String CONFIG_KEY_EMAILTOCOACHES_AREA = "emailTo" + "AreaCoaches"; /** config key: to email addresses to be extracted from specified learn areas */ - public static final String CONFIG_KEY_EMAILTOCOACHES_AREA_IDS = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_COACHES_AREA_IDS; + public static final String CONFIG_KEY_EMAILTOCOACHES_AREA_IDS = "emailTo" + "AreaCoachesIds"; /** config key: keys of the course participants list */ - public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_ALL = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_ALL; + public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_ALL = "emailTo" + "ParticipantsAll"; /** config key: keys of the group participants list */ - public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_GROUP_ID = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_GROUP_ID; + public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_GROUP_ID = "emailTo" + "GroupParticipantsIds"; /** config key: email goes to group participants */ - public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_GROUP = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_GROUP; - public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_AREA_ID = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_AREA_ID; + public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_GROUP = "emailTo" + "GroupParticipants"; + public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_AREA_ID = "emailTo" + "AreaParticipantsIds"; /** config key: email goes to group participants */ - public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_AREA = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_AREA; + public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_AREA = "emailTo" + "AreaParticipants"; /** config key: email goes to course participants */ - public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_COURSE = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_PARTICIPANTS_COURSE; + public static final String CONFIG_KEY_EMAILTOPARTICIPANTS_COURSE = "emailTo" + "CourseParticipants"; /** config key: email goes to group coaches */ - public static final String CONFIG_KEY_EMAILTOCOACHES_GROUP = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_COACHES_GROUP; + public static final String CONFIG_KEY_EMAILTOCOACHES_GROUP = "emailTo" + "GroupCoaches"; /** config key: key of the group coaches list */ - public static final String CONFIG_KEY_EMAILTOCOACHES_GROUP_ID = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_COACHES_GROUP_ID; + public static final String CONFIG_KEY_EMAILTOCOACHES_GROUP_ID = "emailTo" + "GroupCoachesIds"; /** config key: key of the course coaches list */ - public static final String CONFIG_KEY_EMAILTOCOACHES_ALL = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_COACHES_ALL; + public static final String CONFIG_KEY_EMAILTOCOACHES_ALL = "emailTo" + "CoachesAll"; /** config key: email goes to course coaches */ - public static final String CONFIG_KEY_EMAILTOCOACHES_COURSE = "emailTo" + MembersSelectorFormFragment.CONFIG_KEY_COACHES_COURSE; + public static final String CONFIG_KEY_EMAILTOCOACHES_COURSE = "emailTo" + "CourseCoaches"; /** config key: email goes to course owners */ public static final String CONFIG_KEY_EMAILTOOWNERS = "emailToOwners"; /** config key: email goes to email address */ @@ -98,9 +96,7 @@ public class COEditController extends ActivateableTabbableDefaultController impl /** config key: default body text */ public static final String CONFIG_KEY_MBODY_DEFAULT = "mBodyDefault"; - private ModuleConfiguration moduleConfiguration; private final VelocityContainer myContent; - private Panel main; private COConfigForm configForm; private COCourseNode courseNode; private ConditionEditController accessibilityCondContr; @@ -116,16 +112,12 @@ public class COEditController extends ActivateableTabbableDefaultController impl */ public COEditController(ModuleConfiguration config, UserRequest ureq, WindowControl wControl, COCourseNode coCourseNode, ICourse course, UserCourseEnvironment euce) { super(ureq,wControl); - this.moduleConfiguration = config; this.courseNode = coCourseNode; - - main = new Panel("coeditpanel"); - + myContent = createVelocityContainer("edit"); configForm = new COConfigForm(ureq, wControl, config, euce); configForm.addControllerListener(this); - myContent.put("configForm", configForm.getInitialComponent()); // not needed: setInitialComponent(myContent); @@ -134,8 +126,6 @@ public class COEditController extends ActivateableTabbableDefaultController impl accessibilityCondContr = new ConditionEditController(ureq, getWindowControl(), euce, accessCondition, AssessmentHelper.getAssessableNodes(course.getEditorTreeModel(), coCourseNode)); listenTo(accessibilityCondContr); - - main.setContent(myContent); } /** @@ -160,32 +150,8 @@ public class COEditController extends ActivateableTabbableDefaultController impl } } else if (source == configForm) { // those must be links - if (event == Event.CANCELLED_EVENT) { - return; - } else if (event == Event.DONE_EVENT) { - this.configForm.storeFormData(ureq); - -// moduleConfiguration.set(CONFIG_KEY_EMAILTOCOACHES_GROUP, configForm.getEmailGroupCoaches()); -// moduleConfiguration.set(CONFIG_KEY_EMAILTOCOACHES_AREA, configForm.getEmailCoachesAreas()); -// moduleConfiguration.set(CONFIG_KEY_EMAILTOCOACHES_GROUP_ID, configForm.getEmailGroupCoachesIds()); -// moduleConfiguration.set(CONFIG_KEY_EMAILTOCOACHES_AREA_IDS, configForm.getEmailCoachesAreaIds()); -// moduleConfiguration.setBooleanEntry(CONFIG_KEY_EMAILTOCOACHES_ALL, configForm.sendToCoachesAll()); -// moduleConfiguration.setBooleanEntry(CONFIG_KEY_EMAILTOCOACHES_COURSE, configForm.sendToCoachesCourse()); - -// moduleConfiguration.set(CONFIG_KEY_EMAILTOPARTICIPANTS_GROUP, configForm.getEmailGroupParticipants()); -// moduleConfiguration.set(CONFIG_KEY_EMAILTOPARTICIPANTS_GROUP_ID, configForm.getEmailGroupParticipantsIds()); -// moduleConfiguration.set(CONFIG_KEY_EMAILTOPARTICIPANTS_AREA, configForm.getEmailParticipantsAreas()); -// moduleConfiguration.set(CONFIG_KEY_EMAILTOPARTICIPANTS_AREA_ID, configForm.getEmailParticipantsAreaIds()); -// moduleConfiguration.setBooleanEntry(CONFIG_KEY_EMAILTOPARTICIPANTS_COURSE, configForm.sendToParticipantsCourse()); -// moduleConfiguration.setBooleanEntry(CONFIG_KEY_EMAILTOPARTICIPANTS_ALL, configForm.sendToParticipantsAll()); - - moduleConfiguration.setBooleanEntry(CONFIG_KEY_EMAILTOOWNERS, configForm.sendToOwners()); - moduleConfiguration.set(CONFIG_KEY_EMAILTOADRESSES, configForm.getEmailList()); - moduleConfiguration.set(CONFIG_KEY_MSUBJECT_DEFAULT, configForm.getMSubject()); - moduleConfiguration.set(CONFIG_KEY_MBODY_DEFAULT, configForm.getMBody()); - + if (event == Event.DONE_EVENT) { fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT); - return; } } } diff --git a/src/main/java/org/olat/course/nodes/members/MembersConfigForm.java b/src/main/java/org/olat/course/nodes/members/MembersConfigForm.java index 763604b8be3ca468905db32799e1b2fd9d35c1fa..142eaee0abde15553c7b099a40df3c61158dc4f0 100755 --- a/src/main/java/org/olat/course/nodes/members/MembersConfigForm.java +++ b/src/main/java/org/olat/course/nodes/members/MembersConfigForm.java @@ -25,20 +25,14 @@ 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.MultipleSelectionElement; 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.components.form.flexible.impl.IFormFragmentController; -import org.olat.core.gui.components.form.flexible.impl.IFormFragmentHost; import org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; -import org.olat.core.gui.translator.Translator; -import org.olat.core.util.Util; -import org.olat.course.editor.formfragments.MembersSelectorFormFragment; import org.olat.course.nodes.MembersCourseNode; +import org.olat.course.nodes.members.ui.group.MembersSelectorFormFragment; import org.olat.course.run.userview.UserCourseEnvironment; -import org.olat.modules.IModuleConfiguration; import org.olat.modules.ModuleConfiguration; /** @@ -49,20 +43,17 @@ import org.olat.modules.ModuleConfiguration; * * @autohr dfurrer, dirk.furrer@frentix.com, http://www.frentix.com */ -public class MembersConfigForm extends FormBasicController { +public class MembersConfigForm extends MembersSelectorFormFragment { private static final String[] onKeys = new String[] { "on" }; private static final String[] onValues = new String[] { "" }; private static final String[] emailFctKeys = new String[]{ MembersCourseNode.EMAIL_FUNCTION_ALL, MembersCourseNode.EMAIL_FUNCTION_COACH_ADMIN }; - private final ModuleConfiguration config; private MultipleSelectionElement showOwners; private SingleSelection emailFunctionEl; private SingleSelection downloadFunctionEl; - private final MembersSelectorFormFragment membersFragment; - - private FormSubmit subm; + private FormSubmit submitButton; /** * Form constructor @@ -74,31 +65,77 @@ public class MembersConfigForm extends FormBasicController { * @param withCancel * true: cancel button is rendered, false: no cancel button */ - protected MembersConfigForm(UserRequest ureq, WindowControl wControl, UserCourseEnvironment euce, - ModuleConfiguration config) { - super(ureq, wControl); - this.config = config; - membersFragment = new MembersSelectorFormFragment(euce.getCourseEditorEnv()); - registerFormFragment(membersFragment); // register with parent for proper lifecycle handling - initForm(ureq); - validateFormLogic(ureq); + protected MembersConfigForm(UserRequest ureq, WindowControl wControl, + UserCourseEnvironment euce, ModuleConfiguration config) { + super(ureq, wControl, euce.getCourseEditorEnv(), config); } @Override - public void storeFormData(UserRequest ureq) { - config.setBooleanEntry(MembersCourseNode.CONFIG_KEY_SHOWOWNER, showOwners.isSelected(0)); - membersFragment.storeConfiguration(ureq, IModuleConfiguration.fragment("members", config)); + protected String getConfigKeyCoachesGroup() { + return MembersCourseNode.CONFIG_KEY_COACHES_GROUP; + } + + @Override + protected String getConfigKeyCoachesArea() { + return MembersCourseNode.CONFIG_KEY_COACHES_AREA; + } + + @Override + protected String getConfigKeyCoachesGroupIds() { + return MembersCourseNode.CONFIG_KEY_COACHES_GROUP_ID; } @Override - protected boolean validateFormLogic(UserRequest ureq) { - boolean isOK = true; + protected String getConfigKeyCoachesAreaIds() { + return MembersCourseNode.CONFIG_KEY_COACHES_AREA_IDS; + } - return isOK - & membersFragment.validateFormLogic(ureq) - & super.validateFormLogic(ureq); + @Override + protected String getConfigKeyCoachesCourse() { + return MembersCourseNode.CONFIG_KEY_COACHES_COURSE; + } + + @Override + protected String getConfigKeyCoachesAll() { + return MembersCourseNode.CONFIG_KEY_COACHES_ALL; + } + + @Override + protected String getConfigKeyParticipantsGroup() { + return MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP; } + @Override + protected String getConfigKeyParticipantsArea() { + return MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA; + } + + @Override + protected String getConfigKeyParticipantsGroupIds() { + return MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP_ID; + } + + @Override + protected String getConfigKeyParticipantsAreaIds() { + return MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA_ID; + } + + @Override + protected String getConfigKeyParticipantsCourse() { + return MembersCourseNode.CONFIG_KEY_PARTICIPANTS_COURSE; + } + + @Override + protected String getConfigKeyParticipantsAll() { + return MembersCourseNode.CONFIG_KEY_PARTICIPANTS_ALL; + } + + @Override + public void storeConfiguration(ModuleConfiguration config) { + config.setBooleanEntry(MembersCourseNode.CONFIG_KEY_SHOWOWNER, showOwners.isSelected(0)); + super.storeConfiguration(config); + } + @Override protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { // set Formtitle and infobar @@ -111,12 +148,10 @@ public class MembersConfigForm extends FormBasicController { // Generate widgets showOwners = uifactory.addCheckboxesHorizontal("members.owners", formLayout, onKeys, onValues); - showOwners.addActionListener(FormEvent.ONCLICK); // include existing fragment - IModuleConfiguration membersFrag = IModuleConfiguration.fragment("members", config); - membersFragment.initFormFragment(ureq, this, this, membersFrag); + super.initForm(formLayout, listener, ureq); // select initial state according to config showOwners.select("on", showOwnerConfig); @@ -144,53 +179,22 @@ public class MembersConfigForm extends FormBasicController { downloadFunctionEl.select(MembersCourseNode.EMAIL_FUNCTION_ALL, true); } - subm = uifactory.addFormSubmitButton("save", formLayout); + submitButton = uifactory.addFormSubmitButton("save", formLayout); update(); } - @Override - protected void doDispose() { - membersFragment.dispose(); - } - - @Override - protected void formOK(UserRequest ureq) { - fireEvent(ureq, Event.DONE_EVENT); - } - //method to check if the of of the checkboxes needs to be disabled in order to ensure a valid configuration //in the rare case of an invalid config all checkboxes are enabled - private void update() { - membersFragment.refreshContents(); - - flc.setDirty(true); - } - @Override - public IFormFragmentHost getFragmentHostInterface() { - return new IFormFragmentHost() { - final Translator parent = MembersConfigForm.this.getTranslator(); - final Translator delegate = Util.createPackageTranslator(MembersSelectorFormFragment.class, parent.getLocale(), parent); - final IFormFragmentController adapter = IFormFragmentController.fragmentControllerAdapter(MembersConfigForm.this, canSubmit -> { - subm.setEnabled(canSubmit); - }); - - @Override - public Translator getFragmentTranslator() { - return delegate; - } - - @Override - public IFormFragmentController getFragmentController() { - return adapter; - } - }; + protected void update() { + super.update(); + flc.setDirty(true); } @Override protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { - membersFragment.processFormEvent(ureq, source, event); + super.formInnerEvent(ureq, source, event); if(showOwners == source) { // || showCoaches == source || showParticipants == source) { config.setBooleanEntry(MembersCourseNode.CONFIG_KEY_SHOWOWNER, showOwners.isSelected(0)); @@ -218,4 +222,8 @@ public class MembersConfigForm extends FormBasicController { update(); } + @Override + protected void setFormCanSubmit(boolean enable) { + submitButton.setEnabled(enable); + } } diff --git a/src/main/java/org/olat/course/nodes/members/MembersCourseNodeEditController.java b/src/main/java/org/olat/course/nodes/members/MembersCourseNodeEditController.java index cc81014a2c157b66908b8892424b29a213910024..72993d2215dd1e39536757f600b691ce2d9af422 100644 --- a/src/main/java/org/olat/course/nodes/members/MembersCourseNodeEditController.java +++ b/src/main/java/org/olat/course/nodes/members/MembersCourseNodeEditController.java @@ -21,7 +21,6 @@ package org.olat.course.nodes.members; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; -import org.olat.core.gui.components.form.flexible.impl.FormBasicController; import org.olat.core.gui.components.tabbedpane.TabbedPane; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.ControllerEventListener; @@ -49,7 +48,7 @@ public class MembersCourseNodeEditController extends ActivateableTabbableDefault private TabbedPane myTabbedPane; - private FormBasicController membersConfigForm; + private MembersConfigForm membersConfigForm; public MembersCourseNodeEditController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment euce, ModuleConfiguration config) { super(ureq,wControl); @@ -83,7 +82,6 @@ public class MembersCourseNodeEditController extends ActivateableTabbableDefault public void event(UserRequest urequest, Controller source, Event event) { super.event(urequest, source, event); if(source == membersConfigForm && event == Event.DONE_EVENT) { - membersConfigForm.storeFormData(urequest); fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT); } } diff --git a/src/main/java/org/olat/course/nodes/members/MembersCourseNodeRunController.java b/src/main/java/org/olat/course/nodes/members/MembersCourseNodeRunController.java index 76d5433a2ff3774a49b85a9b078a5348cfb8c6b4..ce2f9da3c0fca6c9aee3ad3886813a2418608954 100644 --- a/src/main/java/org/olat/course/nodes/members/MembersCourseNodeRunController.java +++ b/src/main/java/org/olat/course/nodes/members/MembersCourseNodeRunController.java @@ -37,7 +37,6 @@ import org.olat.course.nodes.MembersCourseNode; import org.olat.course.run.environment.CourseEnvironment; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.group.BusinessGroupService; -import org.olat.modules.IModuleConfiguration; import org.olat.modules.ModuleConfiguration; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryService; @@ -85,8 +84,6 @@ public class MembersCourseNodeRunController extends BasicController { String downloadFct = config.getStringValue(MembersCourseNode.CONFIG_KEY_DOWNLOAD_FUNCTION, MembersCourseNode.EMAIL_FUNCTION_COACH_ADMIN); boolean canDownload = MembersCourseNode.EMAIL_FUNCTION_ALL.equals(downloadFct) || userCourseEnv.isAdmin() || userCourseEnv.isCoach(); - IModuleConfiguration membersFrag = IModuleConfiguration.fragment("members", config); - if(showOwners) { RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry(); owners = MembersHelpers.getOwners(repositoryService, courseRepositoryEntry); @@ -95,21 +92,21 @@ public class MembersCourseNodeRunController extends BasicController { } boolean showCoaches = false; - if(membersFrag.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_ALL, MembersCourseNode.CONFIG_KEY_COACHES_COURSE) - || membersFrag.hasAnyOf(MembersCourseNode.CONFIG_KEY_COACHES_GROUP, MembersCourseNode.CONFIG_KEY_COACHES_AREA)) { + if(config.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_ALL, MembersCourseNode.CONFIG_KEY_COACHES_COURSE) + || config.hasAnyOf(MembersCourseNode.CONFIG_KEY_COACHES_GROUP, MembersCourseNode.CONFIG_KEY_COACHES_AREA)) { CourseGroupManager cgm = courseEnv.getCourseGroupManager(); - MembersHelpers.addCoaches(membersFrag, cgm, businessGroupService, coaches); + MembersHelpers.addCoaches(config, cgm, businessGroupService, coaches); showCoaches = true; } boolean showParticipants = false; - if(membersFrag.anyTrue(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_ALL, MembersCourseNode.CONFIG_KEY_PARTICIPANTS_COURSE) - || membersFrag.hasAnyOf(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP, MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA)) { + if(config.anyTrue(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_ALL, MembersCourseNode.CONFIG_KEY_PARTICIPANTS_COURSE) + || config.hasAnyOf(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP, MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA)) { CourseGroupManager cgm = courseEnv.getCourseGroupManager(); - MembersHelpers.addParticipants(membersFrag, cgm, businessGroupService, participants); + MembersHelpers.addParticipants(config, cgm, businessGroupService, participants); showParticipants = true; } @@ -122,14 +119,11 @@ public class MembersCourseNodeRunController extends BasicController { putInitialPanel(membersDisplayRunController.getInitialComponent()); } - @Override protected void event(UserRequest ureq, Component source, Event event) { // } - - @Override protected void doDispose() { // nothing to dispose diff --git a/src/main/java/org/olat/course/nodes/members/MembersHelpers.java b/src/main/java/org/olat/course/nodes/members/MembersHelpers.java index decdbe1f021ed19c1527a82432d5644806054db2..204fff6b698b2ea104a41b7842be1f11d583affe 100644 --- a/src/main/java/org/olat/course/nodes/members/MembersHelpers.java +++ b/src/main/java/org/olat/course/nodes/members/MembersHelpers.java @@ -30,7 +30,7 @@ import org.olat.core.util.StringHelper; import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.nodes.MembersCourseNode; import org.olat.group.BusinessGroupService; -import org.olat.modules.IModuleConfiguration; +import org.olat.modules.ModuleConfiguration; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryService; @@ -52,11 +52,11 @@ public class MembersHelpers { // ----------------------------------------------------- - public static void addCoaches(IModuleConfiguration moduleConfiguration, CourseGroupManager cgm, BusinessGroupService bgs, List<Identity> list) { + public static void addCoaches(ModuleConfiguration moduleConfiguration, CourseGroupManager cgm, BusinessGroupService bgs, List<Identity> list) { if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_COACHES_GROUP)) { - String coachGroupNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_GROUP); - List<Long> coachGroupKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_GROUP_ID); + String coachGroupNames = moduleConfiguration.getStringValue(MembersCourseNode.CONFIG_KEY_COACHES_GROUP); + List<Long> coachGroupKeys = moduleConfiguration.getList(MembersCourseNode.CONFIG_KEY_COACHES_GROUP_ID, Long.class); if(coachGroupKeys == null && StringHelper.containsNonWhitespace(coachGroupNames)) { coachGroupKeys = bgs.toGroupKeys(coachGroupNames, cgm.getCourseEntry()); } @@ -64,8 +64,8 @@ public class MembersHelpers { } if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_COACHES_AREA)) { - String coachAreaNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_AREA); - List<Long> coachAreaKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_AREA_IDS); + String coachAreaNames = moduleConfiguration.getStringValue(MembersCourseNode.CONFIG_KEY_COACHES_AREA); + List<Long> coachAreaKeys = moduleConfiguration.getList(MembersCourseNode.CONFIG_KEY_COACHES_AREA_IDS, Long.class); if(coachAreaKeys == null && StringHelper.containsNonWhitespace(coachAreaNames)) { coachAreaKeys = bgs.toGroupKeys(coachAreaNames, cgm.getCourseEntry()); } @@ -113,11 +113,11 @@ public class MembersHelpers { // ----------------------------------------------------- - public static void addParticipants(IModuleConfiguration moduleConfiguration, CourseGroupManager cgm, BusinessGroupService bgs, List<Identity> list) { + public static void addParticipants(ModuleConfiguration moduleConfiguration, CourseGroupManager cgm, BusinessGroupService bgs, List<Identity> list) { if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP)) { - String participantGroupNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP); - List<Long> participantGroupKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP_ID); + String participantGroupNames = moduleConfiguration.getStringValue(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP); + List<Long> participantGroupKeys = moduleConfiguration.getList(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP_ID, Long.class); if(participantGroupKeys == null && StringHelper.containsNonWhitespace(participantGroupNames)) { participantGroupKeys = bgs.toGroupKeys(participantGroupNames, cgm.getCourseEntry()); } @@ -125,8 +125,8 @@ public class MembersHelpers { } if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA)) { - String participantAreaNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA); - List<Long> participantAreaKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA_ID); + String participantAreaNames = moduleConfiguration.getStringValue(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA); + List<Long> participantAreaKeys = moduleConfiguration.getList(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA_ID, Long.class); if(participantAreaKeys == null && StringHelper.containsNonWhitespace(participantAreaNames)) { participantAreaKeys = bgs.toGroupKeys(participantAreaNames, cgm.getCourseEntry()); } diff --git a/src/main/java/org/olat/course/nodes/members/MembersPeekViewController.java b/src/main/java/org/olat/course/nodes/members/MembersPeekViewController.java index 0c36666a49001366cfff9335f0406529abc0a7bf..a905877408055c3981f84ef261d562b367332c1e 100644 --- a/src/main/java/org/olat/course/nodes/members/MembersPeekViewController.java +++ b/src/main/java/org/olat/course/nodes/members/MembersPeekViewController.java @@ -40,7 +40,6 @@ import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.run.environment.CourseEnvironment; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.group.BusinessGroupService; -import org.olat.modules.IModuleConfiguration; import org.olat.modules.ModuleConfiguration; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryService; @@ -105,12 +104,9 @@ public class MembersPeekViewController extends BasicController { }); putInitialPanel(tableController.getInitialComponent()); - } protected void readFormData(ModuleConfiguration config) { - IModuleConfiguration membersFrag = IModuleConfiguration.fragment("members", config); - CourseGroupManager cgm = courseEnv.getCourseGroupManager(); @@ -118,10 +114,10 @@ public class MembersPeekViewController extends BasicController { List<Identity> owners = MembersHelpers.getOwners(repositoryService, courseRepositoryEntry); List<Identity> coaches = new ArrayList<>(); - MembersHelpers.addCoaches(membersFrag, cgm, businessGroupService, coaches); + MembersHelpers.addCoaches(config, cgm, businessGroupService, coaches); List<Identity> participants = new ArrayList<>(); - MembersHelpers.addParticipants(membersFrag, cgm, businessGroupService, participants); + MembersHelpers.addParticipants(config, cgm, businessGroupService, participants); Set<Long> duplicateCatcher = new HashSet<Long>(); List<Identity> filteredOwners = owners.stream() @@ -154,9 +150,9 @@ public class MembersPeekViewController extends BasicController { }) .collect(Collectors.toList()); - entries.add(new Row(translate("members.owners"), Integer.toString(filteredOwners.size()))); - entries.add(new Row(translate("members.coaches"), Integer.toString(filteredCoaches.size()))); - entries.add(new Row(translate("members.participants"), Integer.toString(filteredParticipants.size()))); + entries.add(new Row(translate("members.owners"), Integer.toString(filteredOwners.size()))); + entries.add(new Row(translate("members.coaches"), Integer.toString(filteredCoaches.size()))); + entries.add(new Row(translate("members.participants"), Integer.toString(filteredParticipants.size()))); } @Override @@ -170,8 +166,8 @@ public class MembersPeekViewController extends BasicController { } private static class Row { - String col1; - String col2; + private String col1; + private String col2; public Row(String col1, String col2) { this.col1 = col1; this.col2 = col2; diff --git a/src/main/java/org/olat/course/editor/formfragments/MembersSelectorFormFragment.java b/src/main/java/org/olat/course/nodes/members/ui/group/MembersSelectorFormFragment.java similarity index 64% rename from src/main/java/org/olat/course/editor/formfragments/MembersSelectorFormFragment.java rename to src/main/java/org/olat/course/nodes/members/ui/group/MembersSelectorFormFragment.java index 4cb74f9071eaae0a7167eae378d9a70fcd8217ac..8cde17b8c72caa926dc744cdefe3be6f31575252 100644 --- a/src/main/java/org/olat/course/editor/formfragments/MembersSelectorFormFragment.java +++ b/src/main/java/org/olat/course/nodes/members/ui/group/MembersSelectorFormFragment.java @@ -17,7 +17,7 @@ * frentix GmbH, http://www.frentix.com * <p> */ -package org.olat.course.editor.formfragments; +package org.olat.course.nodes.members.ui.group; import java.util.ArrayList; import java.util.List; @@ -25,18 +25,18 @@ import java.util.List; 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.FormLink; import org.olat.core.gui.components.form.flexible.elements.SelectionElement; import org.olat.core.gui.components.form.flexible.elements.SingleSelection; import org.olat.core.gui.components.form.flexible.elements.StaticTextElement; -import org.olat.core.gui.components.form.flexible.impl.BasicFormFragment; +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.components.form.flexible.impl.IFormFragment; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController; import org.olat.core.util.StringHelper; +import org.olat.core.util.Util; import org.olat.course.condition.AreaSelectionController; import org.olat.course.condition.GroupSelectionController; import org.olat.course.editor.CourseEditorEnv; @@ -44,7 +44,7 @@ import org.olat.group.BusinessGroupService; import org.olat.group.BusinessGroupShort; import org.olat.group.area.BGArea; import org.olat.group.area.BGAreaManager; -import org.olat.modules.IModuleConfiguration; +import org.olat.modules.ModuleConfiguration; import org.springframework.beans.factory.annotation.Autowired; /** @@ -52,26 +52,8 @@ import org.springframework.beans.factory.annotation.Autowired; * * <p>Initial date: May 6, 2016<br> * @author lmihalkovic, http://www.frentix.com - * @see IFormFragment */ -public class MembersSelectorFormFragment extends BasicFormFragment { - - public static final String CONFIG_KEY_COACHES_GROUP = "GroupCoaches"; - public static final String CONFIG_KEY_COACHES_AREA = "AreaCoaches"; - public static final String CONFIG_KEY_COACHES_GROUP_ID = "GroupCoachesIds"; - public static final String CONFIG_KEY_COACHES_AREA_IDS = "AreaCoachesIds"; - public static final String CONFIG_KEY_COACHES_COURSE = "CourseCoaches"; - public static final String CONFIG_KEY_COACHES_ALL = "CoachesAll"; - - public static final String CONFIG_KEY_PARTICIPANTS_GROUP = "GroupParticipants"; - public static final String CONFIG_KEY_PARTICIPANTS_AREA = "AreaParticipants"; - public static final String CONFIG_KEY_PARTICIPANTS_GROUP_ID = "GroupParticipantsIds"; - public static final String CONFIG_KEY_PARTICIPANTS_AREA_ID = "AreaParticipantsIds"; - public static final String CONFIG_KEY_PARTICIPANTS_COURSE = "CourseParticipants"; - public static final String CONFIG_KEY_PARTICIPANTS_ALL = "ParticipantsAll"; - - - private final CourseEditorEnv cev; +public abstract class MembersSelectorFormFragment extends FormBasicController { // Coaches private SelectionElement wantCoaches; @@ -99,49 +81,58 @@ public class MembersSelectorFormFragment extends BasicFormFragment { // Popup form private CloseableModalController cmc; - - @Autowired private BGAreaManager areaManager; @Autowired private BusinessGroupService businessGroupService; + + private final CourseEditorEnv cev; + protected final ModuleConfiguration config; - public MembersSelectorFormFragment(CourseEditorEnv cev) { + public MembersSelectorFormFragment(UserRequest ureq, WindowControl wControl, + CourseEditorEnv cev, ModuleConfiguration config) { + super(ureq, wControl, Util.createPackageTranslator(MembersSelectorFormFragment.class, ureq.getLocale())); this.cev = cev; + this.config = config; + initForm(ureq); + validateFormLogic(ureq); } @Override - protected void initFormFragment(FormItemContainer formLayout, Controller listener, UserRequest ureq, IModuleConfiguration config) { - FormUIFactory uifactory = uifactory(); - - // ---------------------------------------------------------------------- -// Boolean ownerSelection = config.getBooleanSafe(CONFIG_KEY_OWNERS); - Boolean coacheSelection = config.getBooleanSafe(CONFIG_KEY_COACHES_ALL) || config.getBooleanSafe(CONFIG_KEY_COACHES_COURSE) || config.get(CONFIG_KEY_COACHES_GROUP) != null || config.get(CONFIG_KEY_COACHES_AREA) != null; + protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { + + Boolean coacheSelection = config.getBooleanSafe(getConfigKeyCoachesAll()) + || config.getBooleanSafe(getConfigKeyCoachesCourse()) + || config.get(getConfigKeyCoachesGroup()) != null + || config.get(getConfigKeyCoachesArea()) != null; - // COACHES: from course or groups wantCoaches = uifactory.addCheckboxesHorizontal("coaches", "message.want.coaches", formLayout, new String[]{"xx"},new String[]{null}); - wantCoaches.setTranslator(host.getFragmentTranslator()); - if(coacheSelection != null && coacheSelection) wantCoaches.select("xx", true); - + if(coacheSelection != null && coacheSelection) { + wantCoaches.select("xx", true); + } wantCoaches.addActionListener(FormEvent.ONCLICK); - coachesChoice = uifactory.addRadiosVertical( - "coachesChoice", null, formLayout, + coachesChoice = uifactory.addRadiosVertical("coachesChoice", null, formLayout, new String[]{"all", "course", "group"}, - new String[]{host.getFragmentTranslator().translate("form.message.coaches.all"), host.getFragmentTranslator().translate("form.message.coaches.course"), host.getFragmentTranslator().translate("form.message.coaches.group")} + new String[]{ translate("form.message.coaches.all"), translate("form.message.coaches.course"), translate("form.message.coaches.group")} ); - if(config.getBooleanSafe(CONFIG_KEY_COACHES_ALL)) coachesChoice.select("all", true); - if(config.getBooleanSafe(CONFIG_KEY_COACHES_COURSE)) coachesChoice.select("course", true); - if(config.get(CONFIG_KEY_COACHES_GROUP) != null || config.get(CONFIG_KEY_COACHES_AREA) != null) coachesChoice.select("group", true); + if(config.getBooleanSafe(getConfigKeyCoachesAll())) { + coachesChoice.select("all", true); + } + if(config.getBooleanSafe(getConfigKeyCoachesCourse())) { + coachesChoice.select("course", true); + } + if(config.get(getConfigKeyCoachesGroup()) != null || config.get(getConfigKeyCoachesArea()) != null) { + coachesChoice.select("group", true); + } coachesChoice.addActionListener(FormEvent.ONCLICK); coachesChoice.setVisible(false); chooseGroupCoachesLink = uifactory.addFormLink("groupCoachesChoose", formLayout, "btn btn-default o_xsmall o_form_groupchooser"); - chooseGroupCoachesLink.setTranslator(host.getFragmentTranslator()); chooseGroupCoachesLink.setIconLeftCSS("o_icon o_icon-fw o_icon_group"); chooseGroupCoachesLink.setVisible(false); chooseGroupCoachesLink.setLabel("form.message.group", null); @@ -152,23 +143,20 @@ public class MembersSelectorFormFragment extends BasicFormFragment { chooseGroupCoachesLink.setElementCssClass("o_omit_margin"); String groupCoachesInitVal; - @SuppressWarnings("unchecked") - List<Long> groupCoachesKeys = (List<Long>)config.get(CONFIG_KEY_COACHES_GROUP_ID); + List<Long> groupCoachesKeys = config.getList(getConfigKeyCoachesGroupIds(), Long.class); if(groupCoachesKeys == null) { - groupCoachesInitVal = config.getAs(CONFIG_KEY_COACHES_GROUP); + groupCoachesInitVal = config.getStringValue(getConfigKeyCoachesGroup()); groupCoachesKeys = businessGroupService.toGroupKeys(groupCoachesInitVal, cev.getCourseGroupManager().getCourseEntry()); } groupCoachesInitVal = getGroupNames(groupCoachesKeys); easyGroupCoachSelectionList = uifactory.addStaticTextElement("groupCoaches", null, groupCoachesInitVal, formLayout); - easyGroupCoachSelectionList.setTranslator(host.getFragmentTranslator()); easyGroupCoachSelectionList.setUserObject(groupCoachesKeys); easyGroupCoachSelectionList.setVisible(false); easyGroupCoachSelectionList.setElementCssClass("text-muted"); chooseAreasCoachesLink = uifactory.addFormLink("areaCoachesChoose", formLayout, "btn btn-default o_xsmall o_form_areachooser"); - chooseAreasCoachesLink.setTranslator(host.getFragmentTranslator()); chooseAreasCoachesLink.setIconLeftCSS("o_icon o_icon-fw o_icon_courseareas"); chooseAreasCoachesLink.setLabel("form.message.area", null); chooseAreasCoachesLink.setElementCssClass("o_omit_margin"); @@ -177,42 +165,47 @@ public class MembersSelectorFormFragment extends BasicFormFragment { } String areaCoachesInitVal; - @SuppressWarnings("unchecked") - List<Long> areaCoachesKeys = (List<Long>)config.get(CONFIG_KEY_COACHES_AREA_IDS); + List<Long> areaCoachesKeys = config.getList(getConfigKeyCoachesAreaIds(), Long.class); if(areaCoachesKeys == null) { - areaCoachesInitVal = (String)config.get(CONFIG_KEY_COACHES_AREA); + areaCoachesInitVal = (String)config.get(getConfigKeyCoachesArea()); areaCoachesKeys = areaManager.toAreaKeys(areaCoachesInitVal, cev.getCourseGroupManager().getCourseResource()); } areaCoachesInitVal = getAreaNames(areaCoachesKeys); easyAreaCoachSelectionList = uifactory.addStaticTextElement("areaCoaches", null, areaCoachesInitVal, formLayout); - easyAreaCoachSelectionList.setTranslator(host.getFragmentTranslator()); easyAreaCoachSelectionList.setUserObject(areaCoachesKeys); easyAreaCoachSelectionList.setVisible(false); easyAreaCoachSelectionList.setElementCssClass("text-muted"); // PARTICIPANTS: from course or groups - Boolean particiapntSelection = config.getBooleanSafe(CONFIG_KEY_PARTICIPANTS_ALL) || config.getBooleanSafe(CONFIG_KEY_PARTICIPANTS_COURSE) || config.get(CONFIG_KEY_PARTICIPANTS_GROUP) != null || config.get(CONFIG_KEY_PARTICIPANTS_AREA) != null; + Boolean particiapntSelection = config.getBooleanSafe(getConfigKeyParticipantsAll()) + || config.getBooleanSafe(getConfigKeyParticipantsCourse()) + || config.get(getConfigKeyParticipantsGroup()) != null + || config.get(getConfigKeyParticipantsArea()) != null; wantParticipants = uifactory.addCheckboxesHorizontal("participants", "message.want.participants", formLayout, new String[]{"xx"},new String[]{null}); - wantParticipants.setTranslator(host.getFragmentTranslator()); if(particiapntSelection != null && particiapntSelection) wantParticipants.select("xx", true); wantParticipants.addActionListener(FormEvent.ONCLICK); participantsChoice = uifactory.addRadiosVertical( "participantsChoice", null, formLayout, - new String[]{"all", "course", "group"}, - new String[]{host.getFragmentTranslator().translate("form.message.participants.all"), host.getFragmentTranslator().translate("form.message.participants.course"), host.getFragmentTranslator().translate("form.message.participants.group")} + new String[]{ "all", "course", "group" }, + new String[]{ translate("form.message.participants.all"), translate("form.message.participants.course"), translate("form.message.participants.group")} ); - if(config.getBooleanSafe(CONFIG_KEY_PARTICIPANTS_ALL)) participantsChoice.select("all", true); - if(config.getBooleanSafe(CONFIG_KEY_PARTICIPANTS_COURSE)) participantsChoice.select("course", true); - if(config.get(CONFIG_KEY_PARTICIPANTS_GROUP) != null || config.get(CONFIG_KEY_PARTICIPANTS_AREA) != null) participantsChoice.select("group", true); + if(config.getBooleanSafe(getConfigKeyParticipantsAll())) { + participantsChoice.select("all", true); + } + if(config.getBooleanSafe(getConfigKeyParticipantsCourse())) { + participantsChoice.select("course", true); + } + if(config.get(getConfigKeyParticipantsGroup()) != null || config.get(getConfigKeyParticipantsArea()) != null) { + participantsChoice.select("group", true); + } participantsChoice.addActionListener(FormEvent.ONCLICK); participantsChoice.setVisible(false); chooseGroupParticipantsLink = uifactory.addFormLink("groupParticipantsChoose", formLayout, "btn btn-default o_xsmall o_form_groupchooser"); - chooseGroupParticipantsLink.setTranslator(host.getFragmentTranslator()); chooseGroupParticipantsLink.setIconLeftCSS("o_icon o_icon-fw o_icon_group"); chooseGroupParticipantsLink.setVisible(false); chooseGroupParticipantsLink.setLabel("form.message.group", null); @@ -223,23 +216,20 @@ public class MembersSelectorFormFragment extends BasicFormFragment { } String groupParticipantsInitVal; - @SuppressWarnings("unchecked") - List<Long> groupParticipantsKeys = (List<Long>)config.get(CONFIG_KEY_PARTICIPANTS_GROUP_ID); + List<Long> groupParticipantsKeys = config.getList(getConfigKeyParticipantsGroupIds(), Long.class); if(groupParticipantsKeys == null) { - groupParticipantsInitVal = (String)config.get(CONFIG_KEY_PARTICIPANTS_GROUP); + groupParticipantsInitVal = (String)config.get(getConfigKeyParticipantsGroup()); groupParticipantsKeys = businessGroupService.toGroupKeys(groupParticipantsInitVal, cev.getCourseGroupManager().getCourseEntry()); } groupParticipantsInitVal = getGroupNames(groupParticipantsKeys); easyGroupParticipantsSelectionList = uifactory.addStaticTextElement("groupParticipants", null, groupParticipantsInitVal, formLayout); - easyGroupParticipantsSelectionList.setTranslator(host.getFragmentTranslator()); easyGroupParticipantsSelectionList.setUserObject(groupParticipantsKeys); easyGroupParticipantsSelectionList.setVisible(false); easyGroupParticipantsSelectionList.setElementCssClass("text-muted"); chooseAreasParticipantsLink = uifactory.addFormLink("areaParticipantsChoose", formLayout, "btn btn-default o_xsmall o_form_areachooser"); - chooseAreasParticipantsLink.setTranslator(host.getFragmentTranslator()); chooseAreasParticipantsLink.setIconLeftCSS("o_icon o_icon-fw o_icon_courseareas"); chooseAreasParticipantsLink.setVisible(false); chooseAreasParticipantsLink.setLabel("form.message.area", null); @@ -250,31 +240,22 @@ public class MembersSelectorFormFragment extends BasicFormFragment { } String areaParticipantsInitVal; - @SuppressWarnings("unchecked") - List<Long> areaParticipantsKeys = (List<Long>)config.get(CONFIG_KEY_PARTICIPANTS_AREA_ID); + List<Long> areaParticipantsKeys = config.getList(getConfigKeyParticipantsAreaIds(), Long.class); if(areaParticipantsKeys == null) { - areaParticipantsInitVal = (String)config.get(CONFIG_KEY_PARTICIPANTS_AREA); + areaParticipantsInitVal = (String)config.get(getConfigKeyParticipantsArea()); areaParticipantsKeys = areaManager.toAreaKeys(areaParticipantsInitVal, cev.getCourseGroupManager().getCourseResource()); } areaParticipantsInitVal = getAreaNames(areaParticipantsKeys); easyAreaParticipantsSelectionList = uifactory.addStaticTextElement("areaParticipants", null, areaParticipantsInitVal, formLayout); - easyAreaParticipantsSelectionList.setTranslator(host.getFragmentTranslator()); easyAreaParticipantsSelectionList.setUserObject(areaParticipantsKeys); easyAreaParticipantsSelectionList.setVisible(false); easyAreaParticipantsSelectionList.setElementCssClass("text-muted"); - uifactory.addSpacerElement("s4", formLayout, false); - -// update(); - } - - @Override - public void refreshContents() { - update(); + uifactory.addSpacerElement("s4", formLayout, false); } - private void update () { + protected void update() { coachesChoice.setVisible(wantCoaches.isSelected(0)); chooseGroupCoachesLink.setVisible(coachesChoice.isSelected(2) && wantCoaches.isSelected(0)); chooseAreasCoachesLink.setVisible(coachesChoice.isSelected(2) && wantCoaches.isSelected(0)); @@ -295,11 +276,11 @@ public class MembersSelectorFormFragment extends BasicFormFragment { coachesChoice.clearError(); participantsChoice.clearError(); - container.setNeedsLayout(); + setNeedsLayout(); } @Override - public boolean validateFormLogic(UserRequest ureq) { + protected boolean validateFormLogic(UserRequest ureq) { boolean isOK = true; if(sendToCoaches()){ @@ -336,6 +317,12 @@ public class MembersSelectorFormFragment extends BasicFormFragment { return isOK; } + @Override + protected final void formOK(UserRequest ureq) { + storeConfiguration(config); + fireEvent(ureq, Event.DONE_EVENT); + } + private String getGroupNames(List<Long> keys) { StringBuilder sb = new StringBuilder(); List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(keys); @@ -359,96 +346,90 @@ public class MembersSelectorFormFragment extends BasicFormFragment { } @Override - public void dispose() { + protected void doDispose() { // nothing at the moment } @Override - public boolean processFormEvent(UserRequest ureq, FormItem source, FormEvent event) { - boolean processed = false; - + protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { if (source == chooseGroupCoachesLink) { - host.getFragmentController().removeAsListenerAndDispose(cmc); - host.getFragmentController().removeAsListenerAndDispose(groupChooseCoaches); + removeAsListenerAndDispose(cmc); + removeAsListenerAndDispose(groupChooseCoaches); - groupChooseCoaches = new GroupSelectionController(ureq, host.getFragmentController().getWindowControl(), true, + groupChooseCoaches = new GroupSelectionController(ureq, getWindowControl(), true, cev.getCourseGroupManager(), getKeys(easyGroupCoachSelectionList)); - host.getFragmentController().listenTo(groupChooseCoaches); + listenTo(groupChooseCoaches); String title = chooseGroupCoachesLink.getLinkTitleText(); - cmc = new CloseableModalController(host.getFragmentController().getWindowControl(), "close", groupChooseCoaches.getInitialComponent(), true, title); - host.getFragmentController().listenTo(cmc); + cmc = new CloseableModalController(getWindowControl(), "close", groupChooseCoaches.getInitialComponent(), true, title); + listenTo(cmc); cmc.activate(); - host.getFragmentController().setFormCanSubmit(false); - processed = true; + setFormCanSubmit(false); } else if(source == chooseGroupParticipantsLink){ - host.getFragmentController().removeAsListenerAndDispose(cmc); - host.getFragmentController().removeAsListenerAndDispose(groupChooseParticipants); + removeAsListenerAndDispose(cmc); + removeAsListenerAndDispose(groupChooseParticipants); - groupChooseParticipants = new GroupSelectionController(ureq, host.getFragmentController().getWindowControl(), true, + groupChooseParticipants = new GroupSelectionController(ureq, getWindowControl(), true, cev.getCourseGroupManager(), getKeys(easyGroupParticipantsSelectionList)); - host.getFragmentController().listenTo(groupChooseParticipants); + listenTo(groupChooseParticipants); String title = chooseGroupParticipantsLink.getLabelText(); - cmc = new CloseableModalController(host.getFragmentController().getWindowControl(), "close", groupChooseParticipants.getInitialComponent(), true, title); - host.getFragmentController().listenTo(cmc); + cmc = new CloseableModalController(getWindowControl(), "close", groupChooseParticipants.getInitialComponent(), true, title); + listenTo(cmc); cmc.activate(); - host.getFragmentController().setFormCanSubmit(false); - processed = true; + setFormCanSubmit(false); } else if (source == chooseAreasCoachesLink) { // already areas -> choose areas - host.getFragmentController().removeAsListenerAndDispose(cmc); - host.getFragmentController().removeAsListenerAndDispose(areaChooseCoaches); + removeAsListenerAndDispose(cmc); + removeAsListenerAndDispose(areaChooseCoaches); - areaChooseCoaches = new AreaSelectionController (ureq, host.getFragmentController().getWindowControl(), true, + areaChooseCoaches = new AreaSelectionController (ureq, getWindowControl(), true, cev.getCourseGroupManager(), getKeys(easyAreaCoachSelectionList)); - host.getFragmentController().listenTo(areaChooseCoaches); + listenTo(areaChooseCoaches); String title = chooseAreasCoachesLink.getLinkTitleText(); - cmc = new CloseableModalController(host.getFragmentController().getWindowControl(), "close", areaChooseCoaches.getInitialComponent(), true, title); - host.getFragmentController().listenTo(cmc); + cmc = new CloseableModalController(getWindowControl(), "close", areaChooseCoaches.getInitialComponent(), true, title); + listenTo(cmc); cmc.activate(); - host.getFragmentController().setFormCanSubmit(false); - processed = true; + setFormCanSubmit(false); } else if (source == chooseAreasParticipantsLink){ // already areas -> choose areas - host.getFragmentController().removeAsListenerAndDispose(cmc); - host.getFragmentController().removeAsListenerAndDispose(areaChooseParticipants); + removeAsListenerAndDispose(cmc); + removeAsListenerAndDispose(areaChooseParticipants); - areaChooseParticipants = new AreaSelectionController (ureq, host.getFragmentController().getWindowControl(), true, + areaChooseParticipants = new AreaSelectionController (ureq, getWindowControl(), true, cev.getCourseGroupManager(), getKeys(easyAreaParticipantsSelectionList)); - host.getFragmentController().listenTo(areaChooseParticipants); + listenTo(areaChooseParticipants); String title = chooseAreasParticipantsLink.getLabelText(); - cmc = new CloseableModalController(host.getFragmentController().getWindowControl(), "close", areaChooseParticipants.getInitialComponent(), true, title); - host.getFragmentController().listenTo(cmc); + cmc = new CloseableModalController(getWindowControl(), "close", areaChooseParticipants.getInitialComponent(), true, title); + listenTo(cmc); cmc.activate(); - host.getFragmentController().setFormCanSubmit(false); - processed = true; - } - - return processed; + setFormCanSubmit(false); + } } + + protected abstract void setFormCanSubmit(boolean enable); protected void cleanUp() { - host.getFragmentController().removeAsListenerAndDispose(cmc); - host.getFragmentController().removeAsListenerAndDispose(areaChooseParticipants); - host.getFragmentController().removeAsListenerAndDispose(areaChooseCoaches); - host.getFragmentController().removeAsListenerAndDispose(groupChooseCoaches); + removeAsListenerAndDispose(cmc); + removeAsListenerAndDispose(areaChooseParticipants); + removeAsListenerAndDispose(areaChooseCoaches); + removeAsListenerAndDispose(groupChooseCoaches); } + @Override - public boolean processEvent(UserRequest ureq, Controller source, Event event) { + protected void event(UserRequest ureq, Controller source, Event event) { + setFormCanSubmit(true); - host.getFragmentController().setFormCanSubmit(true); -// subm.setEnabled(true); if (source == groupChooseCoaches) { if (event == Event.DONE_EVENT) { cmc.deactivate(); easyGroupCoachSelectionList.setValue(getGroupNames(groupChooseCoaches.getSelectedKeys())); easyGroupCoachSelectionList.setUserObject(groupChooseCoaches.getSelectedKeys()); chooseGroupCoachesLink.setI18nKey("groupCoachesChoose"); - container.setNeedsLayout(); + setNeedsLayout(); } else if (Event.CANCELLED_EVENT == event) { cmc.deactivate(); } @@ -458,7 +439,7 @@ public class MembersSelectorFormFragment extends BasicFormFragment { easyAreaCoachSelectionList.setValue(getAreaNames(areaChooseCoaches.getSelectedKeys())); easyAreaCoachSelectionList.setUserObject(areaChooseCoaches.getSelectedKeys()); chooseAreasCoachesLink.setI18nKey("areaCoachesChoose"); - container.setNeedsLayout(); + setNeedsLayout(); } else if (event == Event.CANCELLED_EVENT) { cmc.deactivate(); } @@ -468,7 +449,7 @@ public class MembersSelectorFormFragment extends BasicFormFragment { easyGroupParticipantsSelectionList.setValue(getGroupNames(groupChooseParticipants.getSelectedKeys())); easyGroupParticipantsSelectionList.setUserObject(groupChooseParticipants.getSelectedKeys()); chooseGroupParticipantsLink.setI18nKey("groupParticipantsChoose"); - container.setNeedsLayout(); + setNeedsLayout(); } else if (Event.CANCELLED_EVENT == event) { cmc.deactivate(); } @@ -478,13 +459,11 @@ public class MembersSelectorFormFragment extends BasicFormFragment { easyAreaParticipantsSelectionList.setValue(getAreaNames(areaChooseParticipants.getSelectedKeys())); easyAreaParticipantsSelectionList.setUserObject(areaChooseParticipants.getSelectedKeys()); chooseAreasParticipantsLink.setI18nKey("areaParticipantsChoose"); - container.setNeedsLayout(); + setNeedsLayout(); } else if (event == Event.CANCELLED_EVENT) { cmc.deactivate(); } } - - return false; } private List<Long> getKeys(StaticTextElement element) { @@ -564,7 +543,7 @@ public class MembersSelectorFormFragment extends BasicFormFragment { } protected boolean sendToCoachesAll(){ - return coachesChoice.isSelected(0)&& wantCoaches.isSelected(0); + return coachesChoice.isSelected(0) && wantCoaches.isSelected(0); } protected boolean sendToCoachesGroup(){ @@ -572,11 +551,11 @@ public class MembersSelectorFormFragment extends BasicFormFragment { } protected boolean sendToParticipantsCourse(){ - return participantsChoice.isSelected(1)&& wantParticipants.isSelected(0); + return participantsChoice.isSelected(1) && wantParticipants.isSelected(0); } protected boolean sendToParticipantsAll(){ - return participantsChoice.isSelected(0)&& wantParticipants.isSelected(0); + return participantsChoice.isSelected(0) && wantParticipants.isSelected(0); } protected boolean sendToParticipantsGroup(){ @@ -598,22 +577,37 @@ public class MembersSelectorFormFragment extends BasicFormFragment { return false; } - @Override - public void storeConfiguration(UserRequest ureq, IModuleConfiguration moduleConfiguration) { - MembersSelectorFormFragment configForm = this; - moduleConfiguration.set(CONFIG_KEY_COACHES_GROUP, configForm.getGroupCoaches()); - moduleConfiguration.set(CONFIG_KEY_COACHES_GROUP_ID, configForm.getGroupCoachesIds()); - moduleConfiguration.set(CONFIG_KEY_COACHES_AREA, configForm.getCoachesAreas()); - moduleConfiguration.set(CONFIG_KEY_COACHES_AREA_IDS, configForm.getCoachesAreaIds()); - moduleConfiguration.setBooleanEntry(CONFIG_KEY_COACHES_ALL, configForm.sendToCoachesAll()); - moduleConfiguration.setBooleanEntry(CONFIG_KEY_COACHES_COURSE, configForm.sendToCoachesCourse()); + protected void storeConfiguration(ModuleConfiguration config) { + config.set(getConfigKeyCoachesGroup(), getGroupCoaches()); + config.set(getConfigKeyCoachesGroupIds(), getGroupCoachesIds()); + config.set(getConfigKeyCoachesArea(), getCoachesAreas()); + config.set(getConfigKeyCoachesAreaIds(), getCoachesAreaIds()); + config.setBooleanEntry(getConfigKeyCoachesAll(), sendToCoachesAll()); + config.setBooleanEntry(getConfigKeyCoachesCourse(), sendToCoachesCourse()); - moduleConfiguration.set(CONFIG_KEY_PARTICIPANTS_GROUP, configForm.getGroupParticipants()); - moduleConfiguration.set(CONFIG_KEY_PARTICIPANTS_GROUP_ID, configForm.getGroupParticipantsIds()); - moduleConfiguration.set(CONFIG_KEY_PARTICIPANTS_AREA, configForm.getParticipantsAreas()); - moduleConfiguration.set(CONFIG_KEY_PARTICIPANTS_AREA_ID, configForm.getParticipantsAreaIds()); - moduleConfiguration.setBooleanEntry(CONFIG_KEY_PARTICIPANTS_ALL, configForm.sendToParticipantsAll()); - moduleConfiguration.setBooleanEntry(CONFIG_KEY_PARTICIPANTS_COURSE, configForm.sendToParticipantsCourse()); + config.set(getConfigKeyParticipantsGroup(), getGroupParticipants()); + config.set(getConfigKeyParticipantsGroupIds(), getGroupParticipantsIds()); + config.set(getConfigKeyParticipantsArea(), getParticipantsAreas()); + config.set(getConfigKeyParticipantsAreaIds(), getParticipantsAreaIds()); + config.setBooleanEntry(getConfigKeyParticipantsAll(), sendToParticipantsAll()); + config.setBooleanEntry(getConfigKeyParticipantsCourse(), sendToParticipantsCourse()); } + + protected abstract String getConfigKeyCoachesGroup(); + protected abstract String getConfigKeyCoachesGroupIds(); + + protected abstract String getConfigKeyCoachesArea(); + protected abstract String getConfigKeyCoachesAreaIds(); + + protected abstract String getConfigKeyCoachesCourse(); + protected abstract String getConfigKeyCoachesAll(); + protected abstract String getConfigKeyParticipantsGroup(); + protected abstract String getConfigKeyParticipantsArea(); + + protected abstract String getConfigKeyParticipantsGroupIds(); + protected abstract String getConfigKeyParticipantsAreaIds(); + + protected abstract String getConfigKeyParticipantsCourse(); + protected abstract String getConfigKeyParticipantsAll(); } diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_ar.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_ar.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_ar.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_ar.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_bg.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_bg.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_bg.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_bg.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_cs.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_cs.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_cs.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_cs.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_da.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_da.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_da.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_da.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_de.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_de.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_de.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_el.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_el.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_el.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_el.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_en.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_en.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_en.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_es.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_es.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_es.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_es.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_fa.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_fa.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_fa.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_fa.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_fr.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_fr.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_fr.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_fr.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_it.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_it.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_it.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_it.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_jp.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_jp.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_jp.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_jp.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_lt.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_lt.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_lt.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_lt.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_nl_NL.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_nl_NL.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_nl_NL.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_nl_NL.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_pl.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_pl.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_pl.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_pl.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_pt_BR.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_pt_BR.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_pt_BR.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_pt_BR.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_pt_PT.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_pt_PT.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_pt_PT.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_pt_PT.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_ru.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_ru.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_ru.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_ru.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_sq.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_sq.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_sq.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_sq.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_zh_CN.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_zh_CN.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_zh_CN.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_zh_CN.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_zh_TW.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_zh_TW.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/LocalStrings_zh_TW.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/LocalStrings_zh_TW.properties diff --git a/src/main/java/org/olat/course/editor/formfragments/_i18n/i18nBundleMetadata.properties b/src/main/java/org/olat/course/nodes/members/ui/group/_i18n/i18nBundleMetadata.properties similarity index 100% rename from src/main/java/org/olat/course/editor/formfragments/_i18n/i18nBundleMetadata.properties rename to src/main/java/org/olat/course/nodes/members/ui/group/_i18n/i18nBundleMetadata.properties diff --git a/src/main/java/org/olat/modules/IModuleConfiguration.java b/src/main/java/org/olat/modules/IModuleConfiguration.java deleted file mode 100644 index 494d12ec3d36a8a0ef7a618f2154c1d495d8250a..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/modules/IModuleConfiguration.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * <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.modules; - -import org.olat.modules.ModuleProperty.ModulePropertyValue; - -/** - * A simple interface for dealing with sets of key/value pairs supporting the following - * <ul> - * <li>subsets based on a common key prefix (eg: sendToUsers, sendToOwners --> prefix: sendTo) - * <li>strongly typed properties (the definition of "keyName" is associated with a java type) - * </ul> - * - * <p>Initial date: May 6, 2016 - * @author lmihalkovic, http://www.frentix.com - */ -public interface IModuleConfiguration { - - /** - * Factory method for creating a {@link IModuleConfiguration} instance with a given - * property name prefix, backed by a given instance of {@link ModuleConfiguration}. - * This method allows a custom prefix/name separator to be specified. Passing {@code null} - * as a separator is equivalent to passing an empty string {@code ""}. - * - * @param fragmentName - * @param sep - * @param config - * @return - */ - public static IModuleConfiguration fragment(String fragmentName, String sep, ModuleConfiguration config) { - return new ModuleconfigurationFragment(fragmentName, sep, config); - } - - /** - * Factory method for creating a {@link IModuleConfiguration} instance with a given - * property name prefix, backed by a given instance of {@link ModuleConfiguration}. - * By default the property name will follow the pattern: prefix_XXXXX, where XXXXX - * is the name passed as a parameter to the methods in this interface - * - * - * @param fragmentName - * @param config - * @return - */ - public static IModuleConfiguration fragment(String fragmentName, ModuleConfiguration config) { - return new ModuleconfigurationFragment(fragmentName, "_", config); - } - - // ------------------------------------------------------------------------ - - public default boolean has(String configKey) { - return get(configKey) != null; - } - - public default boolean hasAnyOf(String...configKeys) { - for(String key : configKeys) { - if (get(key) != null) return true; - } - return false; - } - - public default boolean allTrue(String... configKeys) { - boolean rc = false; - for(String key : configKeys) { - rc = rc & getBooleanSafe(key); - if (!rc) break; - } - return rc; - } - - public default boolean anyTrue(String... configKeys) { - boolean rc = false; - for(String key : configKeys) { - rc = getBooleanSafe(key); - if (rc) break; - } - return rc; - } - - - public boolean getBooleanSafe(String configKey); - public void setBooleanEntry(String configKey, boolean value); - - public void set(String configKey, Object value); - public Object get(String configKey); - @SuppressWarnings("unchecked") - default public <T> T getAs(String configKey) { - Object val = get(configKey); - return val != null ? (T)val : null; - } - - - // ------------------------------------------------------------------------ - // Strongly typed API - - public <X> ModulePropertyValue<X> get(ModuleProperty<X> key); - public default <X> X val(ModuleProperty<X> key) { - return get(key).val(); - } - public <X> void set(ModulePropertyValue<X> value); - public <X> void set(ModuleProperty<X> key, X value); - - public default boolean has(ModuleProperty<?> key) { - ModulePropertyValue<?> val = get(key); - return val.isSet(); - } - - public boolean hasAnyOf(ModuleProperty<?>...keys); - - public boolean anyTrue(ModuleProperty<Boolean> key); - public boolean anyTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2); - public boolean anyTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3); - public boolean anyTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3, ModuleProperty<Boolean> key4); - public boolean anyTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3, ModuleProperty<Boolean> key4, ModuleProperty<Boolean> key5); - - public boolean allTrue(ModuleProperty<Boolean> key); - public boolean allTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2); - public boolean allTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3); - public boolean allTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3, ModuleProperty<Boolean> key4); - public boolean allTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3, ModuleProperty<Boolean> key4, ModuleProperty<Boolean> key5); - -} diff --git a/src/main/java/org/olat/modules/ModuleConfiguration.java b/src/main/java/org/olat/modules/ModuleConfiguration.java index b434bcec3521ef6d39baea5fc3c8b6e78cc870e2..b39f383316bb53d3379ba470129df8df0942db05 100644 --- a/src/main/java/org/olat/modules/ModuleConfiguration.java +++ b/src/main/java/org/olat/modules/ModuleConfiguration.java @@ -238,7 +238,7 @@ public class ModuleConfiguration implements Serializable { } } - public <U> List<U> getList(String config_key, Class<U> cl) { + public <U> List<U> getList(String config_key, @SuppressWarnings("unused") Class<U> cl) { @SuppressWarnings("unchecked") List<U> list = (List<U>)get(config_key); if(list == null) { @@ -254,6 +254,33 @@ public class ModuleConfiguration implements Serializable { set(config_key, list); } } + + public boolean has(String configKey) { + return get(configKey) != null; + } + + public boolean anyTrue(String... keys) { + if(keys != null && keys.length > 0) { + for(int i=keys.length; i-->0; ) { + if(getBooleanSafe(keys[i])) { + return true; + } + } + } + return false; + } + + public boolean hasAnyOf(String... keys) { + if(keys != null && keys.length > 0) { + for(int i=keys.length; i-->0; ) { + if(get(keys[i]) != null) { + return true; + } + } + } + return false; + } + /** * Get the version of this module configuration. The version specifies which diff --git a/src/main/java/org/olat/modules/ModuleProperty.java b/src/main/java/org/olat/modules/ModuleProperty.java deleted file mode 100644 index 6c66c2968fdb03a9a5523ab70cc5b4cbc994b961..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/modules/ModuleProperty.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * <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.modules; - -import java.lang.reflect.Array; -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.lang.reflect.WildcardType; - -/** - * A simple implementation of a strongly typed named property - * - * <p>Initial date: May 6, 2016 - * @author lmihalkovic, http://www.frentix.com - */ -public abstract class ModuleProperty<T> { - - /** - * A strongly typed property value - * - * Initial date: May 6, 2016<br> - * @author lmihalkovic, http://www.frentix.com - * - */ - public static final class ModulePropertyValue<X> { - private X value; - private final ModuleProperty<X> def; - protected ModulePropertyValue(X value, ModuleProperty<X> def) { - this.value = value; - this.def = def; - } - public X val() { - if(!isSet()) return getDefault(); - return value; - } - public void val(X val) { - this.value = val; - } - public X getDefault() { - return def.getDefault(); - } - public boolean isSet() { - return this.value != null; - } - public String name() { - return def.name; - } - } - - private final String name; - private final T defaultValue; - private final Type type; - - public ModuleProperty(String name) { - this(name, null); - } - - public ModuleProperty(String name, T defaultValue) { - this.name = name; - this.defaultValue = defaultValue; - this.type = getType(); - } - - public ModulePropertyValue<T> val(T value) { - return new ModulePropertyValue<T>(value, this); - } - - public String name() { - return this.name; - } - - public boolean hasDefault() { - return defaultValue != null; - } - - T getDefault() { - return this.defaultValue; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("[") - .append(name()) - .append(":") - .append(type); - if (defaultValue!= null) { - sb.append(" {").append(defaultValue).append("}"); - } - sb.append("]"); - return sb.toString(); - } - - // ------------------------------ - // Internal - - private Type getType() { - Type superclass = getClass().getGenericSuperclass(); - if (superclass instanceof Class) { - throw new RuntimeException("Missing type parameter."); - } - return ((ParameterizedType) superclass).getActualTypeArguments()[0]; - } - - @SuppressWarnings("unchecked") - Class<T> rawType() { - // this is ok or leads to a CCE later if the types do not match - return (Class<T>) getRawType(type); - } - - private static Class<?> getRawType(Type type) { - if (type instanceof Class<?>) { - // type is a class - return (Class<?>) type; - } else if (type instanceof ParameterizedType) { - ParameterizedType parameterizedType = (ParameterizedType) type; - Type rawType = parameterizedType.getRawType(); - checkArgument(rawType instanceof Class); - return (Class<?>) rawType; - } else if (type instanceof GenericArrayType) { - Type componentType = ((GenericArrayType) type).getGenericComponentType(); - return Array.newInstance(getRawType(componentType), 0).getClass(); - } else if (type instanceof TypeVariable) { - return Object.class; - } else if (type instanceof WildcardType) { - return getRawType(((WildcardType) type).getUpperBounds()[0]); - } else { - String className = type == null ? "null" : type.getClass().getName(); - throw new IllegalArgumentException("Expected a Class, ParameterizedType, or " + "GenericArrayType, but <" - + type + "> is of type " + className); - } - } - - private static void checkArgument(boolean condition) { - if (!condition) { - throw new IllegalArgumentException(); - } - } -} diff --git a/src/main/java/org/olat/modules/ModuleconfigurationFragment.java b/src/main/java/org/olat/modules/ModuleconfigurationFragment.java deleted file mode 100644 index 3aeebf598d59abedadaadf71444136bdb70c1442..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/modules/ModuleconfigurationFragment.java +++ /dev/null @@ -1,190 +0,0 @@ -/** - * <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.modules; - -import java.util.Date; -import java.util.List; - -import org.olat.modules.ModuleProperty.ModulePropertyValue; - -/** - * A sub-section of a standard module configuration. This is particularly - * useful in case a block of key/value pairs would be repeated, with a - * different prefix. - * - * <p>Initial date: May 6, 2016 - * @author lmihalkovic, http://www.frentix.com - */ -public class ModuleconfigurationFragment implements IModuleConfiguration { - - private final ModuleConfiguration config; - private final String fragmentName; - private final String sep; - - protected ModuleconfigurationFragment(String fragmentName, String separator, ModuleConfiguration config) { - this.config = config; - this.fragmentName = fragmentName; - this.sep = separator == null ? "" : separator; - } - - protected final String key(String configKey) { - return fragmentName + sep + configKey; - } - - @Override - public boolean getBooleanSafe(String configKey) { - return config.getBooleanSafe(key(configKey)); - } - - @Override - public void setBooleanEntry(String configKey, boolean value) { - config.setBooleanEntry(key(configKey), value); - } - - @Override - public void set(String configKey, Object value) { - config.set(key(configKey), value); - } - - @Override - public Object get(String configKey) { - return config.get(key(configKey)); - } - - public <U> List<U> getList(String configKey, Class<U> cl) { - return config.getList(key(configKey), cl); - } - - @Override - public boolean anyTrue(ModuleProperty<Boolean> key) { - return _anyTrue(key); - } - @Override - public boolean anyTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2) { - return _anyTrue(key1, key2); - } - @Override - public boolean anyTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3) { - return _anyTrue(key1, key2, key3); - } - @Override - public boolean anyTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3, ModuleProperty<Boolean> key4) { - return _anyTrue(key1, key2, key3, key4); - } - @Override - public boolean anyTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3, ModuleProperty<Boolean> key4, ModuleProperty<Boolean> key5) { - return _anyTrue(key1, key2, key3, key4, key5); - } - @SafeVarargs - protected final boolean _anyTrue(ModuleProperty<Boolean>... keys) { - boolean rc = false; - for(ModuleProperty<Boolean> key : keys) { - rc = getBooleanSafe(key.name()); - if (rc) return true; - } - return rc; - } - - - @Override - public boolean allTrue(ModuleProperty<Boolean> key) { - return _allTrue(key); - } - @Override - public boolean allTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2) { - return _allTrue(key1, key2); - } - @Override - public boolean allTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3) { - return _allTrue(key1, key2, key3); - } - @Override - public boolean allTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3, ModuleProperty<Boolean> key4) { - return _allTrue(key1, key2, key3, key3); - } - @Override - public boolean allTrue(ModuleProperty<Boolean> key1, ModuleProperty<Boolean> key2, ModuleProperty<Boolean> key3, ModuleProperty<Boolean> key4, ModuleProperty<Boolean> key5) { - return _allTrue(key1, key2, key3, key4, key5); - } - - @SafeVarargs - protected final boolean _allTrue(ModuleProperty<Boolean>... keys) { - for(ModuleProperty<Boolean> key : keys) { - boolean rc = getBooleanSafe(key.name()); - if (!rc) return false; - } - return true; - } - - @Override - public <X> ModulePropertyValue<X> get(ModuleProperty<X> key) { - ModulePropertyValue<X> value = valueOf(key); - return value; - } - - @Override - public <X> void set(ModulePropertyValue<X> val) { - X value = val.val(); - config.set(key(val.name()), value); - } - - @Override - public <X> void set(ModuleProperty<X> key, X value) { - config.set(key(key.name()), value); - } - - @Override - public boolean hasAnyOf(ModuleProperty<?>... keys) { - for(ModuleProperty<?> key : keys) { - ModulePropertyValue<?> val = get(key); - if (val.isSet()) return true; - } - return false; - } - - protected <X> ModulePropertyValue<X> valueOf(ModuleProperty<X> key) { - Class<X> klass = key.rawType(); - X val = null; - String name = key.name(); - if(klass == Boolean.class) { - Boolean b = (key.hasDefault() ? config.getBooleanSafe(key(name), (Boolean)(key.getDefault())) : config.getBooleanEntry(key(name))); - val = klass.cast(b); - } else if (klass == Float.class) { - Float f = config.getFloatEntry(key(name)); - val = klass.cast(f); - } else if (klass == Integer.class) { - if(!key.hasDefault()) { - throw new IllegalArgumentException("Integer keys MUST define a default value"); - } - Integer i = config.getIntegerSafe(key(name), (Integer)key.getDefault()); - val = klass.cast(i); - } else if (klass == Date.class) { - Date d = config.getDateValue(key(name)); - val = klass.cast(d); - } else { - // This is no different than the normal CCE that would happen - // in the calling code when doing - // SomeType val = (SomeType) config.get("keyName"); - val = klass.cast(get(name)); - } - return new ModulePropertyValue<X>(val, key); - } - -}