Search in sources :

Example 31 with ILayerCell

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

the class InlineCellEditEventHandler method handleLayerEvent.

@Override
public void handleLayerEvent(InlineCellEditEvent event) {
    if (event.convertToLocal(this.layer)) {
        ILayerCell cell = this.layer.getCellByPosition(event.getColumnPosition(), event.getRowPosition());
        EditController.editCell(cell, event.getParent(), event.getInitialValue(), event.getConfigRegistry());
    }
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 32 with ILayerCell

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

the class ComboBoxFilterRowConfiguration method configureRegistry.

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, this.cellEditor, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
    configRegistry.registerConfigAttribute(FilterRowConfigAttributes.TEXT_MATCHING_MODE, TextMatchingMode.REGULAR_EXPRESSION);
    ICellPainter cellPainter = new CellPainterDecorator(new TextPainter() {

        {
            this.paintFg = false;
        }

        // override the preferred width and height to be 0, as otherwise
        // the String that is generated in the background for multiple
        // selection will be taken into account for auto resizing
        @Override
        public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
            return 0;
        }

        @Override
        public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
            return 0;
        }
    }, CellEdgeEnum.RIGHT, this.filterIconPainter);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
}
Also used : IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) GC(org.eclipse.swt.graphics.GC) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 33 with ILayerCell

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

the class ColumnGroupGroupHeaderLayer method getCellByPosition.

// Cell features
/**
 * If a cell belongs to a column group: column position - set to the start
 * position of the group span - set to the width/size of the column group
 *
 * NOTE: gc.setClip() is used in the CompositeLayerPainter to ensure that
 * partially visible Column group header cells are rendered properly.
 */
@Override
public ILayerCell getCellByPosition(int columnPosition, int rowPosition) {
    int bodyColumnIndex = getColumnIndexByPosition(columnPosition);
    if (rowPosition == 0) {
        if (this.model.isPartOfAGroup(bodyColumnIndex)) {
            return new LayerCell(this, getStartPositionOfGroup(columnPosition), rowPosition, columnPosition, rowPosition, getColumnSpan(columnPosition), 1);
        } else {
            ILayerCell underlyingCell = this.columnGroupHeaderLayer.getCellByPosition(columnPosition, rowPosition);
            return new LayerCell(this, underlyingCell.getOriginColumnPosition(), underlyingCell.getOriginRowPosition(), columnPosition, rowPosition, underlyingCell.getColumnSpan(), underlyingCell.getRowSpan() + 1);
        }
    } else if (rowPosition == 1) {
        ILayerCell underlyingCell = this.columnGroupHeaderLayer.getCellByPosition(columnPosition, rowPosition - 1);
        boolean partOfAGroup = this.model.isPartOfAGroup(bodyColumnIndex);
        return new LayerCell(this, underlyingCell.getOriginColumnPosition(), underlyingCell.getOriginRowPosition() + (partOfAGroup ? 1 : 0), columnPosition, rowPosition, underlyingCell.getColumnSpan(), underlyingCell.getRowSpan() + (partOfAGroup ? 0 : 1));
    } else if (rowPosition == 2) {
        ILayerCell underlyingCell = this.columnGroupHeaderLayer.getCellByPosition(columnPosition, rowPosition - 1);
        boolean partOfAGroup = this.model.isPartOfAGroup(bodyColumnIndex) || this.columnGroupHeaderLayer.isColumnInGroup(bodyColumnIndex);
        return new LayerCell(this, underlyingCell.getOriginColumnPosition(), underlyingCell.getOriginRowPosition() + (partOfAGroup ? 1 : 0), columnPosition, rowPosition, underlyingCell.getColumnSpan(), underlyingCell.getRowSpan() + (partOfAGroup ? 0 : 1));
    }
    return null;
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) LayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.LayerCell) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 34 with ILayerCell

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

the class FreezeSelectionStrategy method getTopLeftPosition.

@Override
public PositionCoordinate getTopLeftPosition() {
    PositionCoordinate lastSelectedCellPosition = this.selectionLayer.getLastSelectedCellPosition();
    if (lastSelectedCellPosition == null) {
        return null;
    }
    ILayerCell lastSelectedCell = this.selectionLayer.getCellByPosition(lastSelectedCellPosition.columnPosition, lastSelectedCellPosition.rowPosition);
    int columnPosition = this.viewportLayer.getScrollableLayer().getColumnPositionByX(this.viewportLayer.getOrigin().getX());
    if (columnPosition > 0 && columnPosition >= lastSelectedCellPosition.columnPosition) {
        if (!this.include) {
            columnPosition = lastSelectedCellPosition.columnPosition - 1;
        } else {
            columnPosition = lastSelectedCellPosition.columnPosition + lastSelectedCell.getColumnSpan() - 1;
        }
    }
    int rowPosition = this.viewportLayer.getScrollableLayer().getRowPositionByY(this.viewportLayer.getOrigin().getY());
    if (rowPosition > 0 && rowPosition >= lastSelectedCellPosition.rowPosition) {
        if (!this.include) {
            rowPosition = lastSelectedCellPosition.rowPosition - 1;
        } else {
            rowPosition = lastSelectedCellPosition.rowPosition - lastSelectedCell.getRowSpan() - 1;
        }
    }
    return new PositionCoordinate(this.freezeLayer, columnPosition, rowPosition);
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 35 with ILayerCell

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

the class HierarchicalTreeAlternatingRowConfigLabelAccumulator method calculateLabel.

/**
 * Calculate the even/odd label based on the above row label, taking the
 * spanning into account.
 *
 * @param rowPosition
 *            The row position for which the label should be determined.
 * @return The even/odd row label to be applied for the given row.
 */
protected String calculateLabel(int rowPosition) {
    // get cell in first column to determine the origin row position of the
    // spanned cell
    ILayerCell firstColumn = this.layer.getCellByPosition(0, rowPosition);
    // check if there is a label for the origin row already
    String label = this.rowLabelCache.get(firstColumn.getOriginRowPosition());
    if (label == null) {
        if (firstColumn.getOriginRowPosition() == 0) {
            label = EVEN_ROW_CONFIG_TYPE;
        } else {
            // check for the label one row above
            // remember: spanned cells are rendered at the end
            String labelAbove = this.rowLabelCache.get(firstColumn.getOriginRowPosition() - 1);
            if (labelAbove == null) {
                labelAbove = calculateLabel(firstColumn.getOriginRowPosition() - 1);
            }
            label = (labelAbove == EVEN_ROW_CONFIG_TYPE) ? ODD_ROW_CONFIG_TYPE : EVEN_ROW_CONFIG_TYPE;
        }
    }
    return label;
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)118 Test (org.junit.Test)45 Rectangle (org.eclipse.swt.graphics.Rectangle)23 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)14 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)14 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)11 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)10 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)10 Color (org.eclipse.swt.graphics.Color)10 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)9 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)9 DataProviderFixture (org.eclipse.nebula.widgets.nattable.test.fixture.data.DataProviderFixture)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)5 Point (org.eclipse.swt.graphics.Point)5 HashSet (java.util.HashSet)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)4 IEditableRule (org.eclipse.nebula.widgets.nattable.config.IEditableRule)4 ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)4