view dwtx/jface/viewers/AbstractComboBoxCellEditor.d @ 70:46a6e0e6ccd4

Merge with d-fied sources of 3.4M7
author Frank Benoit <benoit@tionex.de>
date Thu, 22 May 2008 01:36:46 +0200
parents
children 4878bef4a38e
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2008 Tom Schindl 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:
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation (bug 174739)
 * Port to the D programming language:
 *     Frank Benoit <benoit@tionex.de>
 ******************************************************************************/

module dwtx.jface.viewers.AbstractComboBoxCellEditor;

import dwt.DWT;
import dwt.custom.CCombo;
import dwt.widgets.Composite;

/**
 * Abstract base class for Cell-Editors presented as combo boxes
 *
 * @since 3.4
 *
 */
abstract class AbstractComboBoxCellEditor extends CellEditor {
    /**
     * The list is dropped down when the activation is done through the mouse
     */
    public static final int DROP_DOWN_ON_MOUSE_ACTIVATION = 1;

    /**
     * The list is dropped down when the activation is done through the keyboard
     */
    public static final int DROP_DOWN_ON_KEY_ACTIVATION = 1 << 1;

    /**
     * The list is dropped down when the activation is done without
     * ui-interaction
     */
    public static final int DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION = 1 << 2;

    /**
     * The list is dropped down when the activation is done by traversing from
     * cell to cell
     */
    public static final int DROP_DOWN_ON_TRAVERSE_ACTIVATION = 1 << 3;

    private int activationStyle = DWT.NONE;

    /**
     * Create a new cell-editor
     *
     * @param parent
     *            the parent of the combo
     * @param style
     *            the style used to create the combo
     */
    AbstractComboBoxCellEditor(Composite parent, int style) {
        super(parent, style);
    }

    /**
     * Creates a new cell editor with no control and no st of choices.
     * Initially, the cell editor has no cell validator.
     *
     */
    AbstractComboBoxCellEditor() {
    }

    /*
     * (non-Javadoc)
     *
     * @see dwtx.jface.viewers.CellEditor#activate(dwtx.jface.viewers.ColumnViewerEditorActivationEvent)
     */
    public void activate(ColumnViewerEditorActivationEvent activationEvent) {
        super.activate(activationEvent);
        if (activationStyle !is DWT.NONE) {
            bool dropDown = false;
            if ((activationEvent.eventType is ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION || activationEvent.eventType is ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION)
                    && (activationStyle & DROP_DOWN_ON_MOUSE_ACTIVATION) !is 0 ) {
                dropDown = true;
            } else if (activationEvent.eventType is ColumnViewerEditorActivationEvent.KEY_PRESSED
                    && (activationStyle & DROP_DOWN_ON_KEY_ACTIVATION) !is 0 ) {
                dropDown = true;
            } else if (activationEvent.eventType is ColumnViewerEditorActivationEvent.PROGRAMMATIC
                    && (activationStyle & DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION) !is 0) {
                dropDown = true;
            } else if (activationEvent.eventType is ColumnViewerEditorActivationEvent.TRAVERSAL
                    && (activationStyle & DROP_DOWN_ON_TRAVERSE_ACTIVATION) !is 0) {
                dropDown = true;
            }

            if (dropDown) {
                getControl().getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        ((CCombo) getControl()).setListVisible(true);
                    }

                });

            }
        }
    }

    /**
     * This method allows to control how the combo reacts when activated
     *
     * @param activationStyle
     *            the style used
     */
    public void setActivationStyle(int activationStyle) {
        this.activationStyle = activationStyle;
    }
}