view dwtx/jface/viewers/ViewerRow.d @ 43:ea8ff534f622

Fix override and super aliases
author Frank Benoit <benoit@tionex.de>
date Fri, 11 Apr 2008 01:24:25 +0200
parents b6c35faf97c8
children 46a6e0e6ccd4
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2006, 2007 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
 *                                                fix for bug 166346, bug 167325s
 *                                              - Fix for bug 174355
 * Port to the D programming language:
 *     Frank Benoit <benoit@tionex.de>
 *******************************************************************************/

module dwtx.jface.viewers.ViewerRow;

import dwtx.jface.viewers.ViewerCell;
import dwtx.jface.viewers.ViewerRow;
import dwtx.jface.viewers.TreePath;

import dwt.graphics.Color;
import dwt.graphics.Font;
import dwt.graphics.Image;
import dwt.graphics.Point;
import dwt.graphics.Rectangle;
import dwt.widgets.Control;
import dwt.widgets.Widget;

import dwt.dwthelper.utils;

/**
 * ViewerRow is the abstract superclass of the part that represents items in a
 * Table or Tree. Implementors of {@link ColumnViewer} have to provide a
 * concrete implementation for the underlying widget
 *
 * @since 3.3
 *
 */
public abstract class ViewerRow : Cloneable {

    /**
     * Constant denoting the row above the current one (value is 1).
     *
     * @see #getNeighbor(int, bool)
     */
    public static const int ABOVE = 1;

    /**
     * Constant denoting the row below the current one (value is 2).
     *
     * @see #getNeighbor(int, bool)
     */
    public static const int BELOW = 2;

    /**
     * Get the bounds of the entry at the columnIndex,
     *
     * @param columnIndex
     * @return {@link Rectangle}
     */
    public abstract Rectangle getBounds(int columnIndex);

    /**
     * Return the bounds for the whole item.
     *
     * @return {@link Rectangle}
     */
    public abstract Rectangle getBounds();

    /**
     * Return the item for the receiver.
     *
     * @return {@link Widget}
     */
    public abstract Widget getItem();

    /**
     * Return the number of columns for the receiver.
     *
     * @return the number of columns
     */
    public abstract int getColumnCount();

    /**
     * Return the image at the columnIndex.
     *
     * @param columnIndex
     * @return {@link Image} or <code>null</code>
     */
    public abstract Image getImage(int columnIndex);

    /**
     * Set the image at the columnIndex
     *
     * @param columnIndex
     * @param image
     */
    public abstract void setImage(int columnIndex, Image image);

    /**
     * Get the text at the columnIndex.
     *
     * @param columnIndex
     * @return {@link String}
     */
    public abstract String getText(int columnIndex);

    /**
     * Set the text at the columnIndex
     *
     * @param columnIndex
     * @param text
     */
    public abstract void setText(int columnIndex, String text);

    /**
     * Get the background at the columnIndex,
     *
     * @param columnIndex
     * @return {@link Color} or <code>null</code>
     */
    public abstract Color getBackground(int columnIndex);

    /**
     * Set the background at the columnIndex.
     *
     * @param columnIndex
     * @param color
     */
    public abstract void setBackground(int columnIndex, Color color);

    /**
     * Get the foreground at the columnIndex.
     *
     * @param columnIndex
     * @return {@link Color} or <code>null</code>
     */
    public abstract Color getForeground(int columnIndex);

    /**
     * Set the foreground at the columnIndex.
     *
     * @param columnIndex
     * @param color
     */
    public abstract void setForeground(int columnIndex, Color color);

    /**
     * Get the font at the columnIndex.
     *
     * @param columnIndex
     * @return {@link Font} or <code>null</code>
     */
    public abstract Font getFont(int columnIndex);

    /**
     * Set the {@link Font} at the columnIndex.
     *
     * @param columnIndex
     * @param font
     */
    public abstract void setFont(int columnIndex, Font font);

    /**
     * Get the ViewerCell at point.
     *
     * @param point
     * @return {@link ViewerCell}
     */
    public ViewerCell getCell(Point point) {
        int index = getColumnIndex(point);
        return getCell(index);
    }

    /**
     * Get the columnIndex of the point.
     *
     * @param point
     * @return int or -1 if it cannot be found.
     */
    public int getColumnIndex(Point point) {
        int count = getColumnCount();

        // If there are no columns the column-index is 0
        if (count is 0) {
            return 0;
        }

        for (int i = 0; i < count; i++) {
            if (getBounds(i).contains(point)) {
                return i;
            }
        }

        return -1;
    }

    /**
     * Get a ViewerCell for the column at index.
     *
     * @param column
     * @return {@link ViewerCell} or <code>null</code> if the index is
     *         negative.
     */
    public ViewerCell getCell(int column) {
        if (column >= 0)
            return new ViewerCell(cast(ViewerRow) clone(), column, getElement());

        return null;
    }

    /**
     * Get the Control for the receiver.
     *
     * @return {@link Control}
     */
    public abstract Control getControl();

    /**
     * Returns a neighboring row, or <code>null</code> if no neighbor exists
     * in the given direction. If <code>sameLevel</code> is <code>true</code>,
     * only sibling rows (under the same parent) will be considered.
     *
     * @param direction
     *            the direction {@link #BELOW} or {@link #ABOVE}
     *
     * @param sameLevel
     *            if <code>true</code>, search only within sibling rows
     * @return the row above/below, or <code>null</code> if not found
     */
    public abstract ViewerRow getNeighbor(int direction, bool sameLevel);

    /**
     * The tree path used to identify an element by the unique path
     *
     * @return the path
     */
    public abstract TreePath getTreePath();

    public /+override+/ abstract Object clone();

    /**
     * @return the model element
     */
    public abstract Object getElement();

    public override hash_t toHash() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((getItem() is null) ? 0 : getItem().toHash());
        return result;
    }

    public override int opEquals(Object obj) {
        if (this is obj)
            return true;
        if (obj is null)
            return false;
        if (this.classinfo !is obj.classinfo)
            return false;
        ViewerRow other = cast(ViewerRow) obj;
        if (getItem() is null) {
            if (other.getItem() !is null)
                return false;
        } else if (!getItem().opEquals(other.getItem()))
            return false;
        return true;
    }

}