Search in sources :

Example 81 with ILayer

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

the class ColumnGroupHeaderLayer 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);
    // Column group header cell
    if (this.model.isPartOfAGroup(bodyColumnIndex)) {
        if (rowPosition == 0) {
            return new LayerCell(this, getStartPositionOfGroup(columnPosition), rowPosition, columnPosition, rowPosition, getColumnSpan(columnPosition), 1);
        } else {
            return new LayerCell(this, columnPosition, rowPosition);
        }
    } else {
        // render column header w/ rowspan = 2
        // as in this case we ask the column header layer for the cell
        // position and the column header layer asks his data provider for
        // the row count which should always return 1, we ask for row
        // position 0 instead of using getGroupHeaderRowPosition(), if we
        // would use getGroupHeaderRowPosition() the
        // ColumnGroupGroupHeaderLayer wouldn't work anymore
        ILayerCell cell = this.columnHeaderLayer.getCellByPosition(columnPosition, 0);
        if (cell != null) {
            final int rowSpan;
            if (this.calculateHeight && this.model.size() == 0) {
                rowSpan = 1;
            } else {
                rowSpan = 2;
            }
            cell = new TransformedLayerCell(cell) {

                @Override
                public ILayer getLayer() {
                    return ColumnGroupHeaderLayer.this;
                }

                @Override
                public int getRowSpan() {
                    return rowSpan;
                }
            };
        }
        return cell;
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) TransformedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell) 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) TransformedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell)

Example 82 with ILayer

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

the class ReorderColumnsAndGroupsCommandHandler method doCommand.

/**
 * Check if any column belongs to a group. If yes, add all columns in that
 * group. Assumes that the 'toLocation' is not inside another group
 */
@Override
protected boolean doCommand(ReorderColumnsAndGroupsCommand command) {
    final ILayer underlyingLayer = this.columnGroupReorderLayer.getUnderlyingLayer();
    List<String> groupsProcessed = new ArrayList<String>();
    List<Integer> fromColumnPositions = command.getFromColumnPositions();
    List<Integer> fromColumnPositionsWithGroupColumns = new ArrayList<Integer>();
    for (Integer fromColumnPosition : fromColumnPositions) {
        int fromColumnIndex = underlyingLayer.getColumnIndexByPosition(fromColumnPosition.intValue());
        ColumnGroupModel model = this.columnGroupReorderLayer.getModel();
        if (model.isPartOfAGroup(fromColumnIndex)) {
            String groupName = model.getColumnGroupByIndex(fromColumnIndex).getName();
            if (!groupsProcessed.contains(groupName)) {
                groupsProcessed.add(groupName);
                fromColumnPositionsWithGroupColumns.addAll(this.columnGroupReorderLayer.getColumnGroupPositions(fromColumnIndex));
            }
        } else {
            fromColumnPositionsWithGroupColumns.add(fromColumnPosition);
        }
    }
    return underlyingLayer.doCommand(new MultiColumnReorderCommand(this.columnGroupReorderLayer, fromColumnPositionsWithGroupColumns, command.getToColumnPosition(), command.isReorderToLeftEdge()));
}
Also used : MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ArrayList(java.util.ArrayList) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)

Example 83 with ILayer

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

the class ViewportSelectColumnGroupCommandHandler method doCommand.

@Override
protected boolean doCommand(ViewportSelectColumnGroupCommand command) {
    int start = -1;
    int span = -1;
    // if a column group group is configured, we inspect the row position
    if (this.columnGroupGroupHeaderLayer != null && command.getNatTableRowPosition() == 0) {
        start = this.columnGroupGroupHeaderLayer.getStartPositionOfGroup(command.getColumnPosition());
        span = this.columnGroupGroupHeaderLayer.getColumnSpan(command.getColumnPosition());
    } else {
        start = this.columnGroupHeaderLayer.getStartPositionOfGroup(command.getColumnPosition());
        span = this.columnGroupHeaderLayer.getColumnSpan(command.getColumnPosition());
    }
    // the SelectRegionCommand needs to be executed on the underlying layer
    // this way the row range from 0 to MAX works, which otherwise breaks
    // when selecting a column group on scrolled state
    ILayer underlyingLayer = this.viewportLayer.getUnderlyingLayerByPosition(0, 0);
    ColumnPositionCoordinate underlyingStart = LayerCommandUtil.convertColumnPositionToTargetContext(new ColumnPositionCoordinate(this.viewportLayer, start), underlyingLayer);
    SelectRegionCommand regionCommand = new SelectRegionCommand(underlyingLayer, underlyingStart.getColumnPosition(), 0, span, Integer.MAX_VALUE, command.isWithShiftMask(), command.isWithControlMask());
    // set the anchor row position to the first row in the viewport
    RowPositionCoordinate underlyingRow = LayerCommandUtil.convertRowPositionToTargetContext(new RowPositionCoordinate(this.viewportLayer, 0), underlyingLayer);
    regionCommand.setAnchorRowPosition(underlyingRow.rowPosition);
    underlyingLayer.doCommand(regionCommand);
    return true;
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)

Example 84 with ILayer

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

the class ColumnHeaderLayer method renameColumnIndex.

public boolean renameColumnIndex(int columnIndex, String customColumnName) {
    boolean renamed = this.renameColumnHelper.renameColumnIndex(columnIndex, customColumnName);
    if (renamed) {
        // search for the bottom layer in the horizontal dependency to
        // create the event for index and correct layer
        ILayer baseLayer = getHorizontalLayerDependency();
        while (baseLayer.getUnderlyingLayerByPosition(0, 0) != null) {
            baseLayer = baseLayer.getUnderlyingLayerByPosition(0, 0);
        }
        baseLayer.fireLayerEvent(new RenameColumnHeaderEvent(baseLayer, columnIndex));
    }
    return renamed;
}
Also used : RenameColumnHeaderEvent(org.eclipse.nebula.widgets.nattable.columnRename.event.RenameColumnHeaderEvent) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Example 85 with ILayer

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

the class AbstractColumnHideShowLayer method cacheVisibleColumnIndexes.

private void cacheVisibleColumnIndexes() {
    this.cachedVisibleColumnIndexOrder = new ArrayList<Integer>();
    this.cachedVisibleColumnIndexPositionMap = new HashMap<Integer, Integer>();
    this.cachedHiddenColumnIndexToPositionMap = new HashMap<Integer, Integer>();
    this.startXCache.clear();
    ILayer underlyingLayer = getUnderlyingLayer();
    int columnPosition = 0;
    for (int parentColumnPosition = 0; parentColumnPosition < underlyingLayer.getColumnCount(); parentColumnPosition++) {
        int columnIndex = underlyingLayer.getColumnIndexByPosition(parentColumnPosition);
        if (!isColumnIndexHidden(columnIndex)) {
            this.cachedVisibleColumnIndexOrder.add(columnIndex);
            this.cachedVisibleColumnIndexPositionMap.put(columnIndex, columnPosition);
            columnPosition++;
        } else {
            this.cachedHiddenColumnIndexToPositionMap.put(columnIndex, columnPosition);
        }
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

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