Skip to content

Commit

Permalink
MID-1931 working initial implementation. Not fully completed yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Suta committed Jun 23, 2014
1 parent ac0df57 commit a06435a
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 8 deletions.
Expand Up @@ -18,6 +18,9 @@
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<table class="table table-striped table-condensed" wicket:id="table" />
<div wicket:id="paging"/>

<div wicket:id="pagingSize" />
<div wicket:id="paging" />

</wicket:panel>
</html>
Expand Up @@ -18,8 +18,11 @@

import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.web.component.data.paging.NavigatorPanel;
import com.evolveum.midpoint.web.component.data.paging.PagingSizePanel;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import org.apache.commons.lang.Validate;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
Expand All @@ -44,25 +47,29 @@ public class TablePanel<T> extends Panel {

private static final String ID_TABLE = "table";
private static final String ID_PAGING = "paging";
private static final String ID_PAGING_SIZE = "pagingSize";

private IModel<Boolean> showPaging = new Model<Boolean>(true);
private IModel<Boolean> showCount = new Model<Boolean>(true);
private IModel<Boolean> showPagingSize = new Model<Boolean>(false);

public TablePanel(String id, ISortableDataProvider provider, List<IColumn<T, String>> columns) {
this(id, provider, columns, 10);
this(id, provider, columns, UserProfileStorage.DEFAULT_PAGING_SIZE, null);
}

public TablePanel(String id, ISortableDataProvider provider, List<IColumn<T, String>> columns, int itemsPerPage) {
public TablePanel(String id, ISortableDataProvider provider, List<IColumn<T, String>> columns, int itemsPerPage,
UserProfileStorage.TableId tableId) {
super(id);
Validate.notNull(provider, "Object type must not be null.");
Validate.notNull(columns, "Columns must not be null.");

add(AttributeModifier.prepend("style", "display: table; width: 100%;"));

initLayout(columns, itemsPerPage, provider);
initLayout(columns, itemsPerPage, provider, tableId);
}

private void initLayout(List<IColumn<T, String>> columns, int itemsPerPage, ISortableDataProvider provider) {
private void initLayout(List<IColumn<T, String>> columns, final int itemsPerPage, ISortableDataProvider provider,
final UserProfileStorage.TableId tableId) {
DataTable<T, String> table = new SelectableDataTable<T>(ID_TABLE, columns, provider, itemsPerPage);
table.setOutputMarkupId(true);

Expand All @@ -79,6 +86,20 @@ private void initLayout(List<IColumn<T, String>> columns, int itemsPerPage, ISor
NavigatorPanel nb2 = new NavigatorPanel(ID_PAGING, table, showPagedPaging(provider));
addVisibleBehaviour(nb2, showPaging);
add(nb2);

PagingSizePanel pagingSizePanel = new PagingSizePanel(ID_PAGING_SIZE, tableId){

@Override
protected void pagingSizeChangePerformed(AjaxRequestTarget target){
Integer pageSize = getPagingSize();
getPageBase().getSessionStorage().getUserProfile().setPagingSize(tableId, pageSize);
setItemsPerPage(pageSize);
target.add(getNavigatorPanel());
target.add(getDataTable());
}
};
addVisibleBehaviour(pagingSizePanel, showPagingSize);
add(pagingSizePanel);
}

private void addVisibleBehaviour(Component comp, final IModel<Boolean> model) {
Expand All @@ -104,6 +125,10 @@ public DataTable getDataTable() {
return (DataTable) get(ID_TABLE);
}

public NavigatorPanel getNavigatorPanel(){
return (NavigatorPanel) get(ID_PAGING);
}

public void setItemsPerPage(int size) {
getDataTable().setItemsPerPage(size);
}
Expand All @@ -123,6 +148,10 @@ public void setCurrentPage(ObjectPaging paging) {
getDataTable().setCurrentPage(page);
}

public void setShowPagingSize(boolean show){
this.showPagingSize.setObject(show);
}

public void setShowPaging(boolean showPaging) {
this.showPaging.setObject(showPaging);
this.showCount.setObject(showPaging);
Expand Down
@@ -0,0 +1,38 @@
<!--
~ Copyright (c) 2010-2013 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div style="text-align: left">

<form class="form-inline pull-left search-form" wicket:id="pagingForm">
<label class="col-lg-5">
<wicket:message key="PagingSizePanel.label.pagingSize" />
</label>

<div class="col-lg-5 form-group">
<input class="form-control input-sm" wicket:id="pagingSize"/>
</div>

<span class="btn-group">
<a class="btn btn-default btn-sm" wicket:id="setPagingButton"/>
</span>
</form>

</div>
</wicket:panel>
</html>
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.web.component.data.paging;

import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.SearchFormEnterBehavior;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;

/**
* @author shood
* */
public class PagingSizePanel extends SimplePanel {

private static final String ID_FORM_PAGING = "pagingForm";
private static final String ID_PAGING_SIZE = "pagingSize";
private static final String ID_SET_PAGING_BUTTON = "setPagingButton";

private IModel<Integer> pagingModel;

public PagingSizePanel(String id, final UserProfileStorage.TableId tableId){
super(id);

pagingModel = new LoadableModel<Integer>() {

@Override
protected Integer load() {
return getPageBase().getSessionStorage().getUserProfile().getPagingSize(tableId);
}
};

Form pagingForm = new Form(ID_FORM_PAGING);
pagingForm.setOutputMarkupId(true);
add(pagingForm);

initLayout(pagingForm);
}

public Integer getPagingSize(){
return pagingModel.getObject();
}

private void initLayout(Form form){
AjaxSubmitButton setPagingButton = new AjaxSubmitButton(ID_SET_PAGING_BUTTON,
createStringResource("PagingSizePanel.button.set")) {

@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form){
pagingSizeChangePerformed(target);
}

@Override
protected void onError(AjaxRequestTarget target, Form<?> form){
target.add(getFeedbackPanel());
}
};
form.add(setPagingButton);

final TextField<Integer> pagingText = new TextField<Integer>(ID_PAGING_SIZE, pagingModel);
pagingText.setType(Integer.class);
pagingText.add(AttributeModifier.replace("placeholder", createStringResource("PagingSizePanel.label.pagingSize")));
pagingText.add(new SearchFormEnterBehavior(setPagingButton));
form.add(pagingText);
}

private Component getFeedbackPanel() {
return getPageBase().getFeedbackPanel();
}

protected void pagingSizeChangePerformed(AjaxRequestTarget target){}


}
@@ -0,0 +1,18 @@
#
# Copyright (c) 2010-2013 Evolveum
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

PagingSizePanel.button.set=Set
PagingSizePanel.label.pagingSize=Paging size
Expand Up @@ -52,6 +52,7 @@
import com.evolveum.midpoint.web.security.MidPointAuthWebSession;
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.session.SessionStorage;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.wf.api.WorkflowManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

Expand Down Expand Up @@ -638,4 +639,8 @@ public void receiveNotifyMessage(AjaxRequestTarget target, NotifyMessage message

target.appendJavaScript(sb.toString());
}

public Integer getPagingSize(UserProfileStorage.TableId tableId){
return getSessionStorage().getUserProfile().getPagingSize(tableId);
}
}
Expand Up @@ -42,7 +42,7 @@
import com.evolveum.midpoint.web.page.admin.configuration.component.HeaderMenuAction;
import com.evolveum.midpoint.web.page.admin.roles.dto.RolesSearchDto;
import com.evolveum.midpoint.web.session.RolesStorage;
import com.evolveum.midpoint.web.session.UsersStorage;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
Expand Down Expand Up @@ -128,8 +128,10 @@ protected void saveProviderPaging(ObjectQuery query, ObjectPaging paging) {
provider.setQuery(createQuery());

List<IColumn<RoleType, String>> columns = initColumns();
TablePanel table = new TablePanel<>(ID_TABLE, provider, columns);
TablePanel table = new TablePanel<>(ID_TABLE, provider, columns, getPagingSize(UserProfileStorage.TableId.TABLE_ROLES),
UserProfileStorage.TableId.TABLE_ROLES);
table.setOutputMarkupId(true);
table.setShowPagingSize(true);
RolesStorage storage = getSessionStorage().getRoles();
table.setCurrentPage(storage.getRolesPaging());

Expand Down
Expand Up @@ -308,6 +308,7 @@ public UserListItemDto createDataObjectWrapper(PrismObject<UserType> obj) {

TablePanel table = new TablePanel(ID_TABLE, provider, columns);
table.setOutputMarkupId(true);
table.setShowPagingSize(true);

UsersStorage storage = getSessionStorage().getUsers();
table.setCurrentPage(storage.getUsersPaging());
Expand Down
Expand Up @@ -55,6 +55,7 @@
import com.evolveum.midpoint.web.page.admin.users.PageUser;
import com.evolveum.midpoint.web.page.admin.users.dto.*;
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.ObjectTypeGuiDescriptor;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.web.util.WebMiscUtil;
Expand Down Expand Up @@ -330,7 +331,7 @@ public ObjectQuery getQuery() {
};
tableProvider.setOptions(WebModelUtils.createMinimalOptions());
List<IColumn<OrgTableDto, String>> tableColumns = createTableColumns();
TablePanel table = new TablePanel(ID_TABLE, tableProvider, tableColumns, 10);
TablePanel table = new TablePanel(ID_TABLE, tableProvider, tableColumns);
table.setOutputMarkupId(true);
form.add(table);
}
Expand Down
Expand Up @@ -48,6 +48,11 @@ public class SessionStorage implements Serializable {
private RolesStorage roles;
private TasksStorage tasks;

/**
* Store session information for user preferences about paging size in midPoint GUI
* */
private UserProfileStorage userProfile;

public Class<? extends WebPage> getPreviousPage() {
return previousPage;
}
Expand Down Expand Up @@ -105,4 +110,15 @@ public ReportsStorage getReports() {
}
return reports;
}

public UserProfileStorage getUserProfile(){
if(userProfile == null){
userProfile = new UserProfileStorage();
}
return userProfile;
}

public void setUserProfile(UserProfileStorage profile){
userProfile = profile;
}
}

0 comments on commit a06435a

Please sign in to comment.