Paginated view

Les provider de vue standards rencontrent des soucis de performance dans le cas de grosses volumétries. Une vue “basic” permet de régler ce problème.

Le principe est simple : au lieu de demander tous les objets, seuls les objets concernés par la configuration de pagination sont appelés (nombre d’éléments par page, tri, page courante).

Ainsi, la méthode fournissant les objets est rappelée à chaque modification de l’un de ces paramètres.

Exemple

import com.axemble.vdoc.sdk.exceptions.ModuleException;
import com.axemble.vdoc.sdk.exceptions.SDKException;
import com.axemble.vdoc.sdk.interfaces.IProperty;
import com.axemble.vdoc.sdk.interfaces.IViewController;
import com.axemble.vdoc.sdk.interfaces.IWorkflow;
import com.axemble.vdoc.sdk.interfaces.IWorkflowInstance;
import com.axemble.vdoc.sdk.interfaces.runtime.INavigateContext;
import com.axemble.vdoc.sdk.providers.BaseViewProvider;
import com.axemble.vdp.ui.core.providers.IBasicViewProvider;
import com.axemble.vdp.ui.framework.composites.base.CtlAbstractView;
import com.axemble.vdp.ui.framework.composites.base.models.views.BasicViewModel;
import com.axemble.vdp.ui.framework.composites.base.models.views.ViewModelColumn;
import com.axemble.vdp.ui.framework.composites.base.models.views.ViewModelItem;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

public class DummyViewProvider extends BaseViewProvider implements IBasicViewProvider<IWorkflowInstance> {

    public class ViewParameters {
        public int getCountRowsPerPage() {
            return getView().getRowsPerPage();
        }

        public int getCurrentPageIndex() {
            return getView().getPageIndex();
        }

        public String getCurrentSortedColumn() {
            if (getView().getListView().getCurrentSortingColumn() != null) {
                return getView().getListView().getCurrentSortingColumn().getName();
            }
            return null;
        }

        public int getCurrentSortedColumnOrder() {
            return getView().getListView().getCurrentSortingColumn().getSortingOrder();
        }
    }

    /**
     * The default class logger
     */
    private static final com.axemble.vdoc.sdk.utils.Logger LOG = com.axemble.vdoc.sdk.utils.Logger.getLogger(DummyViewProvider.class);

    protected ViewParameters viewParameters = new ViewParameters();
    
    public DummyViewProvider(INavigateContext context, CtlAbstractView view) {
        super(context, view);
    }

    @Override
    public List<IWorkflowInstance> getVisibleObjects() {
        List<IWorkflowInstance> workflowInstances = new ArrayList<>();
        try {
            IViewController viewController = getWorkflowModule().getViewController(getWorkflowModule().getLoggedOnUserContext());
            viewController.setStart((viewParameters.getCurrentPageIndex() - 1) * viewParameters.getCountRowsPerPage());
            viewController.setCount(viewParameters.getCountRowsPerPage());
            if (viewParameters.getCurrentSortedColumn() != null) {
                viewController.setOrderBy(viewParameters.getCurrentSortedColumn(), getColumnTypeClass(viewParameters.getCurrentSortedColumn()), viewParameters.getCurrentSortedColumnOrder() == 1);
            }
            Collection<IWorkflowInstance> workflowInstancesResult = viewController.evaluate((IWorkflow) getWorkflowModule().getElementByProtocolURI("uri://vdoc/workflow/5"));
            if (workflowInstancesResult != null) {
                workflowInstances.addAll(workflowInstancesResult);
            }
        } catch (ModuleException e) {
            LOG.error(e);
            throw new SDKException(e);
        }
        return workflowInstances;
    }
    
    private Class getColumnTypeClass(String columnName) {
        BasicViewModel<IWorkflowInstance> basicViewModel = (BasicViewModel<IWorkflowInstance>) getModel();
        ViewModelColumn viewModelColumn = basicViewModel.getColumnByName(columnName);
        switch (viewModelColumn.getType()) {
            case ViewModelColumn.TYPE_FLOAT:
                return Float.class;
            case ViewModelColumn.TYPE_INTEGER:
                return Long.class;
            case ViewModelColumn.TYPE_STRING:
                return String.class;
            case ViewModelColumn.TYPE_TIMESTAMP:
                return Date.class;
        }
        return null;
    }

    @Override
    public ViewModelItem fetchLine(IWorkflowInstance iWorkflowInstance) {
        ViewModelItem viewModelItem = new ViewModelItem();
        viewModelItem.setKey(iWorkflowInstance.getProtocolURI());
        viewModelItem.setValue(IProperty.System.REFERENCE, iWorkflowInstance.getValue(IProperty.System.REFERENCE));
        viewModelItem.setValue(IProperty.System.TITLE, iWorkflowInstance.getValue(IProperty.System.TITLE));
        viewModelItem.setValue(IProperty.System.CREATION_DATE, iWorkflowInstance.getValue(IProperty.System.CREATION_DATE));
        viewModelItem.setValue(IProperty.System.CREATOR, iWorkflowInstance.getValue(IProperty.System.CREATOR));
        return viewModelItem;
    }

}

Source : https://wiki.myvdoc.net/xwiki/bin/view/Dev+Floor/HowToBuildABasicView