Search in sources :

Example 21 with ILayerEvent

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

the class RowReorderLayerVisibleChangeTest method returnsCorrectPositionRectangleForMultiColumnReorderRightCase.

@SuppressWarnings("boxing")
@Test
public /**
 * 	Index		2	3	0	1 ... 20
 *          --------------------
 *  Position 	0 	1	2	3 ... 20
 */
void returnsCorrectPositionRectangleForMultiColumnReorderRightCase() {
    RowReorderLayer reorderLayer = new RowReorderLayer(new BaseDataLayerFixture(20, 20));
    // Build expected cell positions to redraw
    final Set<Rectangle> expectedPositions = new HashSet<Rectangle>();
    expectedPositions.add(new Rectangle(0, 0, 20, 20));
    reorderLayer.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            RowReorderEvent multiReorder = (RowReorderEvent) event;
            assertTrue(multiReorder.getChangedPositionRectangles().containsAll(expectedPositions));
        }
    });
    // Reorder from beginning of grid
    List<Integer> fromRowPositions = Arrays.asList(new Integer[] { 0, 1 });
    reorderLayer.reorderMultipleRowPositions(fromRowPositions, 2);
    // Reorder to middle of grid
    expectedPositions.clear();
    expectedPositions.add(new Rectangle(0, 5, 20, 15));
    fromRowPositions = Arrays.asList(new Integer[] { 5, 6, 7, 8 });
    reorderLayer.reorderMultipleRowPositions(fromRowPositions, 10);
    // Reorder to end of grid
    expectedPositions.clear();
    expectedPositions.add(new Rectangle(0, 10, 20, 10));
    fromRowPositions = Arrays.asList(new Integer[] { 10, 11, 12, 13 });
    reorderLayer.reorderMultipleRowPositions(fromRowPositions, 19);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) BaseDataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) RowReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.RowReorderEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with ILayerEvent

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

the class ViewportLayerTest method settingViewportColumnOriginFiresEvent.

@Test
public void settingViewportColumnOriginFiresEvent() throws Exception {
    this.viewportLayer.addLayerListener(this.layerListener);
    this.viewportLayer.setOriginX(this.viewportLayer.getStartXOfColumnPosition(2));
    ILayerEvent event = this.layerListener.getReceivedEvents().get(0);
    assertTrue(event instanceof IVisualChangeEvent);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) IVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent) Test(org.junit.Test)

Example 23 with ILayerEvent

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

the class ViewportLayerTest method testMoveColumnPositionIntoViewportFiresEvent.

/*
     * Scrolling Events fired when origin changes
     */
@Test
public void testMoveColumnPositionIntoViewportFiresEvent() throws Exception {
    this.viewportLayer.addLayerListener(this.layerListener);
    this.viewportLayer.moveColumnPositionIntoViewport(4);
    ILayerEvent event = this.layerListener.getReceivedEvents().get(0);
    assertTrue(event instanceof IVisualChangeEvent);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) IVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent) Test(org.junit.Test)

Example 24 with ILayerEvent

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

the class RowGroupExpandCollapseCommandHandler method doCommand.

@Override
protected boolean doCommand(RowGroupExpandCollapseCommand command) {
    int rowIndex = this.rowGroupExpandCollapseLayer.getRowIndexByPosition(command.getRowPosition());
    IRowGroupModel<T> model = this.rowGroupExpandCollapseLayer.getModel();
    IRowGroup<T> group = RowGroupUtils.getTopMostParentGroup(RowGroupUtils.getRowGroupForRowIndex(model, rowIndex));
    // further operation ...
    if (group == null || !group.isCollapseable()) {
        return true;
    }
    boolean wasCollapsed = group.isCollapsed();
    if (wasCollapsed) {
        group.expand();
    } else {
        group.collapse();
    }
    List<Integer> rowIndexes = new ArrayList<Integer>(RowGroupUtils.getRowIndexesInGroup(model, rowIndex));
    List<Integer> rowPositions = RowGroupUtils.getRowPositionsInGroup(this.rowGroupExpandCollapseLayer, rowIndexes);
    ILayerEvent event;
    if (wasCollapsed) {
        event = new ShowRowPositionsEvent(this.rowGroupExpandCollapseLayer, rowPositions);
    } else {
        event = new HideRowPositionsEvent(this.rowGroupExpandCollapseLayer, rowPositions);
    }
    this.rowGroupExpandCollapseLayer.fireLayerEvent(event);
    return true;
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) ArrayList(java.util.ArrayList) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)

Example 25 with ILayerEvent

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

the class ColumnGroupExpandCollapseCommandHandler method doCommand.

@Override
protected boolean doCommand(ColumnGroupExpandCollapseCommand command) {
    int columnIndex = this.columnGroupExpandCollapseLayer.getColumnIndexByPosition(command.getColumnPosition());
    ColumnGroupModel model = this.columnGroupExpandCollapseLayer.getModel(command.getRowPosition());
    ColumnGroup columnGroup = model.getColumnGroupByIndex(columnIndex);
    // further operation ...
    if (columnGroup == null || !columnGroup.isCollapseable()) {
        return true;
    }
    List<Integer> columnIndexes = new ArrayList<Integer>(columnGroup.getMembers());
    columnIndexes.removeAll(columnGroup.getStaticColumnIndexes());
    boolean wasCollapsed = columnGroup.isCollapsed();
    if (wasCollapsed) {
        // we need to cleanup the column position list before we toggle
        // because the columns are hidden before the toggle and will be
        // visible afterwards
        cleanupColumnIndexes(columnIndexes);
    }
    columnGroup.toggleCollapsed();
    if (!wasCollapsed) {
        // we need to cleanup the column position list after we toggle
        // because the columns are hidden now
        cleanupColumnIndexes(columnIndexes);
    }
    ILayerEvent event;
    if (wasCollapsed) {
        event = new ShowColumnPositionsEvent(this.columnGroupExpandCollapseLayer, columnIndexes);
    } else {
        event = new HideColumnPositionsEvent(this.columnGroupExpandCollapseLayer, columnIndexes);
    }
    this.columnGroupExpandCollapseLayer.fireLayerEvent(event);
    return true;
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) ArrayList(java.util.ArrayList) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) ShowColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowColumnPositionsEvent)

Aggregations

ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)28 Test (org.junit.Test)17 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)14 HashSet (java.util.HashSet)4 IVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4 CellSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent)4 BaseDataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 BigDecimal (java.math.BigDecimal)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)3 CellVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent)3 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)3 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)2 ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)2