Search in sources :

Example 1 with SegmentStoreContentProvider

use of org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider in project tracecompass by tracecompass.

the class AbstractSegmentStoreTableViewer method setSegmentProvider.

// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
/**
 * Sets the segment provider, use only in test, only run in display thread
 *
 * @param segmentProvider
 *            the segment provider
 * @since 1.2
 */
@VisibleForTesting
public void setSegmentProvider(ISegmentStoreProvider segmentProvider) {
    fSegmentProvider = segmentProvider;
    // Sort order of the content provider is by start time by default
    getTableViewer().setContentProvider(new SegmentStoreContentProvider());
    Table table = getTableViewer().getTable();
    table.setRedraw(false);
    while (table.getColumnCount() > 0) {
        table.getColumn(0).dispose();
    }
    createColumns();
    createProviderColumns();
    getTableViewer().getTable().addSelectionListener(new TableSelectionListener());
    addPackListener();
    table.setRedraw(true);
}
Also used : Table(org.eclipse.swt.widgets.Table) SegmentStoreContentProvider(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with SegmentStoreContentProvider

use of org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider in project tracecompass by tracecompass.

the class AbstractSegmentStoreTableViewer method updateModel.

/**
 * Update the data in the table viewer
 *
 * @param dataInput
 *            New data input
 */
public void updateModel(@Nullable final Object dataInput) {
    final TableViewer tableViewer = getTableViewer();
    Display.getDefault().asyncExec(() -> {
        try (ScopeLog sl = new ScopeLog(LOGGER, Level.FINE, "updateModel")) {
            // $NON-NLS-1$
            if (!tableViewer.getTable().isDisposed()) {
                // Go to the top of the table
                tableViewer.getTable().setTopIndex(0);
                ISelection selection = tableViewer.getSelection();
                ISegment selected = null;
                if (!selection.isEmpty() && selection instanceof StructuredSelection) {
                    Object firstElement = ((StructuredSelection) selection).getFirstElement();
                    if (firstElement instanceof ISegment) {
                        selected = (ISegment) firstElement;
                    }
                }
                // Reset selected row
                if (dataInput == null) {
                    tableViewer.setSelection(StructuredSelection.EMPTY);
                    tableViewer.setInput(null);
                    tableViewer.setItemCount(0);
                    return;
                }
                addPackListener();
                tableViewer.setInput(dataInput);
                SegmentStoreContentProvider contentProvider = (SegmentStoreContentProvider) getTableViewer().getContentProvider();
                long segmentCount = contentProvider.getSegmentCount();
                String contentProviderName = contentProvider.getClass().getSimpleName();
                // $NON-NLS-1$
                TraceCompassLogUtils.traceCounter(LOGGER, Level.FINE, "SegmentStoreTableViewer#updateModel", contentProviderName, segmentCount);
                if (segmentCount > MAX_ITEMS) {
                    tableViewer.setItemCount(MAX_ITEMS);
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    Activator.getDefault().logWarning("Too many items to display for " + contentProviderName + ". Cannot display " + segmentCount + " in a reasonable timeframe.");
                } else {
                    tableViewer.setItemCount((int) segmentCount);
                }
                boolean found = false;
                if (selected != null && dataInput instanceof ISegmentStore<?>) {
                    ISegmentStore<?> store = (ISegmentStore<?>) dataInput;
                    for (ISegment segment : store.getIntersectingElements(selected.getEnd())) {
                        if (isSameish(segment, selected)) {
                            selection = new StructuredSelection(segment);
                            tableViewer.setSelection(selection, true);
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    tableViewer.setSelection(StructuredSelection.EMPTY);
                }
            }
        }
    });
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) ISegmentStore(org.eclipse.tracecompass.segmentstore.core.ISegmentStore) TableViewer(org.eclipse.jface.viewers.TableViewer) TmfSimpleTableViewer(org.eclipse.tracecompass.tmf.ui.viewers.table.TmfSimpleTableViewer) ScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog) SegmentStoreContentProvider(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider)

Aggregations

SegmentStoreContentProvider (org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Table (org.eclipse.swt.widgets.Table)1 ScopeLog (org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog)1 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)1 ISegmentStore (org.eclipse.tracecompass.segmentstore.core.ISegmentStore)1 TmfSimpleTableViewer (org.eclipse.tracecompass.tmf.ui.viewers.table.TmfSimpleTableViewer)1