Skip to content

Commit

Permalink
fixing MID-2904 - saving paging..
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Apr 27, 2016
1 parent ad3d64d commit 414552d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
Expand Up @@ -88,11 +88,11 @@ public abstract class ObjectListPanel<T extends ObjectType> extends BasePanel<T>

private Collection<SelectorOptions<GetOperationOptions>> options;

private int pageSize = 10;
// private int pageSize = 10;

private boolean multiselect;

private TableId tableId = TableId.TABLE_USERS;
// private TableId tableId = TableId.TABLE_USERS;

public Class<T> getType() {
return type;
Expand All @@ -107,7 +107,17 @@ public Class<T> getType() {
storageMap.put(PageReports.class, SessionStorage.KEY_REPORTS);
storageMap.put(PageRoles.class, SessionStorage.KEY_ROLES);
storageMap.put(PageServices.class, SessionStorage.KEY_SERVICES);
}

private static Map<Class, TableId> tablePagingMap;

static {
tablePagingMap = new HashMap<Class, TableId>();
tablePagingMap.put(PageResources.class, TableId.PAGE_RESOURCES_PANEL);
tablePagingMap.put(PageReports.class, TableId.PAGE_REPORTS);
tablePagingMap.put(PageRoles.class, TableId.TABLE_ROLES);
tablePagingMap.put(PageServices.class, TableId.TABLE_SERVICES);
tablePagingMap.put(PageUsers.class, TableId.TABLE_USERS);
}

public ObjectListPanel(String id, Class<T> type, Collection<SelectorOptions<GetOperationOptions>> options,
Expand Down Expand Up @@ -135,13 +145,13 @@ public void setProvider(BaseSortableDataProvider<SelectableBean<T>> provider) {
this.provider = provider;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

public void setTableId(TableId tableId) {
this.tableId = tableId;
}
// public void setPageSize(int pageSize) {
// this.pageSize = pageSize;
// }
//
// public void setTableId(TableId tableId) {
// this.tableId = tableId;
// }

public List<T> getSelectedObjects() {
BaseSortableDataProvider<SelectableBean<T>> dataProvider = getDataProvider();
Expand All @@ -166,8 +176,9 @@ public Search load() {
String storageKey = getStorageKey();// storageMap.get(parentPage.getClass());
Search search = null;
if (StringUtils.isNotEmpty(storageKey)) {
PageStorage storage = getSession().getSessionStorage().getPageStorageMap()
.get(storageKey);
PageStorage storage = getPageStorage(storageKey);
// getSession().getSessionStorage().getPageStorageMap()
// .get(storageKey);
if (storage != null) {
search = storage.getSearch();
}
Expand All @@ -194,8 +205,9 @@ protected BaseSortableDataProvider<SelectableBean<T>> getProvider() {
protected void saveProviderPaging(ObjectQuery query, ObjectPaging paging) {
String storageKey = getStorageKey();// storageMap.get(type);
if (StringUtils.isNotEmpty(storageKey)) {
PageStorage storage = getSession().getSessionStorage().getPageStorageMap()
.get(storageKey);
PageStorage storage = getPageStorage(storageKey);
// getSession().getSessionStorage().getPageStorageMap()
// .get(storageKey);
if (storage != null) {
storage.setPaging(paging);
}
Expand Down Expand Up @@ -232,8 +244,9 @@ private BoxedTablePanel<SelectableBean<T>> createTable() {
provider = getProvider();
provider.setQuery(getQuery());

TableId tableId = tablePagingMap.get(parentPage.getClass());
BoxedTablePanel<SelectableBean<T>> table = new BoxedTablePanel<SelectableBean<T>>(ID_TABLE, provider,
columns, tableId, pageSize) {
columns, tableId, parentPage.getSessionStorage().getUserProfile().getPagingSize(tableId)) {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -256,7 +269,8 @@ protected WebMarkupContainer createButtonToolbar(String id) {
table.setOutputMarkupId(true);
String storageKey = getStorageKey();
if (StringUtils.isNotEmpty(storageKey)) {
PageStorage storage = getSession().getSessionStorage().getPageStorageMap().get(storageKey);
PageStorage storage = getPageStorage(storageKey);
// getSession().getSessionStorage().getPageStorageMap().get(storageKey);
if (storage != null) {
table.setCurrentPage(storage.getPaging());
}
Expand Down Expand Up @@ -293,15 +307,24 @@ private String getStorageKey() {
return storageMap.get(parentPage.getClass());
}

private PageStorage getPageStorage(String storageKey){
PageStorage storage = getSession().getSessionStorage().getPageStorageMap().get(storageKey);
if (storage == null) {
storage = getSession().getSessionStorage().initPageStorage(storageKey);
}
return storage;
}

private void searchPerformed(ObjectQuery query, AjaxRequestTarget target) {
BaseSortableDataProvider<SelectableBean<T>> provider = getDataProvider();
provider.setQuery(query);
String storageKey = getStorageKey();
if (StringUtils.isNotEmpty(storageKey)) {
PageStorage storage = getSession().getSessionStorage().getPageStorageMap().get(storageKey);
if (storage == null) {
storage = getSession().getSessionStorage().initPageStorage(storageKey);
}
// PageStorage storage = getSession().getSessionStorage().getPageStorageMap().get(storageKey);
// if (storage == null) {
// storage = getSession().getSessionStorage().initPageStorage(storageKey);
// }
PageStorage storage = getPageStorage(storageKey);
if (storage != null) {
storage.setSearch(searchModel.getObject());
storage.setPaging(null);
Expand Down Expand Up @@ -332,7 +355,7 @@ public void refreshTable(Class<T> newType, AjaxRequestTarget target) {
BoxedTablePanel table = getTable();

((WebMarkupContainer) table.get("box")).addOrReplace(initSearch("header"));
table.setCurrentPage(null);
// table.setCurrentPage(null);
target.add((Component) table);
target.add(parentPage.getFeedbackPanel());

Expand All @@ -356,10 +379,11 @@ protected void searchPerformed(ObjectQuery query, AjaxRequestTarget target) {
private void saveSearchModel() {
String storageKey = getStorageKey();
if (StringUtils.isNotEmpty(storageKey)) {
PageStorage storage = getSession().getSessionStorage().getPageStorageMap().get(storageKey);
if (storage == null) {
storage = getSession().getSessionStorage().initPageStorage(storageKey);
}
PageStorage storage = getPageStorage(storageKey);
// PageStorage storage = getSession().getSessionStorage().getPageStorageMap().get(storageKey);
// if (storage == null) {
// storage = getSession().getSessionStorage().initPageStorage(storageKey);
// }
if (storage != null) {
storage.setSearch(searchModel.getObject());
storage.setPaging(null);
Expand Down
@@ -1,5 +1,6 @@
package com.evolveum.midpoint.web.component.data;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.session.UserProfileStorage;
Expand All @@ -17,7 +18,7 @@
/**
* @author lazyman
*/
public class PageSizePopover extends SimplePanel {
public class PageSizePopover extends BasePanel {

private static final String ID_POP_BUTTON = "popButton";
private static final String ID_POPOVER = "popover";
Expand All @@ -28,6 +29,7 @@ public class PageSizePopover extends SimplePanel {
public PageSizePopover(String id) {
super(id);
setRenderBodyOnly(true);
initLayout();
}

@Override
Expand All @@ -46,7 +48,6 @@ public void renderHead(IHeaderResponse response) {
}


@Override
protected void initLayout() {
Button popButton = new Button(ID_POP_BUTTON);
popButton.setOutputMarkupId(true);
Expand Down
Expand Up @@ -94,7 +94,7 @@ public class PageRoles extends PageAdminRoles {
private IModel<Search> searchModel;

public PageRoles() {
this(true);
this(false);
}

public PageRoles(boolean clearPagingInSession) {
Expand Down
Expand Up @@ -36,6 +36,7 @@ public class UserProfileStorage implements Serializable {
public enum TableId {
TABLE_ROLES,
TABLE_USERS,
TABLE_SERVICES,
TREE_TABLE_PANEL_CHILD,
TREE_TABLE_PANEL_MEMBER,
TREE_TABLE_PANEL_MANAGER,
Expand Down

0 comments on commit 414552d

Please sign in to comment.