From 76c08bb5c69d02ac10c55c390612844304a9d62e Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 1 Apr 2019 14:48:12 +0200 Subject: [PATCH] minor fixes and code cleanup --- .../sebserver/gui/content/LmsSetupForm.java | 2 +- .../seb/sebserver/gui/content/MainPage.java | 2 +- .../gui/content/action/ActionDefinition.java | 2 +- .../gui/service/page/PageService.java | 39 ++++++++++-- .../service/page/impl/DefaultPageLayout.java | 2 +- .../gui/service/page/impl/MainPageState.java | 59 ------------------- .../service/page/impl/PageServiceImpl.java | 8 +-- .../seb/sebserver/gui/table/EntityTable.java | 18 +++--- .../sebserver/gui/table/TableNavigator.java | 4 ++ 9 files changed, 53 insertions(+), 83 deletions(-) delete mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/MainPageState.java diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java index ed54ed0d..48b1b09e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java @@ -190,7 +190,7 @@ public class LmsSetupForm implements TemplateComposer { .withEntityKey(entityKey) .withExec(action -> this.testLmsSetup(action, formHandle)) .ignoreMoveAwayFromEdit() - .publishIf(() -> modifyGrant && isNotNew.getAsBoolean() && institutionActive) + .publishIf(() -> modifyGrant && isNotNew.getAsBoolean() && !readonly) .newAction(ActionDefinition.LMS_SETUP_DEACTIVATE) .withEntityKey(entityKey) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/MainPage.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/MainPage.java index 9f70bad2..af283fee 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/MainPage.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/MainPage.java @@ -64,7 +64,7 @@ public class MainPage implements TemplateComposer { @Override public void compose(final PageContext pageContext) { - this.pageStateService.clear(); + this.pageStateService.clearState(); final Composite parent = pageContext.getParent(); parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java index ceef7e10..fa801207 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java @@ -148,7 +148,7 @@ public enum ActionDefinition { LMS_SETUP_TEST( new LocTextKey("sebserver.lmssetup.action.test"), ImageIcon.TEST, - PageStateDefinition.LMS_SETUP_VIEW, + PageStateDefinition.LMS_SETUP_EDIT, ActionCategory.FORM), LMS_SETUP_CANCEL_MODIFY( new LocTextKey("sebserver.overall.action.modify.cancel"), diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java index 6bf3cf2f..93a9036b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java @@ -59,8 +59,9 @@ public interface PageService { * @return the JSONMapper for parse, read and write JSON */ JSONMapper getJSONMapper(); - PageState initPageState(PageState initState); - + /** Get the PageState of the current user. + * + * @return PageState of the current user. */ PageState getCurrentState(); /** Publishes a given PageEvent to the current page tree @@ -70,25 +71,55 @@ public interface PageService { * @param event the concrete PageEvent instance */ void firePageEvent(T event, PageContext pageContext); + /** Executes the given PageAction and if successful, propagate an ActionEvent to the current page. + * + * @param pageAction the PageAction to execute */ default void executePageAction(final PageAction pageAction) { executePageAction(pageAction, result -> { }); } + /** Executes the given PageAction and if successful, propagate an ActionEvent to the current page. + * + * @param pageAction the PageAction to execute + * @param callback a callback to react on PageAction execution. The Callback gets a Result referencing to + * the executed PageAction or to an error if the PageAction has not been executed */ void executePageAction(PageAction pageAction, Consumer> callback); + /** Publishes a PageAction to the current page. This uses the firePageEvent form + * PageContext of the given PageAction and fires a ActionPublishEvent for the given PageAction + * + * All ActionPublishEventListeners that are registered within the current page will + * receive the ActionPublishEvent sent by this. + * + * @param pageAction the PageAction to publish */ void publishAction(final PageAction pageAction); + /** Get a new FormBuilder for the given PageContext and with number of rows. + * + * @param pageContext the PageContext on that the FormBuilder should work + * @param rows the number of rows of the from + * @return a FormBuilder instance for the given PageContext and with number of rows */ FormBuilder formBuilder(final PageContext pageContext, final int rows); + /** Get an new TableBuilder for specified page based RestCall. + * + * @param apiCall the SEB Server API RestCall that feeds the table with data + * @param the type of the Entity of the table + * @return TableBuilder of specified type */ TableBuilder entityTableBuilder(final RestCall> apiCall); - void clear(); - + /** Get a new PageActionBuilder for a given PageContext. + * + * @param pageContext the PageContext that is used by the new PageActionBuilder + * @return new PageActionBuilder to build PageAction */ default PageActionBuilder pageActionBuilder(final PageContext pageContext) { return new PageActionBuilder(this, pageContext); } + /** Clears the PageState of the current users page */ + void clearState(); + default PageAction onEmptyEntityKeyGoTo(final PageAction action, final ActionDefinition gotoActionDef) { if (action.getEntityKey() == null) { final PageContext pageContext = action.pageContext(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java index f986be85..6c641926 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java @@ -140,7 +140,7 @@ public class DefaultPageLayout implements TemplateComposer { // TODO error handling } - this.pageStateService.clear(); + this.pageStateService.clearState(); // forward to login page with success message pageContext.forwardToLoginPage(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/MainPageState.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/MainPageState.java deleted file mode 100644 index 78a4115a..00000000 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/MainPageState.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package ch.ethz.seb.sebserver.gui.service.page.impl; - -public final class MainPageState { - -// private static final Logger log = LoggerFactory.getLogger(MainPageState.class); -// -// private PageAction action = null; -// -// private MainPageState() { -// } -// -// public action -// -// public boolean changeTo(final PageAction action) { -// if (this.action.definition != action.definition) { -// this.action = action; -// return true; -// } -// -// return false; -// } -// -// public static MainPageState get() { -// try { -// -// final HttpSession httpSession = RWT -// .getUISession() -// .getHttpSession(); -// -// MainPageState mainPageState = (MainPageState) httpSession.getAttribute(MainPage.ATTR_MAIN_PAGE_STATE); -// if (mainPageState == null) { -// mainPageState = new MainPageState(); -// httpSession.setAttribute(MainPage.ATTR_MAIN_PAGE_STATE, mainPageState); -// } -// -// return mainPageState; -// -// } catch (final RuntimeException re) { -// throw re; -// } catch (final Exception e) { -// log.error("Unexpected error while trying to get MainPageState from user-session"); -// } -// -// return null; -// } -// -// public static void clear() { -// final MainPageState mainPageState = get(); -// mainPageState.action = null; -// } -} \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java index c182a45d..8258531c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java @@ -91,12 +91,6 @@ public class PageServiceImpl implements PageService { return this.jsonMapper; } - @Override - public PageState initPageState(final PageState initState) { - // TODO Auto-generated method stub - return null; - } - @Override public PageState getCurrentState() { try { @@ -206,7 +200,7 @@ public class PageServiceImpl implements PageService { } @Override - public void clear() { + public void clearState() { try { final HttpSession httpSession = RWT diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java index 5a40ea75..612e212a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java @@ -67,11 +67,12 @@ public class EntityTable { private final Table table; private final TableNavigator navigator; - private int pageNumber = 1; - private int pageSize; - private String sortColumn = null; - private SortOrder sortOrder = SortOrder.ASCENDING; - private boolean columnsWithSameWidth = true; + int pageNumber = 1; + int pageSize; + String sortColumn = null; + SortOrder sortOrder = SortOrder.ASCENDING; + boolean columnsWithSameWidth = true; + boolean hideNavigation = false; EntityTable( final int type, @@ -93,6 +94,7 @@ public class EntityTable { this.columns = Utils.immutableListOf(columns); this.actions = Utils.immutableListOf(actions); this.emptyMessage = emptyMessage; + this.hideNavigation = hideNavigation; final GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; @@ -144,7 +146,7 @@ public class EntityTable { } } - this.navigator = (hideNavigation) ? null : new TableNavigator(this); + this.navigator = new TableNavigator(this); createTableColumns(); updateTableRows( @@ -288,9 +290,7 @@ public class EntityTable { .withQueryParams((this.filter != null) ? this.filter.getFilterParameter() : null) .call() .map(this::createTableRowsFromPage) - .map(pageData -> (this.navigator != null) - ? this.navigator.update(pageData) - : pageData) + .map(this.navigator::update) .onErrorDo(t -> { // TODO error handling }); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/table/TableNavigator.java b/src/main/java/ch/ethz/seb/sebserver/gui/table/TableNavigator.java index fbe87cb9..a160c33a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/table/TableNavigator.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/table/TableNavigator.java @@ -56,6 +56,10 @@ public class TableNavigator { return pageData; } + if (this.entityTable.hideNavigation) { + return pageData; + } + final int pageNumber = pageData.getPageNumber(); final int numberOfPages = pageData.getNumberOfPages();