Search in sources :

Example 21 with ColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class RenameColumnIntegrationTest method shouldRenameColumnHeaderForReorderedColumnProgrammatically.

@Test
public void shouldRenameColumnHeaderForReorderedColumnProgrammatically() {
    String originalColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
    assertEquals("Column 2", originalColumnHeader);
    this.natTableFixture.doCommand(new ColumnReorderCommand(this.natTableFixture, 1, 5));
    originalColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
    assertEquals("Column 3", originalColumnHeader);
    this.grid.getColumnHeaderLayer().renameColumnIndex(2, TEST_COLUMN_NAME);
    String renamedColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
    assertEquals(TEST_COLUMN_NAME, renamedColumnHeader);
    assertEquals(2, this.listener.getEventsCount());
    RenameColumnHeaderEvent event = (RenameColumnHeaderEvent) this.listener.getReceivedEvent(RenameColumnHeaderEvent.class);
    assertEquals(new Range(2, 3), event.getColumnPositionRanges().iterator().next());
}
Also used : RenameColumnHeaderEvent(org.eclipse.nebula.widgets.nattable.columnRename.event.RenameColumnHeaderEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 22 with ColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class ColumnStructuralChangeEventIntegrationTest method shouldUpdateReorderOnInsert.

@Test
public void shouldUpdateReorderOnInsert() {
    DefaultBodyLayerStack body = this.grid.getBodyLayer();
    ColumnReorderLayer reorderLayer = body.getColumnReorderLayer();
    body.doCommand(new ColumnReorderCommand(body, 3, 6));
    body.doCommand(new ColumnReorderCommand(body, 3, 5));
    assertEquals("[0, 1, 2, 5, 4, 3]", reorderLayer.getColumnIndexOrder().toString());
    this.provider.setColumnCount(7);
    this.grid.getBodyDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), 3));
    assertEquals("[0, 1, 2, 3, 6, 5, 4]", reorderLayer.getColumnIndexOrder().toString());
}
Also used : ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 23 with ColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class ColumnStructuralChangeEventIntegrationTest method shouldUpdateOnInsertAndDelete.

@Test
public void shouldUpdateOnInsertAndDelete() {
    DefaultBodyLayerStack body = this.grid.getBodyLayer();
    ColumnReorderLayer reorderLayer = body.getColumnReorderLayer();
    ColumnHideShowLayer hideShowLayer = body.getColumnHideShowLayer();
    body.doCommand(new ColumnReorderCommand(body, 3, 6));
    body.doCommand(new ColumnReorderCommand(body, 3, 5));
    body.doCommand(new MultiColumnHideCommand(body, new int[] { 2, 3, 5 }));
    assertEquals("[0, 1, 2, 5, 4, 3]", reorderLayer.getColumnIndexOrder().toString());
    assertEquals("[2, 3, 5]", hideShowLayer.getHiddenColumnIndexes().toString());
    this.provider.setColumnCount(7);
    this.grid.getBodyDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), 3));
    assertEquals("[0, 1, 2, 3, 6, 5, 4]", reorderLayer.getColumnIndexOrder().toString());
    assertEquals("[2, 4, 6]", hideShowLayer.getHiddenColumnIndexes().toString());
    this.provider.setColumnCount(6);
    this.grid.getBodyDataLayer().fireLayerEvent(new ColumnDeleteEvent(this.grid.getBodyDataLayer(), 3));
    assertEquals("[0, 1, 2, 5, 4, 3]", reorderLayer.getColumnIndexOrder().toString());
    assertEquals("[2, 3, 5]", hideShowLayer.getHiddenColumnIndexes().toString());
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) Test(org.junit.Test)

Example 24 with ColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class ColumnStructuralChangeEventIntegrationTest method shouldUpdateOnInsert.

@Test
public void shouldUpdateOnInsert() {
    DefaultBodyLayerStack body = this.grid.getBodyLayer();
    ColumnReorderLayer reorderLayer = body.getColumnReorderLayer();
    ColumnHideShowLayer hideShowLayer = body.getColumnHideShowLayer();
    body.doCommand(new ColumnReorderCommand(body, 3, 6));
    body.doCommand(new ColumnReorderCommand(body, 3, 5));
    body.doCommand(new MultiColumnHideCommand(body, new int[] { 2, 3, 5 }));
    assertEquals("[0, 1, 2, 5, 4, 3]", reorderLayer.getColumnIndexOrder().toString());
    assertEquals("[2, 3, 5]", hideShowLayer.getHiddenColumnIndexes().toString());
    this.provider.setColumnCount(7);
    this.grid.getBodyDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), 3));
    assertEquals("[0, 1, 2, 3, 6, 5, 4]", reorderLayer.getColumnIndexOrder().toString());
    assertEquals("[2, 4, 6]", hideShowLayer.getHiddenColumnIndexes().toString());
}
Also used : ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) Test(org.junit.Test)

Example 25 with ColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class ChooseColumnsFromCategoriesCommandHandler method itemsMoved.

/**
 * Moves the columns up or down by firing commands on the dialog.
 *
 * Individual columns are moved using the {@link ColumnReorderCommand}
 * Contiguously selected columns are moved using the
 * {@link MultiColumnReorderCommand}
 *
 * @param direction
 *            the direction to move
 * @param selectedPositions
 *            the column positions to move
 */
@Override
public void itemsMoved(MoveDirectionEnum direction, List<Integer> selectedPositions) {
    List<List<Integer>> fromPositions = PositionUtil.getGroupedByContiguous(selectedPositions);
    List<Integer> toPositions = getDestinationPositions(direction, fromPositions);
    for (int i = 0; i < fromPositions.size(); i++) {
        boolean multipleColumnsMoved = fromPositions.get(i).size() > 1;
        ILayerCommand command = null;
        if (!multipleColumnsMoved) {
            int fromPosition = fromPositions.get(i).get(0).intValue();
            int toPosition = toPositions.get(i);
            command = new ColumnReorderCommand(this.columnHideShowLayer, fromPosition, toPosition);
        } else if (multipleColumnsMoved) {
            command = new MultiColumnReorderCommand(this.columnHideShowLayer, fromPositions.get(i), toPositions.get(i));
        }
        this.columnHideShowLayer.doCommand(command);
    }
    refreshDialog();
}
Also used : MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ArrayList(java.util.ArrayList) List(java.util.List) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ILayerCommand(org.eclipse.nebula.widgets.nattable.command.ILayerCommand)

Aggregations

ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)42 Test (org.junit.Test)39 MultiColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand)22 ColumnInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent)4 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)4 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)4 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)3 RenameColumnHeaderEvent (org.eclipse.nebula.widgets.nattable.columnRename.event.RenameColumnHeaderEvent)2 ILayerCommand (org.eclipse.nebula.widgets.nattable.command.ILayerCommand)2 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 ClientAreaResizeCommand (org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand)2 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)2 ColumnDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent)2 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)1