Search in sources :

Example 66 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerTest method testCollapseExpandSingleItemFirstLevel.

@Test
public void testCollapseExpandSingleItemFirstLevel() {
    assertEquals(11, this.treeLayer.getRowCount());
    assertTrue(this.treeLayer.collapsedNodes.isEmpty());
    assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
    // collapse first node in first level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
    assertEquals(1, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(HideRowPositionsEvent.class));
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) this.layerListener.getReceivedEvent(HideRowPositionsEvent.class);
    Collection<Range> rowPositionRanges = hideEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
    // expand first node in first level again
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(11, this.treeLayer.getRowCount());
    assertTrue(this.treeLayer.collapsedNodes.isEmpty());
    assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
    assertEquals(2, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(ShowRowPositionsEvent.class));
    ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
    rowPositionRanges = showEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent) Test(org.junit.Test)

Example 67 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerTest method testCollapseMultipleExpandSingle.

// collapse second - collapse first - expand first - second still collapsed
@Test
public void testCollapseMultipleExpandSingle() {
    assertEquals(11, this.treeLayer.getRowCount());
    assertTrue(this.treeLayer.collapsedNodes.isEmpty());
    assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
    // collapse first node in second level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 2));
    assertEquals(10, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    HierarchicalTreeNode node = this.treeLayer.collapsedNodes.iterator().next();
    assertEquals(0, node.rowIndex);
    assertEquals(2, node.columnIndex);
    assertNotNull(node.rowObject);
    assertEquals(1, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
    assertEquals(1, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(HideRowPositionsEvent.class));
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) this.layerListener.getReceivedEvent(HideRowPositionsEvent.class);
    Collection<Range> rowPositionRanges = hideEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 2), rowPositionRanges.iterator().next());
    this.layerListener.clearReceivedEvents();
    // collapse first node in first level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(2, this.treeLayer.collapsedNodes.size());
    assertTrue(this.treeLayer.collapsedNodes.contains(new HierarchicalTreeNode(2, 0, null)));
    assertTrue(this.treeLayer.collapsedNodes.contains(new HierarchicalTreeNode(0, 0, null)));
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
    assertEquals(1, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(HideRowPositionsEvent.class));
    hideEvent = (HideRowPositionsEvent) this.layerListener.getReceivedEvent(HideRowPositionsEvent.class);
    rowPositionRanges = hideEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
    // expand first node in first level again
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(10, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    node = this.treeLayer.collapsedNodes.iterator().next();
    assertEquals(0, node.rowIndex);
    assertEquals(2, node.columnIndex);
    assertNotNull(node.rowObject);
    assertEquals(1, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
    assertEquals(2, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(ShowRowPositionsEvent.class));
    ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
    rowPositionRanges = showEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(2, 5), rowPositionRanges.iterator().next());
}
Also used : HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent) Test(org.junit.Test)

Example 68 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerTest method testCollapseAll.

// collapseAll - expand single item with sub items - sub items are all
// collapsed
@Test
public void testCollapseAll() {
    this.treeLayer.doCommand(new TreeCollapseAllCommand());
    assertEquals(3, this.treeLayer.getRowCount());
    assertEquals(6, this.treeLayer.collapsedNodes.size());
    assertEquals(8, this.treeLayer.getHiddenRowIndexes().size());
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) this.layerListener.getReceivedEvent(HideRowPositionsEvent.class);
    Collection<Range> rowPositionRanges = hideEvent.getRowPositionRanges();
    assertEquals(2, rowPositionRanges.size());
    assertTrue(rowPositionRanges.contains(new Range(1, 5)));
    assertTrue(rowPositionRanges.contains(new Range(7, 11)));
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(5, this.treeLayer.getRowCount());
    assertEquals(5, this.treeLayer.collapsedNodes.size());
    assertEquals(6, this.treeLayer.getHiddenRowIndexes().size());
    ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
    rowPositionRanges = showEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(2, 4), rowPositionRanges.iterator().next());
}
Also used : TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent) Test(org.junit.Test)

Example 69 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class ColumnHideShowLayerStructuralChangeEventTest method testHandleMultipleColumnDeleteEvent.

@Test
public void testHandleMultipleColumnDeleteEvent() {
    // test start order: 0 1 2 3 4
    assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnHideShowLayer.getColumnIndexByPosition(1));
    assertEquals(2, this.columnHideShowLayer.getColumnIndexByPosition(2));
    assertEquals(3, this.columnHideShowLayer.getColumnIndexByPosition(3));
    assertEquals(4, this.columnHideShowLayer.getColumnIndexByPosition(4));
    assertEquals("one", this.columnHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.columnHideShowLayer.getDataValueByPosition(1, 0));
    assertEquals("three", this.columnHideShowLayer.getDataValueByPosition(2, 0));
    assertEquals("four", this.columnHideShowLayer.getDataValueByPosition(3, 0));
    assertEquals("five", this.columnHideShowLayer.getDataValueByPosition(4, 0));
    // hide column at position 2: 0 1 3 4
    List<Integer> columnsToHide = new ArrayList<Integer>();
    columnsToHide.add(2);
    this.columnHideShowLayer.hideColumnPositions(columnsToHide);
    assertEquals(4, this.columnHideShowLayer.getColumnCount());
    assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnHideShowLayer.getColumnIndexByPosition(1));
    assertEquals(3, this.columnHideShowLayer.getColumnIndexByPosition(2));
    assertEquals(4, this.columnHideShowLayer.getColumnIndexByPosition(3));
    assertEquals(-1, this.columnHideShowLayer.getColumnIndexByPosition(4));
    assertEquals("one", this.columnHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.columnHideShowLayer.getDataValueByPosition(1, 0));
    assertEquals("four", this.columnHideShowLayer.getDataValueByPosition(2, 0));
    assertEquals("five", this.columnHideShowLayer.getDataValueByPosition(3, 0));
    // delete columns in the middle
    this.contents.get(0).remove(1);
    this.contents.get(0).remove(1);
    this.contents.get(0).remove(1);
    this.underlyingLayer.fireLayerEvent(new ColumnDeleteEvent(this.underlyingLayer, new Range(1, 4)));
    assertEquals(2, this.columnHideShowLayer.getColumnCount());
    assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnHideShowLayer.getColumnIndexByPosition(1));
    assertEquals(-1, this.columnHideShowLayer.getColumnIndexByPosition(2));
    assertEquals("one", this.columnHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("five", this.columnHideShowLayer.getDataValueByPosition(1, 0));
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 70 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range 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);
}
Also used : ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Aggregations

Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)115 Test (org.junit.Test)54 ArrayList (java.util.ArrayList)40 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)23 HashSet (java.util.HashSet)12 Rectangle (org.eclipse.swt.graphics.Rectangle)12 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)9 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)9 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)6 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)6 ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)6 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)5 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 Point (org.eclipse.swt.graphics.Point)5 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4