Example usage for org.eclipse.jface.viewers TableViewer setItemCount

List of usage examples for org.eclipse.jface.viewers TableViewer setItemCount

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TableViewer setItemCount.

Prototype

public void setItemCount(int count) 

Source Link

Document

Set the item count of the receiver.

Usage

From source file:org.lttng.scope.lami.ui.viewers.LamiTableViewer.java

License:Open Source License

/**
 * Update the data in the table viewer//ww  w . ja  va2 s.  co  m
 *
 * @param dataInput
 *            New data input
 */
private void fillData() {
    final TableViewer tableViewer = getTableViewer();
    Display.getDefault().asyncExec(() -> {
        if (tableViewer.getTable().isDisposed()) {
            return;
        }
        // Go to the top of the table
        tableViewer.getTable().setTopIndex(0);
        // Reset selected row
        tableViewer.setSelection(StructuredSelection.EMPTY);

        /* Fill the table data */
        tableViewer.setInput(fPage.getResultTable().getEntries());
        LamiTableContentProvider latencyContentProvider = (LamiTableContentProvider) getTableViewer()
                .getContentProvider();
        tableViewer.setItemCount(latencyContentProvider.getNbEntries());

        /* Set the column's alignment and pack them */
        TableColumn[] cols = tableViewer.getTable().getColumns();
        for (int i = 0; i < cols.length; i++) {
            LamiTableEntryAspect colAspect = fPage.getResultTable().getTableClass().getAspects().get(i);
            int alignment = (colAspect.isContinuous() ? SWT.RIGHT : SWT.LEFT);
            cols[i].setAlignment(alignment);

        }

        /*
         * On creation check if there is selections if so update the table
         * selections here. Selections needs the ContentProvider for valid
         * index lookup and since the content provider is set in an
         * asynchronous task we cannot use the normal signal handler since
         * we have no guarantee of time of execution of the fill data.
         */
        if (!fSelections.isEmpty()) {
            int[] selectionsIndexes = fSelections.stream()
                    .map(index -> fPage.getResultTable().getEntries().get(index))
                    .mapToInt(entry -> ((LamiTableContentProvider) getTableViewer().getContentProvider())
                            .getIndexOf(entry))
                    .toArray();

            Display.getDefault().asyncExec(() -> {
                getTableViewer().getTable().setSelection(selectionsIndexes);
                getTableViewer().getTable().redraw();
            });
        }
    });
    Display.getDefault().asyncExec(() -> {
        if (tableViewer.getTable().isDisposed()) {
            return;
        }

        TableColumn[] cols = tableViewer.getTable().getColumns();
        for (int i = 0; i < cols.length; i++) {
            cols[i].pack();
        }
    });
}