All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.mdl.paging.PagingWM Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2003, 2010 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

// @(#) $Id:  $
package at.spardat.xma.mdl.paging;

import java.io.IOException;

import at.spardat.xma.mdl.ModelChangeEvent;
import at.spardat.xma.mdl.NewModelEvent;
import at.spardat.xma.mdl.NewModelEventFactory;
import at.spardat.xma.mdl.WModel;
import at.spardat.xma.mdl.table.ITableWM;
import at.spardat.xma.mdl.table.TableWM;
import at.spardat.xma.mdl.util.TransNumber;
import at.spardat.xma.page.Page;
import at.spardat.xma.serializer.XmaInput;
import at.spardat.xma.serializer.XmaOutput;

/**
 * Implements the part of the paging model which is available on server and client side.
 * All this data is automatically synchronized between client and server. So you can let the user
 * modify this data using the GUI and query it on the server for loading the required slice of the
 * data objects to show in the corresponding table.
 *
 * @author gub
 * @since 2.3.0
 */
public class PagingWM extends WModel implements IPagingWM {
    /** Index of the first data object to show in the result list. */
    TransNumber offset = new TransNumber(TransNumber.T_INT,0);

    /** Number of data objects to show at the same time. */
    TransNumber pageSize = new TransNumber(TransNumber.T_SHORT,100);

    /** Maximum pageSize the user can choose. */
    TransNumber maxPageSize = new TransNumber(TransNumber.T_SHORT,1000);

    /** Total number of data objects in the result list. */
    TransNumber resultSize = new TransNumber(TransNumber.T_INT,Integer.MAX_VALUE);

    /** Number of pages to jump forward or back when the user presses the fastNext or fastBack button. */
    TransNumber jumpSize = new TransNumber(TransNumber.T_SHORT, 5);

    /** Index of the column to sort. */
    TransNumber sortingColumn = new TransNumber(TransNumber.T_SHORT,-1);

    /** Defines if sorting should be ascending or descending. */
    TransNumber ascending = new TransNumber(TransNumber.T_BYTE,1);

    /** Holds all members for synchronization. */
    TransNumber[] data;

    /** Flag if this was instantiated on the server side. */
    boolean isAtServer=true;

    /** Flag if the corresponding table was changed on server side. */
    boolean tableChanged;

    /** Corresponding table holding the paged data. */
    ITableWM table;

    /**
     * Constructs the paging model.
     * @param id a unique id identifying this WidgetModel within its page.
     * @param pm the {@link Page} this model belongs to.
     * @param table the corresponding table holding the data.
     */
    public PagingWM(short id, Page pm, ITableWM table) {
        super(id, pm);
        this.table=table;
        data = new TransNumber[] { offset, pageSize, maxPageSize, resultSize, jumpSize, sortingColumn, ascending };
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.mdl.paging.IPagingWM#getOffset()
     */
    public int getOffset() {
        return offset.toInt();
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.mdl.paging.IPagingWM#setOffset(int)
     */
    public void setOffset(int offset) {
        this.offset.set(offset);
        handle(new PagingModelChangeEvent(this, false));
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.mdl.paging.IPagingWM#getPageSize()
     */
    public short getPageSize() {
        return pageSize.toShort();
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.mdl.paging.IPagingWM#setPageSize(short)
     */
    public void setPageSize(short pageSize) {
        this.pageSize.set(pageSize);
        handle(new PagingModelChangeEvent(this, false));
    }

    /**
     * Used by UIDelegate to set the page size.
     * This method does not actualize the GUI.
     */
    void setPageSizeFromUI(short pageSize) {
        this.pageSize.set(pageSize);
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.mdl.paging.IPagingWM#getMaxPageSize()
     */
    public short getMaxPageSize() {
        return maxPageSize.toShort();
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.mdl.paging.IPagingWM#setMaxPageSize(short)
     */
    public void setMaxPageSize(short maxPageSize) {
        this.maxPageSize.set(maxPageSize);
        if(maxPageSize




© 2015 - 2024 Weber Informatics LLC | Privacy Policy