Package org.eclipse.nebula.widgets.nattable.edit.event

Source Code of org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent

/*******************************************************************************
* Copyright (c) 2012, 2013 Original authors 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:
*     Original authors and others - initial API and implementation
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.edit.event;

import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
import org.eclipse.swt.widgets.Composite;

/**
* This event is used to activate an editor inline. It is used internally if a
* single cell should be edited by selection, e.g. on pressing the F2 key on the
* current selected cell.
* <p>
* This event is needed to do the translation of the coordinates and bounds
* needed for inline editing. On activating an editor via selection these
* informations are not known and need to be evaluated through the layer event
* handlers.
*/
public class InlineCellEditEvent implements ILayerEvent {

    /**
     * The layer the cellCoordinates rely on. The layer will change on event
     * processing to always match the translated coordinates.
     */
    private ILayer layer;
    /**
     * The coordinates of the cell to edit for the set layer.
     */
    private final PositionCoordinate cellCoordinate;
    /**
     * The parent Composite, needed for the creation of the editor control.
     */
    private final Composite parent;
    /**
     * The {@link IConfigRegistry} containing the configuration of the current
     * NatTable instance the command should be executed for. This is necessary
     * because the edit controllers in the current architecture are not aware of
     * the instance they are running in.
     */
    private final IConfigRegistry configRegistry;
    /**
     * The value that should be put to the activated editor control.
     */
    private final Object initialValue;

    /**
     *
     * @param layer
     *            The layer the cellCoordinates rely on.
     * @param cellCoordinate
     *            The coordinates of the cell to edit for the set layer.
     * @param parent
     *            The parent Composite, needed for the creation of the editor
     *            control.
     * @param configRegistry
     *            The {@link IConfigRegistry} containing the configuration of
     *            the current NatTable instance the command should be executed
     *            for. This is necessary because the edit controllers in the
     *            current architecture are not aware of the instance they are
     *            running in.
     * @param initialValue
     *            The value that should be put to the activated editor control.
     */
    public InlineCellEditEvent(ILayer layer, PositionCoordinate cellCoordinate,
            Composite parent, IConfigRegistry configRegistry,
            Object initialValue) {

        this.layer = layer;
        this.cellCoordinate = cellCoordinate;
        this.parent = parent;
        this.configRegistry = configRegistry;
        this.initialValue = initialValue;
    }

    @Override
    public boolean convertToLocal(ILayer localLayer) {
        cellCoordinate.columnPosition = localLayer
                .underlyingToLocalColumnPosition(layer,
                        cellCoordinate.columnPosition);
        if (cellCoordinate.columnPosition < 0
                || cellCoordinate.columnPosition >= localLayer.getColumnCount()) {
            return false;
        }

        cellCoordinate.rowPosition = localLayer.underlyingToLocalRowPosition(
                layer, cellCoordinate.rowPosition);
        if (cellCoordinate.rowPosition < 0
                || cellCoordinate.rowPosition >= localLayer.getRowCount()) {
            return false;
        }

        this.layer = localLayer;
        return true;
    }

    /**
     * @return The column position of the cell to edit.
     */
    public int getColumnPosition() {
        return cellCoordinate.columnPosition;
    }

    /**
     * @return The row position of the cell to edit.
     */
    public int getRowPosition() {
        return cellCoordinate.rowPosition;
    }

    /**
     * @return The parent Composite, needed for the creation of the editor
     *         control.
     */
    public Composite getParent() {
        return parent;
    }

    /**
     * @return The {@link IConfigRegistry} containing the configuration of the
     *         current NatTable instance the command should be executed for.
     *         This is necessary because the edit controllers in the current
     *         architecture are not aware of the instance they are running in.
     */
    public IConfigRegistry getConfigRegistry() {
        return configRegistry;
    }

    /**
     * @return The value that should be put to the activated editor control.
     */
    public Object getInitialValue() {
        return initialValue;
    }

    @Override
    public InlineCellEditEvent cloneEvent() {
        return new InlineCellEditEvent(layer, new PositionCoordinate(
                cellCoordinate), parent, configRegistry, initialValue);
    }

}
TOP

Related Classes of org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.