Search in sources :

Example 11 with IUniqueIndexLayer

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

the class AbstractColumnHideShowLayer method getStartXOfColumnPosition.

@Override
public int getStartXOfColumnPosition(int localColumnPosition) {
    Integer cachedStartX = this.startXCache.get(localColumnPosition);
    if (cachedStartX != null) {
        return cachedStartX.intValue();
    }
    IUniqueIndexLayer underlyingLayer = (IUniqueIndexLayer) getUnderlyingLayer();
    int underlyingPosition = localToUnderlyingColumnPosition(localColumnPosition);
    if (underlyingPosition < 0) {
        return -1;
    }
    int underlyingStartX = underlyingLayer.getStartXOfColumnPosition(underlyingPosition);
    if (underlyingStartX < 0) {
        return -1;
    }
    for (Integer hiddenIndex : getHiddenColumnIndexes()) {
        int hiddenPosition = underlyingLayer.getColumnPositionByIndex(hiddenIndex);
        if (hiddenPosition <= underlyingPosition) {
            underlyingStartX -= underlyingLayer.getColumnWidthByPosition(hiddenPosition);
        }
    }
    this.startXCache.put(localColumnPosition, underlyingStartX);
    return underlyingStartX;
}
Also used : IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)

Example 12 with IUniqueIndexLayer

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

the class ViewportEventHandler method handleLayerEvent.

@Override
public void handleLayerEvent(IStructuralChangeEvent event) {
    IUniqueIndexLayer scrollableLayer = this.viewportLayer.getScrollableLayer();
    if (event.isHorizontalStructureChanged()) {
        this.viewportLayer.invalidateHorizontalStructure();
        int columnOffset = 0;
        int minimumOriginColumnPosition = this.viewportLayer.getMinimumOriginColumnPosition();
        Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
        if (columnDiffs != null) {
            if (minimumOriginColumnPosition < 0) {
                // this is for handling of hide/show behaviour
                // the value can only be -1 in case the column for which the
                // minimum origin was set before
                // was hidden, so we try to determine the correct value now
                // if it is shown again
                minimumOriginColumnPosition = scrollableLayer.getColumnPositionByX(this.viewportLayer.getMinimumOrigin().getX());
            }
            for (StructuralDiff columnDiff : columnDiffs) {
                switch(columnDiff.getDiffType()) {
                    case ADD:
                        Range afterPositionRange = columnDiff.getAfterPositionRange();
                        if (minimumOriginColumnPosition > 0) {
                            for (int i = afterPositionRange.start; i < afterPositionRange.end; i++) {
                                if (i < minimumOriginColumnPosition) {
                                    minimumOriginColumnPosition++;
                                }
                            }
                        }
                        break;
                    case DELETE:
                        Range beforePositionRange = columnDiff.getBeforePositionRange();
                        if (minimumOriginColumnPosition > 0) {
                            for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
                                if (i < minimumOriginColumnPosition) {
                                    columnOffset -= 1;
                                }
                            }
                        }
                        break;
                }
            }
        }
        int minimumOriginColumn = minimumOriginColumnPosition + columnOffset;
        // of the calculated value
        if (this.viewportLayer.getMinColumnPosition() >= 0) {
            minimumOriginColumn = this.viewportLayer.getMinColumnPosition();
        }
        // if the new origin is out of range (e.g. the last column in the
        // viewport is moved
        // to the frozen region, the minimum origin need to be updated in
        // another way
        int startX = scrollableLayer.getStartXOfColumnPosition(minimumOriginColumn);
        if (startX < 0 && minimumOriginColumnPosition > 0) {
            int columnCount = scrollableLayer.getColumnCount();
            if (columnCount == 0) {
                // special case when all columns are hidden
                startX = 0;
            } else {
                startX = scrollableLayer.getStartXOfColumnPosition(columnCount - 1) + scrollableLayer.getColumnWidthByPosition(columnCount - 1);
            }
        }
        this.viewportLayer.setMinimumOriginX(startX);
    }
    if (event.isVerticalStructureChanged()) {
        this.viewportLayer.invalidateVerticalStructure();
        int rowOffset = 0;
        int minimumOriginRowPosition = this.viewportLayer.getMinimumOriginRowPosition();
        Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
        if (rowDiffs != null) {
            if (minimumOriginRowPosition < 0) {
                // this is for handling of hide/show behaviour
                // the value can only be -1 in case the row for which the
                // minimum origin was set before
                // was hidden, so we try to determine the correct value now
                // if it is shown again
                minimumOriginRowPosition = scrollableLayer.getRowPositionByY(this.viewportLayer.getMinimumOrigin().getY());
            }
            for (StructuralDiff rowDiff : rowDiffs) {
                switch(rowDiff.getDiffType()) {
                    case ADD:
                        Range afterPositionRange = rowDiff.getAfterPositionRange();
                        if (minimumOriginRowPosition > 0) {
                            for (int i = afterPositionRange.start; i < afterPositionRange.end; i++) {
                                if (i < minimumOriginRowPosition) {
                                    minimumOriginRowPosition++;
                                }
                            }
                        }
                        break;
                    case DELETE:
                        Range beforePositionRange = rowDiff.getBeforePositionRange();
                        if (minimumOriginRowPosition > 0) {
                            for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
                                if (i < minimumOriginRowPosition) {
                                    rowOffset -= 1;
                                }
                            }
                        }
                        break;
                }
            }
        }
        int minimumOriginRow = minimumOriginRowPosition + rowOffset;
        // the calculated value
        if (this.viewportLayer.getMinRowPosition() >= 0) {
            minimumOriginRow = this.viewportLayer.getMinRowPosition();
        }
        // if the new origin is out of range (e.g. the last row in the
        // viewport is moved
        // to the frozen region, the minimum origin need to be updated in
        // another way
        int startY = scrollableLayer.getStartYOfRowPosition(minimumOriginRow);
        if (startY < 0 && minimumOriginRowPosition > 0) {
            int rowCount = scrollableLayer.getRowCount();
            if (rowCount == 0) {
                // special case when all rows are hidden
                startY = 0;
            } else {
                startY = scrollableLayer.getStartYOfRowPosition(rowCount - 1) + scrollableLayer.getRowHeightByPosition(rowCount - 1);
            }
        }
        this.viewportLayer.setMinimumOriginY(startY);
    }
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 13 with IUniqueIndexLayer

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

the class Creating_a_summary_row method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    this.myDataProvider = new IDataProvider() {

        @Override
        public int getColumnCount() {
            return 4;
        }

        @Override
        public int getRowCount() {
            return 10;
        }

        @Override
        public Object getDataValue(int columnIndex, int rowIndex) {
            if (columnIndex >= getColumnCount() || rowIndex >= getRowCount()) {
                throw new RuntimeException("Data value requested is out of bounds");
            }
            return (columnIndex % 2 == 0) ? 10 : "Apple";
        }

        @Override
        public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
        }
    };
    IConfigRegistry configRegistry = new ConfigRegistry();
    IUniqueIndexLayer dataLayer = new DataLayer(this.myDataProvider);
    // Plug in the SummaryRowLayer
    IUniqueIndexLayer summaryRowLayer = new SummaryRowLayer(dataLayer, configRegistry, false);
    ViewportLayer viewportLayer = new ViewportLayer(summaryRowLayer);
    NatTable natTable = new NatTable(parent, viewportLayer, false);
    // Configure custom summary formula for a column
    natTable.addConfiguration(new MySummaryRowConfig(this.myDataProvider));
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
    return natTable;
}
Also used : IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) SummaryRowLayer(org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)

Example 14 with IUniqueIndexLayer

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

the class ColumnGroupExpandCollapseLayer method getHiddenColumnIndexes.

@Override
public Collection<Integer> getHiddenColumnIndexes() {
    Collection<Integer> hiddenColumnIndexes = new HashSet<Integer>();
    IUniqueIndexLayer underlyingLayer = (IUniqueIndexLayer) getUnderlyingLayer();
    int underlyingColumnCount = underlyingLayer.getColumnCount();
    for (int i = 0; i < underlyingColumnCount; i++) {
        int columnIndex = underlyingLayer.getColumnIndexByPosition(i);
        for (ColumnGroupModel model : this.models) {
            ColumnGroup columnGroup = model.getColumnGroupByIndex(columnIndex);
            if (columnGroup != null && columnGroup.isCollapsed()) {
                if (!ColumnGroupUtils.isStaticOrFirstVisibleColumn(columnIndex, underlyingLayer, underlyingLayer, model)) {
                    hiddenColumnIndexes.add(Integer.valueOf(columnIndex));
                }
            }
        }
    }
    return hiddenColumnIndexes;
}
Also used : IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup) HashSet(java.util.HashSet)

Example 15 with IUniqueIndexLayer

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

the class ColumnGroupExpandCollapseLayer method isColumnIndexHidden.

// Expand/collapse
@Override
public boolean isColumnIndexHidden(int columnIndex) {
    IUniqueIndexLayer underlyingLayer = (IUniqueIndexLayer) getUnderlyingLayer();
    boolean isHiddeninUnderlyingLayer = ColumnGroupUtils.isColumnIndexHiddenInUnderLyingLayer(columnIndex, this, underlyingLayer);
    if (isHiddeninUnderlyingLayer)
        return true;
    for (ColumnGroupModel model : this.models) {
        ColumnGroup columnGroup = model.getColumnGroupByIndex(columnIndex);
        boolean isCollapsedAndStaticColumn = columnGroup != null && columnGroup.isCollapsed() && !ColumnGroupUtils.isStaticOrFirstVisibleColumn(columnIndex, underlyingLayer, underlyingLayer, model);
        if (isCollapsedAndStaticColumn)
            return true;
    }
    return false;
}
Also used : IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)

Aggregations

IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)17 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)4 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)3 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)3 Shell (org.eclipse.swt.widgets.Shell)3 HashSet (java.util.HashSet)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 ColumnGroup (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)2 RowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand)2 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Properties (java.util.Properties)1 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)1