Search in sources :

Example 1 with RowStructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class DataChangeLayerIdIndexTest method shouldUpdateChangeOnSortAndSaveWithTemp.

@Test
public void shouldUpdateChangeOnSortAndSaveWithTemp() {
    // enable temp data storage to test update on save
    this.dataChangeLayer = new DataChangeLayer(this.dataLayer, new IdIndexKeyHandler<>(this.dataProvider, new IRowIdAccessor<Person>() {

        @Override
        public Serializable getRowId(Person rowObject) {
            return rowObject.getId();
        }
    }), true);
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 2, "Zoolander"));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    assertEquals("Zoolander", this.dataChangeLayer.getDataValueByPosition(1, 2));
    // sort via firstname
    // NOTE: this is because we are storing the data temporary and therefore
    // sorting for lastname would not respect the shown data.
    this.dataLayer.setDataValueByPosition(0, 2, "Yosefine");
    Collections.sort(this.dataModel, new Comparator<Person>() {

        @Override
        public int compare(Person o1, Person o2) {
            return o1.getFirstName().compareTo(o2.getFirstName());
        }
    });
    // fire event to trigger update of cached row indexes
    this.dataLayer.fireLayerEvent(new RowStructuralRefreshEvent(this.dataLayer));
    // now the dirty state should be on the last row
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 17));
    assertEquals("Zoolander", this.dataChangeLayer.getDataValueByPosition(1, 17));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 17).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 2 is dirty", this.dataChangeLayer.isRowDirty(2));
    assertTrue("Row 17 is not dirty", this.dataChangeLayer.isRowDirty(17));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 17));
    assertFalse("changed columns are empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertFalse("changed rows are empty", this.dataChangeLayer.changedRows.isEmpty());
    assertFalse("changes are empty", this.dataChangeLayer.dataChanges.isEmpty());
    // check if discard is applied correctly
    this.dataChangeLayer.doCommand(new SaveDataChangesCommand());
    assertEquals("Zoolander", this.dataLayer.getDataValue(1, 17));
    assertEquals("Zoolander", this.dataChangeLayer.getDataValueByPosition(1, 17));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 17).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 2 is dirty", this.dataChangeLayer.isRowDirty(2));
    assertFalse("Row 17 is dirty", this.dataChangeLayer.isRowDirty(17));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 17));
    assertTrue("changed columns are not empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertTrue("changed rows are not empty", this.dataChangeLayer.changedRows.isEmpty());
    assertTrue("changes are not empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : Serializable(java.io.Serializable) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Test(org.junit.Test)

Example 2 with RowStructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithRowStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithRowStructuralRefresh() throws Exception {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
    NatTable nattable = new NatTableFixture(gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    // test SelectionModel updates
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
    nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
    assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
    Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
    assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
    // clear the table
    listFixture.clear();
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new RowStructuralRefreshEvent(bodyDataLayer));
    // row count of 1 for NatTable because of header
    assertEquals(1, nattable.getRowCount());
    assertTrue("selection is not empty", selectionLayer.getSelectedCells().isEmpty());
    assertTrue("selection model is not empty", selectionLayer.getSelectionModel().getSelections().isEmpty());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 3 with RowStructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithRowStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithRowStructuralRefresh() throws Exception {
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    // Ford motor at top and selected
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    // clear the table
    this.listFixture.clear();
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new RowStructuralRefreshEvent(this.bodyDataLayer));
    // row count of 1 for NatTable because of header
    assertEquals(1, this.nattable.getRowCount());
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    assertTrue("selection model is not empty", this.selectionLayer.getSelectionModel().getSelections().isEmpty());
}
Also used : RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 4 with RowStructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class FilterRowDataLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    boolean handled = false;
    if (command instanceof ClearFilterCommand && command.convertToTargetLayer(this)) {
        int columnPosition = ((ClearFilterCommand) command).getColumnPosition();
        setDataValueByPosition(columnPosition, 0, null);
        handled = true;
    } else if (command instanceof ClearAllFiltersCommand) {
        getFilterRowDataProvider().clearAllFilters();
        handled = true;
    }
    if (handled) {
        fireLayerEvent(new RowStructuralRefreshEvent(this));
        return true;
    } else {
        return super.doCommand(command);
    }
}
Also used : ClearFilterCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ClearFilterCommand) ClearAllFiltersCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ClearAllFiltersCommand) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)

Example 5 with RowStructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class ColumnGroupHeaderLayer method setCalculateHeight.

public void setCalculateHeight(boolean calculateHeight) {
    boolean changed = calculateHeight != this.calculateHeight;
    this.calculateHeight = calculateHeight;
    if (changed) {
        if (calculateHeight) {
            this.model.registerColumnGroupModelListener(this.modelChangeListener);
        } else {
            this.model.unregisterColumnGroupModelListener(this.modelChangeListener);
        }
        this.fireLayerEvent(new RowStructuralRefreshEvent(this));
    }
}
Also used : RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)

Aggregations

RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)16 Test (org.junit.Test)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)3 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)2 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2 ClearAllFiltersCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ClearAllFiltersCommand)2 ClearFilterCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ClearFilterCommand)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 DisposeResourcesCommand (org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand)1 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)1 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)1 DiscardDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand)1 SaveDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand)1 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)1 ToggleFilterRowCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ToggleFilterRowCommand)1 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)1