Search in sources :

Example 1 with DisposeResourcesCommand

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

the class GroupByDataLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof CalculateSummaryRowValuesCommand) {
        // summary values
        for (int i = 0; i < getRowCount(); i++) {
            if (this.treeData.getDataAtIndex(i) instanceof GroupByObject) {
                for (int j = 0; j < getColumnCount(); j++) {
                    LabelStack labelStack = getConfigLabelsByPosition(j, i);
                    final IGroupBySummaryProvider<T> summaryProvider = getGroupBySummaryProvider(labelStack);
                    if (summaryProvider != null) {
                        GroupByObject groupByObject = (GroupByObject) this.treeData.getDataAtIndex(i);
                        final List<T> children = getItemsInGroup(groupByObject);
                        final int col = j;
                        this.valueCache.getCalculatedValue(j, i, new GroupByValueCacheKey(j, i, groupByObject), false, new ICalculator() {

                            @Override
                            public Object executeCalculation() {
                                return summaryProvider.summarize(col, children);
                            }
                        });
                    }
                }
            }
        }
    // we do not return true here, as there might be other layers
    // involved in the composition that also need to calculate the
    // summary values immediately
    } else if (command instanceof DisposeResourcesCommand) {
        // ensure to clear the caches to avoid memory leaks
        this.treeFormat.clearComparatorCache();
        this.valueCache.killCache();
        this.valueCache.dispose();
    }
    return super.doCommand(command);
}
Also used : DisposeResourcesCommand(org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand) CalculateSummaryRowValuesCommand(org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ICalculator(org.eclipse.nebula.widgets.nattable.util.ICalculator)

Example 2 with DisposeResourcesCommand

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

the class ComboBoxFilterRowHeaderComposite method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    boolean handled = false;
    if (command instanceof ToggleFilterRowCommand) {
        setFilterRowVisible(!this.filterRowVisible);
        return true;
    } else // to the FilterRowDataLayer
    if (command instanceof ClearFilterCommand && command.convertToTargetLayer(this)) {
        int columnPosition = ((ClearFilterCommand) command).getColumnPosition();
        this.filterRowDataLayer.setDataValueByPosition(columnPosition, 0, getComboBoxDataProvider().getValues(columnPosition, 0));
        handled = true;
    } else if (command instanceof ClearAllFiltersCommand) {
        setAllValuesSelected();
        handled = true;
    } else if (command instanceof DisposeResourcesCommand) {
        this.comboBoxDataProvider.dispose();
    }
    if (handled) {
        fireLayerEvent(new RowStructuralRefreshEvent(this));
        return true;
    } else {
        return super.doCommand(command);
    }
}
Also used : DisposeResourcesCommand(org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand) ClearFilterCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ClearFilterCommand) ClearAllFiltersCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ClearAllFiltersCommand) ToggleFilterRowCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ToggleFilterRowCommand) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)

Example 3 with DisposeResourcesCommand

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

the class GlazedListsEventLayerTest method shouldShutConflaterThreadDownWhenNatTableIsDisposed.

@Test
public void shouldShutConflaterThreadDownWhenNatTableIsDisposed() throws Exception {
    Assert.assertFalse(this.layerUnderTest.isDisposed());
    this.listFixture.add(RowDataFixture.getInstance("T1", "A"));
    Thread.sleep(100);
    this.listFixture.add(RowDataFixture.getInstance("T2", "A"));
    Thread.sleep(100);
    this.layerUnderTest.doCommand(new DisposeResourcesCommand());
    Assert.assertTrue(this.layerUnderTest.isDisposed());
}
Also used : DisposeResourcesCommand(org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand) Test(org.junit.Test)

Example 4 with DisposeResourcesCommand

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

the class NatTableTest method shouldFireDisposeCommandOnDisposal.

@Test
public void shouldFireDisposeCommandOnDisposal() throws Exception {
    AnyCommandHandlerFixture commandHandler = new AnyCommandHandlerFixture();
    this.underlyingLayerFixture.registerCommandHandler(commandHandler);
    this.natTable.dispose();
    assertEquals(1, commandHandler.getNumberOfCommandsHandled());
    assertTrue(commandHandler.getCommadHandled() instanceof DisposeResourcesCommand);
}
Also used : AnyCommandHandlerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.command.AnyCommandHandlerFixture) DisposeResourcesCommand(org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand) Test(org.junit.Test)

Aggregations

DisposeResourcesCommand (org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand)4 Test (org.junit.Test)2 ClearAllFiltersCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ClearAllFiltersCommand)1 ClearFilterCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ClearFilterCommand)1 ToggleFilterRowCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ToggleFilterRowCommand)1 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)1 RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)1 CalculateSummaryRowValuesCommand (org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand)1 AnyCommandHandlerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.command.AnyCommandHandlerFixture)1 ICalculator (org.eclipse.nebula.widgets.nattable.util.ICalculator)1