Search in sources :

Example 76 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class PositionCoordinateTest method setup.

@Before
public void setup() {
    ILayer layer = new DataLayerFixture();
    this.p1 = new PositionCoordinate(layer, 1, 2);
    this.p2 = new PositionCoordinate(layer, 1, 2);
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Before(org.junit.Before)

Example 77 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class CellSelectionTest method willSelectBodyCellAndShouldHaveColumnHeaderSelected.

@Test
public void willSelectBodyCellAndShouldHaveColumnHeaderSelected() {
    // Select body cell
    // The cell position is a grid layer position
    this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 2, 2, false, false));
    // Get body layer cell corresponding to the selected body cell
    ILayer bodyLayer = this.gridLayer.getBodyLayer();
    // The column position is 1 because it takes into account the offset of
    // the row header
    ILayerCell cell = bodyLayer.getCellByPosition(1, 1);
    // Assert the cell is in selected state
    Assert.assertEquals(DisplayMode.SELECT, cell.getDisplayMode());
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 78 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class LayerCommandUtil method convertPositionToTargetContext.

public static PositionCoordinate convertPositionToTargetContext(PositionCoordinate positionCoordinate, ILayer targetLayer) {
    ILayer layer = positionCoordinate.getLayer();
    if (layer == targetLayer) {
        return positionCoordinate;
    }
    int columnPosition = positionCoordinate.getColumnPosition();
    int underlyingColumnPosition = layer.localToUnderlyingColumnPosition(columnPosition);
    if (underlyingColumnPosition < 0) {
        return null;
    }
    int rowPosition = positionCoordinate.getRowPosition();
    int underlyingRowPosition = layer.localToUnderlyingRowPosition(rowPosition);
    if (underlyingRowPosition < 0) {
        return null;
    }
    ILayer underlyingLayer = layer.getUnderlyingLayerByPosition(columnPosition, rowPosition);
    if (underlyingLayer == null) {
        return null;
    }
    return convertPositionToTargetContext(new PositionCoordinate(underlyingLayer, underlyingColumnPosition, underlyingRowPosition), targetLayer);
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate) ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 79 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class LayerCommandUtil method convertRowPositionToTargetContext.

public static RowPositionCoordinate convertRowPositionToTargetContext(RowPositionCoordinate rowPositionCoordinate, ILayer targetLayer) {
    if (rowPositionCoordinate != null) {
        ILayer layer = rowPositionCoordinate.getLayer();
        if (layer == targetLayer) {
            return rowPositionCoordinate;
        }
        int rowPosition = rowPositionCoordinate.getRowPosition();
        int underlyingRowPosition = layer.localToUnderlyingRowPosition(rowPosition);
        if (underlyingRowPosition < 0) {
            return null;
        }
        Collection<ILayer> underlyingLayers = layer.getUnderlyingLayersByRowPosition(rowPosition);
        if (underlyingLayers != null) {
            for (ILayer underlyingLayer : underlyingLayers) {
                if (underlyingLayer != null) {
                    RowPositionCoordinate convertedRowPositionCoordinate = convertRowPositionToTargetContext(new RowPositionCoordinate(underlyingLayer, underlyingRowPosition), targetLayer);
                    if (convertedRowPositionCoordinate != null) {
                        return convertedRowPositionCoordinate;
                    }
                }
            }
        }
    }
    return null;
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)

Example 80 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class EditController method editCells.

/**
 * This method is used to edit cells in a sub dialog. In every case this
 * method will open a dialog for editing, regardless if the list of cells to
 * edit contain several or only one value. Only if the given list of cells
 * to edit is <code>null</code> or empty, there is no action performed.
 *
 * @param cells
 *            The list of cells to edit.
 * @param parent
 *            The parent composite to access the parent shell, or
 *            <code>null</code> to create a top-level shell dialog. In the
 *            last case, the dialog will be opened as non modal.
 * @param initialCanonicalValue
 *            The value that should be propagated to the editor control.
 *            Needed because for multi cell editing or editor activation by
 *            letter/digit key will result in a different value to populate
 *            for some editors than populating the value out of the
 *            cell/data model directly.
 * @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 and therefore it is needed for activation of
 *            editors.
 */
public static void editCells(final Collection<ILayerCell> cells, final Composite parent, Object initialCanonicalValue, final IConfigRegistry configRegistry) {
    if (cells != null && !cells.isEmpty()) {
        // get the editor to use, because the editor contains information if
        // it allows editing on a multi edit dialog
        // Note: this works because previous to calling this method it is
        // checked if all cells have the same editor configured. Otherwise
        // this method will have serious issues further on.
        ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, cells.iterator().next().getConfigLabels().getLabels());
        if (cells.size() == 1 || (cells.size() > 1 && supportMultiEdit(cells, cellEditor, configRegistry))) {
            if (cellEditor.openMultiEditDialog()) {
                // as the EditSelectionCommandHandler already ensured that
                // all cells have the same configuration, we can simply use
                // any cell for multi cell edit handling
                ICellEditDialog dialog = CellEditDialogFactory.createCellEditDialog(parent != null ? parent.getShell() : null, initialCanonicalValue, cells.iterator().next(), cellEditor, configRegistry);
                int returnValue = dialog.open();
                if (returnValue == Window.OK) {
                    for (ILayerCell selectedCell : cells) {
                        Object editorValue = dialog.getCommittedValue();
                        if (!(dialog.getEditType() == EditTypeEnum.SET)) {
                            editorValue = dialog.calculateValue(selectedCell.getDataValue(), editorValue);
                        }
                        ILayer layer = selectedCell.getLayer();
                        layer.doCommand(new UpdateDataCommand(layer, selectedCell.getColumnPosition(), selectedCell.getRowPosition(), editorValue));
                    }
                }
            } else {
                // directly changes the value and closes right away.
                for (ILayerCell cell : cells) {
                    ICellEditHandler editHandler = new InlineEditHandler(cell.getLayer(), cell.getColumnPosition(), cell.getRowPosition());
                    cellEditor.activateCell(parent, initialCanonicalValue, EditModeEnum.INLINE, editHandler, cell, configRegistry);
                }
            }
        }
    }
}
Also used : ICellEditDialog(org.eclipse.nebula.widgets.nattable.edit.gui.ICellEditDialog) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)127 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)91 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)90 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)82 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)73 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)71 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)68 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)68 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)67 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)67 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)64 HashMap (java.util.HashMap)62 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)60 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)58 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)58 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)53 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)48 GridLayout (org.eclipse.swt.layout.GridLayout)35 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)34 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)33