minor fixes and code cleanup

This commit is contained in:
anhefti 2019-04-01 14:48:12 +02:00
parent 529e3a84f2
commit 76c08bb5c6
9 changed files with 53 additions and 83 deletions

View file

@ -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)

View file

@ -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));

View file

@ -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"),

View file

@ -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 */
<T extends PageEvent> 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<Result<PageAction>> 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 <T> the type of the Entity of the table
* @return TableBuilder of specified type */
<T extends Entity> TableBuilder<T> entityTableBuilder(final RestCall<Page<T>> 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();

View file

@ -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();

View file

@ -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;
// }
}

View file

@ -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

View file

@ -67,11 +67,12 @@ public class EntityTable<ROW extends Entity> {
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<ROW extends Entity> {
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<ROW extends Entity> {
}
}
this.navigator = (hideNavigation) ? null : new TableNavigator(this);
this.navigator = new TableNavigator(this);
createTableColumns();
updateTableRows(
@ -288,9 +290,7 @@ public class EntityTable<ROW extends Entity> {
.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
});

View file

@ -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();