Skip to content

Commit

Permalink
page (list) tasks rework - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Dec 17, 2019
1 parent b4bd3d0 commit b450731
Show file tree
Hide file tree
Showing 20 changed files with 573 additions and 171 deletions.
Expand Up @@ -21,6 +21,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
Expand Down Expand Up @@ -48,6 +49,7 @@
import com.evolveum.midpoint.web.page.admin.configuration.PageImportObject;
import com.evolveum.midpoint.web.session.UserProfileStorage.TableId;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.wicket.util.time.Duration;

/**
* @author katkav
Expand All @@ -62,6 +64,8 @@ public abstract class MainObjectListPanel<O extends ObjectType, S extends Serial

public MainObjectListPanel(String id, Class<O> type, TableId tableId, Collection<SelectorOptions<GetOperationOptions>> options, PageBase parentPage) {
super(id, type, tableId, options);


}

@Override
Expand Down Expand Up @@ -319,4 +323,9 @@ protected void populateItem(ListItem<Component> listItem) {
add(buttonsView);
}
}

@Override
protected boolean isRefreshEnabled() {
return true;
}
}
Expand Up @@ -20,10 +20,12 @@
import com.evolveum.midpoint.web.component.data.column.InlineMenuButtonColumn;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.SerializableSupplier;
import com.evolveum.midpoint.web.page.admin.server.dto.TaskSelectableBeanProvider;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.export.AbstractExportableColumn;
Expand Down Expand Up @@ -57,6 +59,7 @@
import com.evolveum.midpoint.web.component.util.SelectableBeanImpl;
import com.evolveum.midpoint.web.session.PageStorage;
import com.evolveum.midpoint.web.session.UserProfileStorage.TableId;
import org.apache.wicket.util.time.Duration;
import org.jetbrains.annotations.NotNull;

import static java.util.Collections.singleton;
Expand Down Expand Up @@ -133,11 +136,13 @@ public int getSelectedObjectsCount(){
@SuppressWarnings("unchecked")
@NotNull
public List<O> getSelectedObjects() {
BaseSortableDataProvider<SelectableBean<O>> dataProvider = getDataProvider();
BaseSortableDataProvider<? extends SelectableBean<O>> dataProvider = getDataProvider();
if (dataProvider instanceof SelectableBeanObjectDataProvider) {
return ((SelectableBeanObjectDataProvider<O>) dataProvider).getSelectedData();
} else if (dataProvider instanceof ListDataProvider2) {
return ((ListDataProvider2) dataProvider).getSelectedObjects();
} else if (dataProvider instanceof TaskSelectableBeanProvider) {
return (List<O>) ((TaskSelectableBeanProvider) dataProvider).getSelectedTasks();
}
return new ArrayList<>();
}
Expand Down Expand Up @@ -203,7 +208,9 @@ private BoxedTablePanel<SelectableBean<O>> createTable() {


BoxedTablePanel<SelectableBean<O>> table = new BoxedTablePanel<SelectableBean<O>>(ID_TABLE, provider,
columns, tableId, tableId == null ? 10 : getPageBase().getSessionStorage().getUserProfile().getPagingSize(getTableIdKeyValue())) {
columns, tableId,
tableId == null ? 10 : getPageBase().getSessionStorage().getUserProfile().getPagingSize(getTableIdKeyValue()),
isRefreshEnabled()) {
private static final long serialVersionUID = 1L;

@Override
Expand Down Expand Up @@ -241,6 +248,8 @@ protected boolean hideFooterIfSinglePage(){
return table;
}

protected abstract boolean isRefreshEnabled();

protected WebMarkupContainer createHeader(String headerId) {
return initSearch(headerId);
}
Expand Down Expand Up @@ -610,24 +619,24 @@ private void searchPerformed(ObjectQuery query, AjaxRequestTarget target) {
}

public void refreshTable(Class<O> newTypeClass, AjaxRequestTarget target) {
ObjectTypes newType = newTypeClass != null ? ObjectTypes.getObjectType(newTypeClass) : null;

BaseSortableDataProvider<SelectableBean<O>> provider = getDataProvider();
provider.setQuery(getQuery());
if (newType != null && provider instanceof SelectableBeanObjectDataProvider) {
((SelectableBeanObjectDataProvider<O>) provider).setType(newTypeClass);
}
// ObjectTypes newType = newTypeClass != null ? ObjectTypes.getObjectType(newTypeClass) : null;
//
// BaseSortableDataProvider<SelectableBean<O>> provider = getDataProvider();
// provider.setQuery(getQuery());
// if (newType != null && provider instanceof SelectableBeanObjectDataProvider) {
// ((SelectableBeanObjectDataProvider<O>) provider).setType(newTypeClass);
// }

BoxedTablePanel<SelectableBean<O>> table = getTable();

((WebMarkupContainer) table.get("box")).addOrReplace(initSearch("header"));
if (newType != null && !this.type.equals(newType)) {
this.type = newType;
resetSearchModel();
table.setCurrentPage(null);
} else {
saveSearchModel(getCurrentTablePaging());
}
// ((WebMarkupContainer) table.get("box")).addOrReplace(initSearch("header"));
// if (newType != null && !this.type.equals(newType)) {
// this.type = newType;
// resetSearchModel();
// table.setCurrentPage(null);
// } else {
// saveSearchModel(getCurrentTablePaging());
// }

target.add((Component) table);
target.add(getPageBase().getFeedbackPanel());
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.web.component.data.column.PolyStringPropertyColumn;
import com.evolveum.midpoint.web.component.util.SelectableBeanImpl;
import com.evolveum.midpoint.web.component.util.SerializableSupplier;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -84,7 +85,7 @@ protected IColumn<SelectableBean<O>, String> createNameColumn(IModel<String> col
return new LinkColumn<SelectableBean<O>>(
columnNameModel == null ? createStringResource("ObjectType.name") : columnNameModel,
StringUtils.isEmpty(itemPath) ? ObjectType.F_NAME.getLocalPart() : itemPath,
SelectableBean.F_VALUE + "." +
SelectableBeanImpl.F_VALUE + "." +
(StringUtils.isEmpty(itemPath) ? "name" : itemPath)) {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -113,7 +114,7 @@ public void onClick(AjaxRequestTarget target, IModel<SelectableBean<O>> rowModel
} else {
return new PropertyColumn(
columnNameModel == null ? createStringResource("userBrowserDialog.name") : columnNameModel,
itemPath,SelectableBean.F_VALUE + "." + itemPath);
itemPath,SelectableBeanImpl.F_VALUE + "." + itemPath);
}
}
}
Expand Down Expand Up @@ -144,4 +145,9 @@ protected void onUpdateCheckbox(AjaxRequestTarget target, IModel<SelectableBean<
protected IModel<Boolean> getCheckBoxEnableModel(IModel<SelectableBean<O>> rowModel){
return Model.of(true);
}

@Override
protected boolean isRefreshEnabled() {
return false;
}
}
Expand Up @@ -12,6 +12,7 @@
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
Expand All @@ -27,6 +28,7 @@
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import org.apache.wicket.util.time.Duration;

/**
* @author Viliam Repan (lazyman)
Expand All @@ -51,6 +53,9 @@ public class BoxedTablePanel<T> extends BasePanel<T> implements Table {
private UserProfileStorage.TableId tableId;
private boolean showPaging;
private String additionalBoxCssClasses = null;
private boolean isRefreshEnabled;

private static final Duration TIMER_IN_SECONDS = Duration.seconds(3);

public BoxedTablePanel(String id, ISortableDataProvider provider, List<IColumn<T, String>> columns) {
this(id, provider, columns, null, Integer.MAX_VALUE);
Expand All @@ -62,9 +67,15 @@ public BoxedTablePanel(String id, ISortableDataProvider provider, List<IColumn<T
}

public BoxedTablePanel(String id, ISortableDataProvider provider, List<IColumn<T, String>> columns,
UserProfileStorage.TableId tableId, int pageSize) {
UserProfileStorage.TableId tableId, int pageSize) {
this(id, provider, columns, tableId, pageSize, false);
}

public BoxedTablePanel(String id, ISortableDataProvider provider, List<IColumn<T, String>> columns,
UserProfileStorage.TableId tableId, int pageSize, boolean isRefreshEnabled) {
super(id);
this.tableId = tableId;
this.isRefreshEnabled = isRefreshEnabled;

initLayout(columns, provider, pageSize);
}
Expand Down Expand Up @@ -102,6 +113,9 @@ protected Item<T> newRowItem(String id, int index, IModel<T> rowModel) {
table.setOutputMarkupId(true);
tableContainer.add(table);
box.add(tableContainer);
if (isRefreshEnabled) {
table.add(new AjaxSelfUpdatingTimerBehavior(TIMER_IN_SECONDS));
}

TableHeadersToolbar headersTop = new TableHeadersToolbar(table, provider);
headersTop.setOutputMarkupId(true);
Expand Down
Expand Up @@ -82,7 +82,7 @@ public class SelectableBeanObjectDataProvider<O extends ObjectType> extends Base
private Collection<SelectorOptions<GetOperationOptions>> options;

public SelectableBeanObjectDataProvider(Component component, Class<? extends O> type, Set<? extends O> selected ) {
super(component, true, true);
super(component, false, true);

Validate.notNull(type);
if (selected != null) {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.SelectableBeanImpl;
import com.evolveum.midpoint.web.util.TooltipBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -264,13 +265,13 @@ public static <T extends ObjectType> List<IColumn<SelectableBean<T>, String>> ge

List<ColumnTypeDto<String>> columnsDefs = Arrays.asList(
new ColumnTypeDto<String>("UserType.givenName", UserType.F_GIVEN_NAME.getLocalPart(),
SelectableBean.F_VALUE + ".givenName", false, true),
SelectableBeanImpl.F_VALUE + ".givenName", false, true),
new ColumnTypeDto<String>("UserType.familyName", UserType.F_FAMILY_NAME.getLocalPart(),
SelectableBean.F_VALUE + ".familyName", false, true),
SelectableBeanImpl.F_VALUE + ".familyName", false, true),
new ColumnTypeDto<String>("UserType.fullName", UserType.F_FULL_NAME.getLocalPart(),
SelectableBean.F_VALUE + ".fullName", false, true),
SelectableBeanImpl.F_VALUE + ".fullName", false, true),
new ColumnTypeDto<String>("UserType.emailAddress", UserType.F_EMAIL_ADDRESS.getLocalPart(),
SelectableBean.F_VALUE + ".emailAddress", false)
SelectableBeanImpl.F_VALUE + ".emailAddress", false)

);
columns.addAll(ColumnUtils.<SelectableBean<T>>createColumns(columnsDefs));
Expand Down Expand Up @@ -348,7 +349,7 @@ public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem,

List<ColumnTypeDto<String>> columnsDefs = Arrays.asList(
new ColumnTypeDto<String>("TaskType.executionStatus", TaskType.F_EXECUTION_STATUS.getLocalPart(),
SelectableBean.F_VALUE + ".executionStatus", false));
SelectableBeanImpl.F_VALUE + ".executionStatus", false));
columns.addAll(ColumnUtils.<SelectableBean<T>>createColumns(columnsDefs));

return columns;
Expand Down Expand Up @@ -398,12 +399,12 @@ public static <T extends AbstractRoleType> List<IColumn<SelectableBean<T>, Strin
List<ColumnTypeDto<String>> columnsDefs = Arrays.asList(
new ColumnTypeDto<String>("AbstractRoleType.displayName",
sortByDisplayName,
SelectableBean.F_VALUE + ".displayName", false, true),
SelectableBeanImpl.F_VALUE + ".displayName", false, true),
new ColumnTypeDto<String>("AbstractRoleType.description",
null,
SelectableBean.F_VALUE + ".description", false),
SelectableBeanImpl.F_VALUE + ".description", false),
new ColumnTypeDto<String>("AbstractRoleType.identifier", sortByIdentifer,
SelectableBean.F_VALUE + ".identifier", false)
SelectableBeanImpl.F_VALUE + ".identifier", false)

);
List<IColumn<SelectableBean<T>, String>> columns = createColumns(columnsDefs);
Expand Down Expand Up @@ -440,7 +441,7 @@ public static <T extends ObjectType> List<IColumn<SelectableBean<T>, String>> ge

List<ColumnTypeDto<String>> columnsDefs = Arrays.asList(
new ColumnTypeDto<String>("AbstractRoleType.description", null,
SelectableBean.F_VALUE + ".description", false)
SelectableBeanImpl.F_VALUE + ".description", false)

);

Expand Down
@@ -1,18 +1,20 @@
package com.evolveum.midpoint.web.component.util;

import com.evolveum.midpoint.web.page.admin.server.dto.TaskDto;
import com.evolveum.midpoint.web.page.admin.server.dto.TaskEditableState;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

import java.util.ArrayList;
import java.util.List;

public class TaskSelectableBean extends SelectableBeanImpl<TaskType> {

private boolean loadedChildren;
private List<TaskSelectableBean> children;

private TaskEditableState currentEditableState = new TaskEditableState();
private TaskEditableState originalEditableState;
// private TaskEditableState currentEditableState = new TaskEditableState();
// private TaskEditableState originalEditableState;

public TaskSelectableBean(TaskType taskType) {
super(taskType);
Expand All @@ -34,19 +36,27 @@ public void setChildren(List<TaskSelectableBean> children) {
this.children = children;
}

public TaskEditableState getCurrentEditableState() {
return currentEditableState;
}

public void setCurrentEditableState(TaskEditableState currentEditableState) {
this.currentEditableState = currentEditableState;
}

public boolean isCoordinator() {
return getValue().getWorkManagement() != null && getValue().getWorkManagement().getTaskKind() == TaskKindType.COORDINATOR;
}

public boolean isPartitionedMaster() {
return getValue().getWorkManagement() != null && getValue().getWorkManagement().getTaskKind() == TaskKindType.PARTITIONED_MASTER;
// public TaskEditableState getCurrentEditableState() {
// return currentEditableState;
// }
//
// public void setCurrentEditableState(TaskEditableState currentEditableState) {
// this.currentEditableState = currentEditableState;
// }

// public boolean isCoordinator() {
// return getValue().getWorkManagement() != null && getValue().getWorkManagement().getTaskKind() == TaskKindType.COORDINATOR;
// }
//
// public boolean isPartitionedMaster() {
// return getValue().getWorkManagement() != null && getValue().getWorkManagement().getTaskKind() == TaskKindType.PARTITIONED_MASTER;
// }

public static List<String> getOids(List<TaskType> taskDtoList) {
List<String> retval = new ArrayList<>();
for (TaskType taskDto : taskDtoList) {
retval.add(taskDto.getOid());
}
return retval;
}
}
Expand Up @@ -27,12 +27,14 @@
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.string.StringValue;
import org.apache.wicket.util.time.Duration;

import java.util.*;

Expand Down Expand Up @@ -178,12 +180,22 @@ protected void setDefaultSorting(BaseSortableDataProvider<SelectableBean<O>> pro
PageAdminObjectList.this.setDefaultSorting(provider);
}

@Override
protected BaseSortableDataProvider<SelectableBean<O>> initProvider() {
if (getCustomProvider() != null) {
return getCustomProvider();
}
return super.initProvider();
}
};

userListPanel.setAdditionalBoxCssClasses(WebComponentUtil.getBoxCssClasses(WebComponentUtil.classToQName(getPrismContext(), getType())));
userListPanel.setOutputMarkupId(true);
mainForm.add(userListPanel);
}
protected BaseSortableDataProvider<SelectableBean<O>> getCustomProvider() {
return null;
}

protected abstract Class<O> getType();

Expand Down

0 comments on commit b450731

Please sign in to comment.