From 727a60da759ab5ce2f5978ffdfad30b8568f9ca2 Mon Sep 17 00:00:00 2001 From: uhensler <urs.hensler@frentix.com> Date: Mon, 1 Apr 2019 11:01:07 +0200 Subject: [PATCH] OO-3939: Encapsulate editor full screen mode to a separate controller --- .../modules/bc/commands/CmdCreateFile.java | 20 +--- .../modules/bc/commands/CmdOpenContent.java | 19 +--- .../VFSLeafEditorFullscreenController.java | 107 ++++++++++++++++++ .../ui/AbstractAssignmentEditController.java | 12 +- .../ui/GTASampleSolutionsEditController.java | 13 +-- .../gta/ui/SubmitDocumentsController.java | 13 +-- 6 files changed, 121 insertions(+), 63 deletions(-) create mode 100644 src/main/java/org/olat/core/commons/services/vfs/ui/editor/VFSLeafEditorFullscreenController.java diff --git a/src/main/java/org/olat/core/commons/modules/bc/commands/CmdCreateFile.java b/src/main/java/org/olat/core/commons/modules/bc/commands/CmdCreateFile.java index 18c1699e7bd..61203abff4f 100644 --- a/src/main/java/org/olat/core/commons/modules/bc/commands/CmdCreateFile.java +++ b/src/main/java/org/olat/core/commons/modules/bc/commands/CmdCreateFile.java @@ -45,13 +45,11 @@ import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallback; import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallbackBuilder; import org.olat.core.commons.services.vfs.VFSMetadata; import org.olat.core.commons.services.vfs.VFSRepositoryService; -import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorController; +import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorFullscreenController; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; -import org.olat.core.gui.control.ChiefController; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; -import org.olat.core.gui.control.ScreenMode.Mode; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.BasicController; import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController; @@ -149,7 +147,6 @@ public class CmdCreateFile extends BasicController implements FolderCommand { fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FILE_EVENT, fileName)); fireEvent(ureq, FOLDERCOMMAND_FINISHED); notifyFinished(ureq); - doCloseEditor(); cleanUp(); } } @@ -180,7 +177,6 @@ public class CmdCreateFile extends BasicController implements FolderCommand { } } - @SuppressWarnings("deprecation") private void doEdit(UserRequest ureq) { List<VFSLeafEditor> editors = vfsRepositoryService.getEditors(vfsLeaf, VFSLeafEditor.Mode.EDIT); // Not able to decide which editor to use -> show the folder list @@ -198,20 +194,8 @@ public class CmdCreateFile extends BasicController implements FolderCommand { VFSLeafEditorConfigs configs = VFSLeafEditorConfigs.builder() .addConfig(htmlEditorConfig) .build(); - editorCtr = new VFSLeafEditorController(ureq, getWindowControl(), vfsLeaf, secCallback, configs); + editorCtr = new VFSLeafEditorFullscreenController(ureq, getWindowControl(), vfsLeaf, secCallback, configs); listenTo(editorCtr); - - ChiefController cc = getWindowControl().getWindowBackOffice().getChiefController(); - String businessPath = editorCtr.getWindowControlForDebug().getBusinessControl().getAsString(); - cc.getScreenMode().setMode(Mode.full, businessPath); - getWindowControl().pushToMainArea(editorCtr.getInitialComponent()); - } - - private void doCloseEditor() { - getWindowControl().pop(); - String businessPath = getWindowControl().getBusinessControl().getAsString(); - getWindowControl().getWindowBackOffice().getChiefController().getScreenMode().setMode(Mode.standard, businessPath); - cleanUp(); } private void cleanUp() { diff --git a/src/main/java/org/olat/core/commons/modules/bc/commands/CmdOpenContent.java b/src/main/java/org/olat/core/commons/modules/bc/commands/CmdOpenContent.java index 188ba81ec41..6794542d911 100644 --- a/src/main/java/org/olat/core/commons/modules/bc/commands/CmdOpenContent.java +++ b/src/main/java/org/olat/core/commons/modules/bc/commands/CmdOpenContent.java @@ -29,13 +29,11 @@ import org.olat.core.commons.services.vfs.VFSLeafEditorConfigs; import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallback; import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallbackBuilder; import org.olat.core.commons.services.vfs.VFSRepositoryService; -import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorController; +import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorFullscreenController; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; -import org.olat.core.gui.control.ChiefController; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; -import org.olat.core.gui.control.ScreenMode.Mode; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.BasicController; import org.olat.core.gui.translator.Translator; @@ -114,13 +112,9 @@ public class CmdOpenContent extends BasicController implements FolderCommand { VFSLeafEditorConfigs configs = VFSLeafEditorConfigs.builder() .addConfig(htmlEditorConfig) .build(); - editCtrl = new VFSLeafEditorController(ureq, getWindowControl(), vfsLeaf, secCallback, configs); + editCtrl = new VFSLeafEditorFullscreenController(ureq, getWindowControl(), vfsLeaf, secCallback, configs); listenTo(editCtrl); - ChiefController cc = getWindowControl().getWindowBackOffice().getChiefController(); - String businessPath = editCtrl.getWindowControlForDebug().getBusinessControl().getAsString(); - cc.getScreenMode().setMode(Mode.full, businessPath); - getWindowControl().pushToMainArea(editCtrl.getInitialComponent()); return this; } @@ -157,7 +151,7 @@ public class CmdOpenContent extends BasicController implements FolderCommand { if (event == Event.DONE_EVENT) { notifyFinished(ureq); } - doCloseEditor(); + cleanUp(); fireEvent(ureq, FOLDERCOMMAND_FINISHED); } super.event(ureq, source, event); @@ -174,13 +168,6 @@ public class CmdOpenContent extends BasicController implements FolderCommand { } } - private void doCloseEditor() { - getWindowControl().pop(); - String businessPath = getWindowControl().getBusinessControl().getAsString(); - getWindowControl().getWindowBackOffice().getChiefController().getScreenMode().setMode(Mode.standard, businessPath); - cleanUp(); - } - private void cleanUp() { removeAsListenerAndDispose(editCtrl); editCtrl = null; diff --git a/src/main/java/org/olat/core/commons/services/vfs/ui/editor/VFSLeafEditorFullscreenController.java b/src/main/java/org/olat/core/commons/services/vfs/ui/editor/VFSLeafEditorFullscreenController.java new file mode 100644 index 00000000000..1dac849bf6c --- /dev/null +++ b/src/main/java/org/olat/core/commons/services/vfs/ui/editor/VFSLeafEditorFullscreenController.java @@ -0,0 +1,107 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.core.commons.services.vfs.ui.editor; + +import org.olat.core.commons.services.vfs.VFSLeafEditorConfigs; +import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallback; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.core.gui.control.ChiefController; +import org.olat.core.gui.control.Controller; +import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.ScreenMode.Mode; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.controller.BasicController; +import org.olat.core.util.vfs.VFSLeaf; + +/** + * + * Initial date: 1 Apr 2019<br> + * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com + * + */ +public class VFSLeafEditorFullscreenController extends BasicController { + + private VFSLeafEditorController editorCtrl; + + private final VFSLeaf vfsLeaf; + + public VFSLeafEditorFullscreenController(UserRequest ureq, WindowControl wControl, VFSLeaf vfsLeaf, + VFSLeafEditorSecurityCallback secCallback, VFSLeafEditorConfigs configs) { + super(ureq, wControl); + this.vfsLeaf = vfsLeaf; + + editorCtrl = new VFSLeafEditorController(ureq, wControl, vfsLeaf, secCallback, configs); + listenTo(editorCtrl); + doOpenEditor(); + } + + public VFSLeafEditorFullscreenController(UserRequest ureq, WindowControl wControl, VFSLeaf vfsLeaf, + VFSLeafEditorSecurityCallback secCallback, VFSLeafEditorConfigs configs, String cssClass) { + super(ureq, wControl); + this.vfsLeaf = vfsLeaf; + + editorCtrl = new VFSLeafEditorController(ureq, wControl, vfsLeaf, secCallback, configs, cssClass); + listenTo(editorCtrl); + doOpenEditor(); + } + + public VFSLeaf getVfsLeaf() { + return vfsLeaf; + } + + @Override + protected void event(UserRequest ureq, Controller source, Event event) { + if (source == editorCtrl) { + doCloseEditor(); + fireEvent(ureq, event); + } + super.event(ureq, source, event); + } + + @Override + protected void event(UserRequest ureq, Component source, Event event) { + // + } + + @SuppressWarnings("deprecation") + private void doOpenEditor() { + ChiefController cc = getWindowControl().getWindowBackOffice().getChiefController(); + String businessPath = editorCtrl.getWindowControlForDebug().getBusinessControl().getAsString(); + cc.getScreenMode().setMode(Mode.full, businessPath); + getWindowControl().pushToMainArea(editorCtrl.getInitialComponent()); + } + + private void doCloseEditor() { + getWindowControl().pop(); + String businessPath = getWindowControl().getBusinessControl().getAsString(); + getWindowControl().getWindowBackOffice().getChiefController().getScreenMode().setMode(Mode.standard, businessPath); + + removeAsListenerAndDispose(editorCtrl); + editorCtrl = null; + } + + + @Override + protected void doDispose() { + // + } + +} diff --git a/src/main/java/org/olat/course/nodes/gta/ui/AbstractAssignmentEditController.java b/src/main/java/org/olat/course/nodes/gta/ui/AbstractAssignmentEditController.java index dd0c096baa0..8d7a167dce0 100644 --- a/src/main/java/org/olat/course/nodes/gta/ui/AbstractAssignmentEditController.java +++ b/src/main/java/org/olat/course/nodes/gta/ui/AbstractAssignmentEditController.java @@ -33,7 +33,7 @@ import org.olat.core.commons.services.vfs.VFSLeafEditorConfigs; import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallback; import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallbackBuilder; import org.olat.core.commons.services.vfs.VFSRepositoryService; -import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorController; +import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorFullscreenController; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -95,7 +95,7 @@ abstract class AbstractAssignmentEditController extends FormBasicController { private DialogBoxController confirmDeleteCtrl; private EditHTMLController editHtmlCtrl; private EditTaskController addTaskCtrl, editTaskCtrl; - private VFSLeafEditorController vfsLeafEditorCtrl; + private VFSLeafEditorFullscreenController vfsLeafEditorCtrl; private final File tasksFolder; protected final boolean readOnly; @@ -247,7 +247,6 @@ abstract class AbstractAssignmentEditController extends FormBasicController { if(event == Event.DONE_EVENT) { gtaManager.markNews(courseEnv, gtaNode); updateModel(); - doCloseFullscreen(); cleanUp(); } } else if(confirmDeleteCtrl == source) { @@ -392,13 +391,8 @@ abstract class AbstractAssignmentEditController extends FormBasicController { .withMode(mode) .build(); VFSLeafEditorConfigs configs = VFSLeafEditorConfigs.builder().build(); - vfsLeafEditorCtrl = new VFSLeafEditorController(ureq, getWindowControl(), (VFSLeaf)vfsItem, secCallback, configs); + vfsLeafEditorCtrl = new VFSLeafEditorFullscreenController(ureq, getWindowControl(), (VFSLeaf)vfsItem, secCallback, configs); listenTo(vfsLeafEditorCtrl); - - ChiefController cc = getWindowControl().getWindowBackOffice().getChiefController(); - String businessPath = vfsLeafEditorCtrl.getWindowControlForDebug().getBusinessControl().getAsString(); - cc.getScreenMode().setMode(ScreenMode.Mode.full, businessPath); - getWindowControl().pushToMainArea(vfsLeafEditorCtrl.getInitialComponent()); } } diff --git a/src/main/java/org/olat/course/nodes/gta/ui/GTASampleSolutionsEditController.java b/src/main/java/org/olat/course/nodes/gta/ui/GTASampleSolutionsEditController.java index 6a32f0208ce..c1f68034f68 100644 --- a/src/main/java/org/olat/course/nodes/gta/ui/GTASampleSolutionsEditController.java +++ b/src/main/java/org/olat/course/nodes/gta/ui/GTASampleSolutionsEditController.java @@ -33,7 +33,7 @@ import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallback; import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallbackBuilder; import org.olat.core.commons.services.vfs.VFSMetadata; import org.olat.core.commons.services.vfs.VFSRepositoryService; -import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorController; +import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorFullscreenController; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -85,7 +85,7 @@ public class GTASampleSolutionsEditController extends FormBasicController { private EditSolutionController editSolutionCtrl; private NewSolutionController newSolutionCtrl; private EditHTMLController editHtmlCtrl; - private VFSLeafEditorController vfsLeafEditorCtrl; + private VFSLeafEditorFullscreenController vfsLeafEditorCtrl; private final File solutionDir; private final boolean readOnly; @@ -238,7 +238,6 @@ public class GTASampleSolutionsEditController extends FormBasicController { if(event == Event.DONE_EVENT) { gtaManager.markNews(courseEnv, gtaNode); updateModel(); - doCloseFullscreen(); cleanUp(); } } else if(cmc == source) { @@ -319,7 +318,6 @@ public class GTASampleSolutionsEditController extends FormBasicController { } } - @SuppressWarnings("deprecation") private void doEditVfsEditor(UserRequest ureq, Solution solution, Mode mode) { VFSItem vfsItem = solutionContainer.resolve(solution.getFilename()); if(vfsItem == null || !(vfsItem instanceof VFSLeaf)) { @@ -330,13 +328,8 @@ public class GTASampleSolutionsEditController extends FormBasicController { .build(); //TODO uh container to config VFSLeafEditorConfigs configs = VFSLeafEditorConfigs.builder().build(); - vfsLeafEditorCtrl = new VFSLeafEditorController(ureq, getWindowControl(), (VFSLeaf)vfsItem, secCallback, configs); + vfsLeafEditorCtrl = new VFSLeafEditorFullscreenController(ureq, getWindowControl(), (VFSLeaf)vfsItem, secCallback, configs); listenTo(vfsLeafEditorCtrl); - - ChiefController cc = getWindowControl().getWindowBackOffice().getChiefController(); - String businessPath = vfsLeafEditorCtrl.getWindowControlForDebug().getBusinessControl().getAsString(); - cc.getScreenMode().setMode(ScreenMode.Mode.full, businessPath); - getWindowControl().pushToMainArea(vfsLeafEditorCtrl.getInitialComponent()); } } diff --git a/src/main/java/org/olat/course/nodes/gta/ui/SubmitDocumentsController.java b/src/main/java/org/olat/course/nodes/gta/ui/SubmitDocumentsController.java index 21943c4af7e..1738148851a 100644 --- a/src/main/java/org/olat/course/nodes/gta/ui/SubmitDocumentsController.java +++ b/src/main/java/org/olat/course/nodes/gta/ui/SubmitDocumentsController.java @@ -40,7 +40,7 @@ import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallback; import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallbackBuilder; import org.olat.core.commons.services.vfs.VFSMetadata; import org.olat.core.commons.services.vfs.VFSRepositoryService; -import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorController; +import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorFullscreenController; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -97,7 +97,7 @@ class SubmitDocumentsController extends FormBasicController { private DialogBoxController confirmDeleteCtrl; private SinglePageController viewDocCtrl; private EditHTMLController editHtmlCtrl; - private VFSLeafEditorController vfsLeafEditorCtrl; + private VFSLeafEditorFullscreenController vfsLeafEditorCtrl; private final int maxDocs; private final String docI18nKey; @@ -322,7 +322,6 @@ class SubmitDocumentsController extends FormBasicController { gtaManager.markNews(courseEnv, gtaNode); } updateModel(); - doCloseFullscreen(); cleanUp(); checkDeadline(ureq); } else if(cmc == source) { @@ -458,7 +457,6 @@ class SubmitDocumentsController extends FormBasicController { } } - @SuppressWarnings("deprecation") private void doEditVfsEditor(UserRequest ureq, String filename, Mode mode) { VFSItem vfsItem = documentsContainer.resolve(filename); if(vfsItem == null || !(vfsItem instanceof VFSLeaf)) { @@ -468,13 +466,8 @@ class SubmitDocumentsController extends FormBasicController { .withMode(mode) .build(); VFSLeafEditorConfigs configs = VFSLeafEditorConfigs.builder().build(); - vfsLeafEditorCtrl = new VFSLeafEditorController(ureq, getWindowControl(), (VFSLeaf)vfsItem, secCallback, configs); + vfsLeafEditorCtrl = new VFSLeafEditorFullscreenController(ureq, getWindowControl(), (VFSLeaf)vfsItem, secCallback, configs); listenTo(vfsLeafEditorCtrl); - - ChiefController cc = getWindowControl().getWindowBackOffice().getChiefController(); - String businessPath = vfsLeafEditorCtrl.getWindowControlForDebug().getBusinessControl().getAsString(); - cc.getScreenMode().setMode(ScreenMode.Mode.full, businessPath); - getWindowControl().pushToMainArea(vfsLeafEditorCtrl.getInitialComponent()); } } -- GitLab