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

at.spardat.xma.mdl.table.XMATableColumn 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: XMATableColumn.java 2726 2008-09-17 10:05:17Z webok $
package at.spardat.xma.mdl.table;

import at.spardat.enterprise.fmt.IFmt;
import at.spardat.xma.mdl.Atom;

/**
 * This class is a data object to specify information pertaining to columns
 * of table widget models.
 *
 * @author YSD, 26.04.2003 09:51:10
 */
public class XMATableColumn {


    private IFmt                formatter_;

    /**
     * Indicates that this table column may be sorted
     */
    private boolean             isSortable_ = true;

    /**
     * Indicates that this table column is visible on the UI.
     */
    private boolean             visible_ = true;

    /**
     * Indicates if this column tries to resloves its values to a registered image
     * @since 2.0.4
     */
    private boolean             imageColumn_ = false;

    /**
     * The table this column belongs to
     */
    private TableWMClient       table_;

    /**
     * a costum Comparator
     */
    private AtomComparator          comparator_;


    /**
     * Constructs the information necessary to describe a column of table
     * widget model.
     */
    public XMATableColumn (TableWMClient table) {
        table_ = table;
    }

    /**
     * Sets the formatter for a particular column
     *
     * @param formatter will be used to render the string representations of the column
     *         cells. This parameter may be null.
     */
    public void setFormatter (IFmt formatter) {
        formatter_ = formatter;
        // notify listeners of the change since the layout of a column might change
        table_.handle (table_.new TableRowsChangedEvent());
        table_.handle (table_.new SelectionChangedEvent(false));
    }

    /**
     * Returns the formatter set or null if none has been set.
     */
    public IFmt getFormatter() {
        return formatter_;
    }

    /**
     * Returns if this column is sortable.
     */
    public boolean isSortable() {
        return isSortable_;
    }

    /**
     * Sets whether this column is sortable
     */
    public void setSortable (boolean b) {
        isSortable_ = b;
    }

    /**
     * Returns true if this column is visible.
     */
    public boolean isVisible () {
        return visible_;
    }

    /**
     * Sets the visibility state of this column. If this method is never
     * called, the property defaults to true.
     *
     * @param b the boolean which indicates the visibility state.
     */
    public void setVisible (boolean b) {
        visible_ = b;
    }

    /**
     *
     * @return Returns the comparator_.
     */
    public AtomComparator getComparator() {
        return comparator_;
    }

    /**
     * Sets an AtomComparator for the client side sorting of the XMATableColumn.
     * The use of a costum comparator for XMATableColumns is optional.
     * If no AtomComparator is set then the Atom's type natural ordering is used.
     * @param comparator The comparator_ to set.
     */
    public void setComparator(AtomComparator comparator) {
        this.comparator_ = comparator;
    }

    /**
     * This interace is used to implement a costum comparator for an XMATableColumn.
     * AtomComparator#compare is to use like java.util.Comparator#compare(java.lang.Object, java.lang.Object).
     * but the objects to compare are always of the type at.spardat.xma.mdl.Atom.
     * For the sorting of an XMATableColumn the AtomComparator is always called with both arguments != null,
     * so no compare null logic has to be implemented.
     * The use of a costum comparator for XMATableColumns is optional.
     * If no AtomComparator is set then the Atom's type natural ordering is used.
     * @author S3460
     * @since version_number
     */
    public static interface AtomComparator{
        /**
         * Use this method to implement a costum comparator for XMATableColumns.
         * Used like java.util.Comparator#compare but instead of objects the arguments
         * are of the type at.spardat.xma.mdl.Atom, as at the IWModelClients data is always
         * stored as Atoms.
         * Contrary to java.util.Comparator#compare you do not have to take care of null arguments!
         *
         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
         *
         * @author S3460
         */
        int compare(Atom a1, Atom a2);
    }

    /**
     * Shows if a column tries to resolve its values to a registered images.
     * @return true - if this column tries to resloves its values to a registered image - otherwise false
     * @since 2.0.4
     * @author s3460
     */
    public boolean isImageColumn() {
        return imageColumn_;
    }

    /**
     * Set 'imageColumn_' to true if this column tries to resolve its values to a registered image (which then is shown).
     * If the column's value cannot be resolved then the value itself is shown at the UI.
     * Such a column can be filled with numbers as well as Strings.
     * So it is possible to mix Strings resolving to an image (registered short values) with any other Strings in one column.
     * Values representing '0' (Strings or numbers) are interpreted as no image and are not shown.
     * @param imageColumn_ - set to true if an image should be shown.
     * @since 2.0.4
     * @author s3460
     */
    public void setImageColumn(boolean imageColumn) {
        this.imageColumn_ = imageColumn;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy