Search in sources :

Example 11 with ColumnResizeEvent

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

the class ResizingVisibleReorderedColumnsTest method changeShouldIncludeHalfOfGrid.

@Test
public void changeShouldIncludeHalfOfGrid() {
    // Reorder columns should now be 0, 1, 3, 2, 4
    this.reorderLayer.reorderColumnPosition(3, 2);
    // Resize last column
    this.dataLayer.setColumnWidthByPosition(3, 200);
    // The changed position rectangle should just have one column, and the
    // column position should be the last column (4)
    Rectangle expectedRectangle = new Rectangle(2, 0, 3, 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)

Example 12 with ColumnResizeEvent

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

the class DataLayer method setColumnWidthPercentageByPosition.

/**
 * Set the width of the column at the given position to the given percentage
 * value.
 *
 * @param columnPosition
 *            The position of the column to change.
 * @param width
 *            The percentage value to set.
 *
 * @since 1.6
 */
public void setColumnWidthPercentageByPosition(int columnPosition, double width) {
    this.columnWidthConfig.setPercentage(columnPosition, width);
    fireLayerEvent(new ColumnResizeEvent(this, columnPosition));
}
Also used : ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)

Example 13 with ColumnResizeEvent

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

the class ResizeColumnHideShowLayer method showColumnIndexes.

@Override
public void showColumnIndexes(Collection<Integer> columnIndexes) {
    // 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);
    List<Integer> processed = new ArrayList<Integer>();
    for (Integer index : columnIndexes) {
        ColumnSizeInfo info = this.hiddenColumns.remove(index);
        if (info != null) {
            processed.add(index);
            // first make the column resizable
            this.bodyDataLayer.setColumnPositionResizable(index, true);
            // 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);
            // set the previous configured min width
            if (info.configuredMinWidth < 0) {
                this.bodyDataLayer.resetMinColumnWidth(index, false);
            } else {
                this.bodyDataLayer.setMinColumnWidth(index, info.configuredMinWidth);
            }
        }
    }
    // reset the fixColumnPercentageValuesOnResize flag
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(fix);
    if (!processed.isEmpty()) {
        List<Range> ranges = PositionUtil.getRanges(processed);
        // fire events
        for (Range range : ranges) {
            this.bodyDataLayer.fireLayerEvent(new ColumnResizeEvent(this.bodyDataLayer, range));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 14 with ColumnResizeEvent

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

the class ResizeColumnHideShowLayer method hideColumnPositions.

@Override
public void hideColumnPositions(Collection<Integer> columnPositions) {
    Map<Integer, ColumnSizeInfo> positionsToHide = new TreeMap<Integer, ColumnSizeInfo>();
    // On hide we expect that all remaining visible columns share the free
    // space. To avoid that only the adjacent column is increased, we
    // disable fixColumnPercentageValuesOnResize in any case and restore it
    // afterwards
    boolean fix = this.bodyDataLayer.isFixColumnPercentageValuesOnResize();
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(false);
    for (Integer columnPosition : columnPositions) {
        // transform the position to index
        int columnIndex = getColumnIndexByPosition(columnPosition);
        // get the currently applied width of the column
        int configuredWidth = this.bodyDataLayer.getConfiguredColumnWidthByPosition(columnIndex);
        // get the currently applied min width of the column
        int configuredMinWidth = this.bodyDataLayer.getConfiguredMinColumnWidthByPosition(columnIndex);
        // get the currently applied resizable info
        boolean configuredResizable = this.bodyDataLayer.isColumnPositionResizable(columnIndex);
        // get the information if the column is configured for percentage
        // sizing
        boolean configuredPercentage = this.bodyDataLayer.isColumnPercentageSizing(columnIndex);
        // get the currently applied percentage width of the column
        double configuredPercentageValue = this.bodyDataLayer.getConfiguredColumnWidthPercentageByPosition(columnIndex);
        positionsToHide.put(columnIndex, new ColumnSizeInfo(configuredWidth, configuredMinWidth, configuredResizable, configuredPercentage, configuredPercentageValue));
    }
    for (Integer columnIndex : positionsToHide.keySet()) {
        // moment to make hiding work
        if (!this.bodyDataLayer.isColumnPositionResizable(columnIndex)) {
            this.bodyDataLayer.setColumnPositionResizable(columnIndex, true);
        }
        // if a min width is configured, set it to 0 to make hiding work
        if (this.bodyDataLayer.isMinColumnWidthConfigured()) {
            this.bodyDataLayer.setMinColumnWidth(columnIndex, 0);
        }
        // set the column width to 0
        if (positionsToHide.get(columnIndex).configuredPercentage) {
            this.bodyDataLayer.setColumnWidthPercentageByPosition(columnIndex, 0d);
        } else {
            this.bodyDataLayer.setColumnWidthByPosition(columnIndex, 0, false);
        }
        // make that column not resizable
        this.bodyDataLayer.setColumnPositionResizable(columnIndex, false);
    }
    this.hiddenColumns.putAll(positionsToHide);
    // reset the fixColumnPercentageValuesOnResize flag
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(fix);
    // fire events
    List<Range> ranges = PositionUtil.getRanges(positionsToHide.keySet());
    for (Range range : ranges) {
        this.bodyDataLayer.fireLayerEvent(new ColumnResizeEvent(this.bodyDataLayer, range));
    }
}
Also used : ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) TreeMap(java.util.TreeMap) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 15 with ColumnResizeEvent

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

the class MultiColumnResizeCommandHandler method doCommand.

@Override
protected boolean doCommand(MultiColumnResizeCommand command) {
    Collection<Integer> columnPositions = command.getColumnPositions();
    for (int columnPosition : columnPositions) {
        int newColumnWidth = command.downScaleValue() ? this.dataLayer.downScaleColumnWidth(command.getColumnWidth(columnPosition)) : command.getColumnWidth(columnPosition);
        this.dataLayer.setColumnWidthByPosition(columnPosition, newColumnWidth, false);
    }
    List<Range> ranges = PositionUtil.getRanges(columnPositions);
    for (Range range : ranges) {
        this.dataLayer.fireLayerEvent(new ColumnResizeEvent(this.dataLayer, range));
    }
    return true;
}
Also used : ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

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