Search in sources :

Example 6 with ColumnResizeEvent

use of org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent in project nebula.widgets.nattable by eclipse.

the class ResizingVisibleReorderedColumnsTest method changeShouldIncludeAllColumns.

@Test
public void changeShouldIncludeAllColumns() {
    // Reorder columns again, should now be 3, 0, 1, 2, 4
    this.reorderLayer.reorderColumnPosition(3, 0);
    // Resize first column
    this.dataLayer.setColumnWidthByPosition(3, 200);
    // The changed position rectangle should now be the entire grid
    Rectangle expectedRectangle = new Rectangle(0, 0, 5, 7);
    Collection<Rectangle> actualRectangles = ((ColumnResizeEvent) this.layerListener.getReceivedEvent(ColumnResizeEvent.class)).getChangedPositionRectangles();
    Assert.assertEquals(expectedRectangle, actualRectangles);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) Test(org.junit.Test)

Example 7 with ColumnResizeEvent

use of org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent in project nebula.widgets.nattable by eclipse.

the class DataLayer method setColumnWidthPercentageByPosition.

public void setColumnWidthPercentageByPosition(int columnPosition, int width) {
    this.columnWidthConfig.setPercentage(columnPosition, width);
    fireLayerEvent(new ColumnResizeEvent(this, columnPosition));
}
Also used : ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)

Example 8 with ColumnResizeEvent

use of org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayer method showAllColumns.

@Override
public void showAllColumns() {
    // On show we expect that all visible columns share the free
    // space. To avoid that only the adjacent column is decreased, we
    // disable fixColumnPercentageValuesOnResize in any case and restore it
    // afterwards
    boolean fix = this.bodyDataLayer.isFixColumnPercentageValuesOnResize();
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(false);
    for (Map.Entry<Integer, ColumnSizeInfo> entry : this.hiddenColumns.entrySet()) {
        Integer index = entry.getKey();
        ColumnSizeInfo info = entry.getValue();
        // first make the column resizable
        this.bodyDataLayer.setColumnPositionResizable(index, true);
        // set the previous configured min width
        if (info.configuredMinWidth < 0) {
            this.bodyDataLayer.resetMinColumnWidth(index, false);
        } else {
            this.bodyDataLayer.setMinColumnWidth(index, info.configuredMinWidth);
        }
        // set the previous configured width
        if (info.configuredPercentage && info.configuredPercentageValue >= 0) {
            this.bodyDataLayer.setColumnWidthPercentageByPosition(index, info.configuredPercentageValue);
        } else if (!info.configuredPercentage && info.configuredSize >= 0) {
            this.bodyDataLayer.setColumnWidthByPosition(index, info.configuredSize, false);
        } else {
            this.bodyDataLayer.resetColumnWidth(index, false);
        }
        // set the configured resizable value
        this.bodyDataLayer.setColumnPositionResizable(index, info.configuredResizable);
    }
    List<Range> ranges = PositionUtil.getRanges(this.hiddenColumns.keySet());
    this.hiddenColumns.clear();
    // reset the fixColumnPercentageValuesOnResize flag
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(fix);
    // fire events
    for (Range range : ranges) {
        this.bodyDataLayer.fireLayerEvent(new ColumnResizeEvent(this.bodyDataLayer, range));
    }
}
Also used : ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 9 with ColumnResizeEvent

use of org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent in project nebula.widgets.nattable by eclipse.

the class ResizeEventPropagationTest method shouldReturnARectangleStartingFromResizedColumnToEndOfGrid.

@Test
public void shouldReturnARectangleStartingFromResizedColumnToEndOfGrid() {
    // Mimics resizing the second column
    this.layerListener = new LayerListenerFixture();
    this.dataLayer.addLayerListener(this.layerListener);
    this.dataLayer.setColumnWidthByPosition(2, 200);
    // This is the propagated event
    ColumnResizeEvent columnResizeEvent = (ColumnResizeEvent) this.layerListener.getReceivedEvents().get(0);
    Collection<Rectangle> actualRectangles = columnResizeEvent.getChangedPositionRectangles();
    // The affected region should have the following size
    Rectangle expectedRectangle = new Rectangle(2, 0, 3, 7);
    Assert.assertEquals(expectedRectangle, actualRectangles.iterator().next());
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Test(org.junit.Test)

Example 10 with ColumnResizeEvent

use of org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent in project nebula.widgets.nattable by eclipse.

the class ResizingVisibleReorderedColumnsTest method changeShouldIncludeLastColumn.

@Test
public void changeShouldIncludeLastColumn() {
    // Reorder columns should now be 0, 2, 3, 4, 1
    this.reorderLayer.reorderColumnPosition(1, 4);
    // Resize last column
    this.dataLayer.setColumnWidthByPosition(1, 200);
    // The changed position rectangle should just have one column, and the
    // column position should be the last column (4)
    Rectangle expectedRectangle = new Rectangle(4, 0, 1, 7);
    Collection<Rectangle> actualRectangles = ((ColumnResizeEvent) this.layerListener.getReceivedEvent(ColumnResizeEvent.class)).getChangedPositionRectangles();
    Assert.assertEquals(expectedRectangle, actualRectangles.iterator().next());
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) Test(org.junit.Test)

Aggregations

ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)15 Test (org.junit.Test)8 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)6 Rectangle (org.eclipse.swt.graphics.Rectangle)5 TreeMap (java.util.TreeMap)2 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)1 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)1 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)1 Before (org.junit.Before)1