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());
}
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));
}
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));
}
}
}
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));
}
}
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;
}
Aggregations