use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.
the class ColumnHideShowLayerTest2 method shouldFireTheCorrectEventOnColumnHide.
@Test
public void shouldFireTheCorrectEventOnColumnHide() throws Exception {
NatTable natTable = new NatTableFixture();
LayerListenerFixture listener = new LayerListenerFixture();
natTable.addLayerListener(listener);
// Grid coordinates
natTable.doCommand(new ColumnHideCommand(natTable, 5));
assertEquals(1, listener.getReceivedEvents().size());
HideColumnPositionsEvent hideEvent = (HideColumnPositionsEvent) listener.getReceivedEvents().get(0);
Range range = hideEvent.getColumnPositionRanges().iterator().next();
assertEquals(5, range.start);
assertEquals(6, range.end);
// The range Before hide: 5 -> 6
// The range After hide: 5 -> 5 (column is not there anymore)
StructuralDiff columnDiff = hideEvent.getColumnDiffs().iterator().next();
assertEquals(5, columnDiff.getBeforePositionRange().start);
assertEquals(6, columnDiff.getBeforePositionRange().end);
assertEquals(5, columnDiff.getAfterPositionRange().start);
assertEquals(5, columnDiff.getAfterPositionRange().end);
}
use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.
the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionIfSelectedColumnIsHidden.
@Test
public void shouldClearSelectionIfSelectedColumnIsHidden() {
this.selectionModel.addSelection(3, 4);
List<Integer> columns = new ArrayList<Integer>();
columns.add(3);
this.selectionModel.handleLayerEvent(new HideColumnPositionsEvent(this.dataLayer, columns));
Assert.assertTrue(this.selectionModel.isEmpty());
}
use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.
the class SelectionModelStructuralChangeEventHandlerTest method shouldNotClearSelectionIfOtherColumnIsHidden.
@Test
public void shouldNotClearSelectionIfOtherColumnIsHidden() {
this.selectionModel.addSelection(3, 4);
List<Integer> columns = new ArrayList<Integer>();
columns.add(2);
this.selectionModel.handleLayerEvent(new HideColumnPositionsEvent(this.dataLayer, columns));
Assert.assertTrue(this.selectionModel.isEmpty());
}
use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.
the class ColumnHideShowLayerTest2 method scrollAndHideTheLastColumn.
/**
* Integration test
*/
@Test
public void scrollAndHideTheLastColumn() throws Exception {
// Total columns in fixture - 20 (index 0 - 19)
NatTableFixture natTable = new NatTableFixture();
LayerListenerFixture natTableListener = new LayerListenerFixture();
natTable.addLayerListener(natTableListener);
// Scroll to position 14 in grid/14 in body
natTable.scrollToColumn(14);
assertEquals(14, natTable.getColumnIndexByPosition(1));
// Hide last column - position 6/index 19
assertEquals(19, natTable.getColumnIndexByPosition(6));
natTable.doCommand(new ColumnHideCommand(natTable, 6));
// Assert event received
assertNotNull(natTableListener.getReceivedEvent(HideColumnPositionsEvent.class));
HideColumnPositionsEvent hideEvent = (HideColumnPositionsEvent) natTableListener.getReceivedEvent(HideColumnPositionsEvent.class);
// When last column is hidden it is not carrying the following info
assertEquals(1, hideEvent.getColumnPositionRanges().size());
// View port adjusted origin to move an extra column in
Range hiddenRange = hideEvent.getColumnPositionRanges().iterator().next();
assertEquals(7, hiddenRange.start);
assertEquals(8, hiddenRange.end);
}
use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent 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;
}
Aggregations