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

at.spardat.xma.mdl.table.TableWMClient Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/*******************************************************************************
 * Copyright (c) 2003, 2007 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: TableWMClient.java 7142 2011-01-27 15:17:25Z hoenninger $
package at.spardat.xma.mdl.table;

import org.eclipse.swt.widgets.TableItem;

import at.spardat.enterprise.fmt.IFmt;
import at.spardat.xma.mdl.ModelChangeEvent;
import at.spardat.xma.mdl.NewModelEvent;
import at.spardat.xma.mdl.UIDelegateClient;
import at.spardat.xma.mdl.UIDelegateFactoryClient;
import at.spardat.xma.mdl.WModel;
import at.spardat.xma.page.Page;
import at.spardat.xma.page.PageClient;

/**
 * The implementation of a TableWM widget model implementation at the client
 * side.
 *
 * @author YSD, 27.04.2003 16:19:23
 */
public class TableWMClient extends TableWM implements ITableWMClient {

    /**
     * Specifies column information.
     */
    protected XMATableColumn []                 columns_;

    private TableUIDelegateClient               ui_;

    TableWM2UIListenerClient                    wm2UIlistener_;


    /**
     * Constructor. Dont forget to call setFormatter if the table
     * does not merley contain Strings.
     *
     * @param id uniquely identifies the model within its page
     * @param pm the enclosing page model this widget model belongs to.
     * @param columnCount the number of columns this table has
     * @param style bit or combination of the style constants S_* of this class and its superclass.
     */
    public TableWMClient (short id, Page pm, int columnCount, int style) {
        super (id, pm, columnCount, style);
        columns_ = new XMATableColumn[columnCount];
        for (int i=0; icolumnIndex.
     *
     * @param columnIndex the zero based index of the column
     * @param formatter the IFmt object determining the string layout of a column cell.
     * @exception ArrayIndexOutOfBoundsException if columnIndex not valid.
     */
    public void setFormatter (int columnIndex, IFmt formatter) {
        columns_[columnIndex].setFormatter (formatter);
    }

    /**
     * Sets the property if the column at index columnIndex may be sorted
     * by the user or not. If this method is not called for a particular column,
     * the value defaults to true.
     *
     * @param columnIndex the zero based index of the column
     * @param what false if sorting of the column should be supressed, true otherwise.
     */
    public void setSortable (int columnIndex, boolean what) {
        columns_[columnIndex].setSortable (what);
    }

    /**
     * Returns true if the column at index columnIndex may be sorted.
     */
    public boolean isSortable (int columnIndex) {
        return columns_[columnIndex].isSortable();
    }

    /**
     * Sorts the table contents on the UI using a particular column as sort order column. Note
     * that this method does not sort the widget model. The model stays completely unchanged.
     * It merely changes the permutation of rows on the UI. If you are working with zero based
     * indexes on the table model, this indexes may no longer correspond with the rows rank you
     * see in the UI table. E.g., selecting the first row in the table model will not select
     * the first row in the UI table.

* * The table won't be sorted if any of the following is true: *

    *
  • The UI is not created yet. *
  • The provided column is not sortable. *
  • The cells in the provided column are not all of the same type. *
      * * The sort algorithm is stable. Therefore sorting along columns c1 and c2 * in succession result in a sort order where rows are primarely sorted along c2. * Within rows with the same c2 value, sort order is defined by c1. * * @param columnIndex the index of the column to be sorted. */ public void sort (int columnIndex) { if (columnIndex < 0 || columnIndex >= columnCount_) throw new IllegalArgumentException(); ui_.sort(columnIndex); } /** * Returns the formatter set for the column at index columnIndex or null * if none has been set. */ public IFmt getFormatter (int columnIndex) { return columns_[columnIndex].getFormatter(); } /** * Sets the property whether the column at index columnIndex is * visible or not. This property defaults to true, i.e., if this * method is never called, the column is visible on the UI. * * @param columnIndex zero based index of the column * @param what true indicates that the column should be visible. */ public void setVisible (int columnIndex, boolean what) { columns_[columnIndex].setVisible(what); } /** * Returns the visibility state of a particular column. * * @param columnIndex zero based index of the column * @return true if visible, false otherwise */ public boolean isVisible (int columnIndex) { return columns_[columnIndex].isVisible(); } /** * @see at.spardat.xma.mdl.IWModelClient#getUIDelegate() */ public UIDelegateClient getUIDelegate() { return ui_; } /** * @see at.spardat.xma.mdl.WModel#handle(at.spardat.xma.mdl.ModelChangeEvent) */ public boolean handle (ModelChangeEvent event) { boolean success = super.handle(event); if (success && !event.isFromUI()) { // notify the UIDelegate of the modification ui_.handleModelChangeEvent(event); } return success; } /** * Returns the column at the provided zero based index. * * @param i zero based index indentifying a column * @return a TableColumn object describing the column * @exception ArrayIndexOutOfBounds if i greater equal getColumnCount or * less than zero. */ public XMATableColumn getColumn (int i) { return columns_[i]; } /** * @see at.spardat.xma.mdl.table.ITableWMClient#selectByUIIndex(int) */ public void selectByUIIndex (int index) { if (index < 0 || index >= size()) return; if (ui_ == null) return; int modelIndex = ui_.swtIndex2ModelIndex(index); if (modelIndex >= 0 && modelIndex < size()) selectByModelIndex(modelIndex); } /** * @see at.spardat.xma.mdl.IWModelClient#isEditable() */ public boolean isEditable() { return ui_.isEditable(); } /** * @see at.spardat.xma.mdl.IWModelClient#isEnabled() */ public boolean isEnabled() { return ui_.isEnabled(); } /** * @see at.spardat.xma.mdl.IWModelClient#setEditable(boolean) */ public void setEditable(boolean what) { ui_.setEditable(what); } /** * @see at.spardat.xma.mdl.IWModelClient#setEnabled(boolean) */ public void setEnabled(boolean what) { ui_.setEnabled(what); } /** * @see at.spardat.xma.mdl.table.ITableWMClient#sortNatural() */ public void sortNatural() { ui_.sortNatural(); } /** * @see at.spardat.xma.mdl.table.ITableWMClient#getSortingColumn() * @since version_number * @author S3460 */ public int getSortingColumn(){ return ui_.getSortingColumn(); } /** * @see at.spardat.xma.mdl.table.ITableWMClient#isSortingColumnAscending() * @since version_number * @author S3460 */ public boolean isSortingColumnAscending(){ return ui_.isSortingColumnAscending(); } /** * @see at.spardat.xma.mdl.table.ITableWMClient#hasSortIndicator() */ public boolean hasSortIndicator() { return ui_.hasSortIndicator(); } /** * @see at.spardat.xma.mdl.table.ITableWMClient#setSortIndicator(boolean) */ public void setSortIndicator(boolean showSortIndicator) { ui_.setSortIndicator(showSortIndicator); } /** * @see at.spardat.xma.mdl.table.ITableWMClient#setExternalSorter(TableExternalSorterClient) */ public void setExternalSorter(TableExternalSorterClient externalSorter) { ui_.setExternalSorter(externalSorter); } /** * Returns the model's TableRow to the given TableItem. It returns the XMA TableRow * that corresponds to the tree item of the underlying UI library. In the case of SWT, * the argument must be an instance of class TableItem.

      * * @param uiTableItem SWT-TableItem if SWT is the UI-library you are using. Must not be null. * The SWT-TableItem must not be disposed. * @return TableRow for the given TableItem */ public static TableRow getTableRowFor (Object uiTableItem) { if (uiTableItem == null) throw new IllegalArgumentException (); return TableUIDelegateClient.row2Item((TableItem)uiTableItem); } /** * Sets a TableWM2UIListenerClient which is called for every model cell to TableItem event. * @param listener * @see ITableWMClient#setTableWM2UIListener(TableWM2UIListenerClient) * @since 2.0.4 * @author s3460 */ public void setTableWM2UIListener(TableWM2UIListenerClient listener) { wm2UIlistener_ = listener; } /** * Converts a model column index to its corresponding UI index. * @since 2.1.1 */ public int modelColumnIndexToUIColumnIndex(int index) { return ui_.modelColumnIndex2SwtColumnIndex(index); } /** * Converts a UI column index to its corresponding model column index. * @since 2.2.0 */ public int uiColumnIndexToModelColumnIndex(int uiIndex) { return ui_.swtColumnIndex2modelColumnIndex(uiIndex); } /** * Converts a model row index to its corresponding UI index. * @since 2.2.0 */ public int modelIndexToUIIndex(int modelIndex) { return ui_.modelIndex2SwtIndex(modelIndex); } /** * Converts a UI row index to its corresponding model row index. * @since 2.2.0 */ public int uiIndex2ModelIndex(int uiIndex) { return ui_.swtIndex2ModelIndex(uiIndex); } /** * Event class used to notify the dynamic registration of a new TableWMClient. * @author gub * @since 2.1.0 * @see Page#addWModel(WModel) */ public static class NewTableWMClientEvent extends NewTableWMEvent { /** empty constructor for deserialization */ public NewTableWMClientEvent() {} /** * constructor which initializes the modelType * @param columnCount number of columns this table has * @param style bit or combination of the style constants S_*. */ public NewTableWMClientEvent(int columnCount, int style, byte[] columnTypes) { super(columnCount,style,columnTypes); } // see at.spardat.xma.mdl.NewModelEvent.createModel() public WModel createModel(short id,Page page) { return new TableWMClient(id,page,columns,style); } } // see at.sparda.xma.mdl.WModel.createNewModelEvent() public NewModelEvent createNewModelEvent() { int style = S_NULL; if(isMultiSelect()) style|=S_MULTI_SELECT; if(isOneWay()) style|=S_ONE_WAY; return new NewTableWMClientEvent(getColumnCount(),style,columnTypes); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy