Search in sources :

Example 1 with ITableColumnDescriptor

use of org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor in project tracecompass by tracecompass.

the class TableColumnDescriptorTest method test.

// ------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------
/**
 * Test @{link TableColumnDescriptor) construction using {@link Builder}.
 */
@Test
public void test() {
    TableColumnDescriptor.Builder builder = new TableColumnDescriptor.Builder();
    ITableColumnDescriptor desc = builder.setText(COLUMN_TEXT0).build();
    assertEquals("Column header", COLUMN_TEXT0, desc.getText());
    assertTrue("Empty tooltip", desc.getTooltip().isEmpty());
    builder = new TableColumnDescriptor.Builder();
    desc = builder.setText(COLUMN_TEXT0).setTooltip(COLUMN_TOOLTIP0).build();
    assertEquals("Column header", COLUMN_TEXT0, desc.getText());
    assertEquals("Column tooltip", COLUMN_TOOLTIP0, desc.getTooltip());
    builder = new TableColumnDescriptor.Builder();
    desc = builder.setTooltip(COLUMN_TOOLTIP0).build();
    assertTrue("Empty Text", desc.getText().isEmpty());
    assertEquals("Column tooltip", COLUMN_TOOLTIP0, desc.getTooltip());
}
Also used : Builder(org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor.Builder) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) TableColumnDescriptor(org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor) Builder(org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor.Builder) Test(org.junit.Test)

Example 2 with ITableColumnDescriptor

use of org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor in project tracecompass by tracecompass.

the class TableColumnDescriptorTest method testHashCode.

// ------------------------------------------------------------------------
// TableColumnDescriptor#hashCode
// ------------------------------------------------------------------------
/**
 * Run the {@link ITableColumnDescriptor#hashCode} method test.
 */
@Test
public void testHashCode() {
    ITableColumnDescriptor model0 = createDescriptor(0);
    ITableColumnDescriptor model1 = createDescriptor(1);
    assertEquals(HASH_CODE, fModel0.hashCode(), model0.hashCode());
    assertEquals(HASH_CODE, fModel1.hashCode(), model1.hashCode());
    assertNotEquals(HASH_CODE, fModel0.hashCode(), model1.hashCode());
    assertNotEquals(HASH_CODE, fModel1.hashCode(), model0.hashCode());
}
Also used : ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) Test(org.junit.Test)

Example 3 with ITableColumnDescriptor

use of org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor in project tracecompass by tracecompass.

the class TableColumnDescriptorTest method testToString.

/**
 * Test {@link TableColumnDescriptor#toString()}
 */
@Test
public void testToString() {
    TableColumnDescriptor.Builder builder = new TableColumnDescriptor.Builder();
    ITableColumnDescriptor desc = builder.setText(COLUMN_TEXT0).setTooltip(COLUMN_TOOLTIP0).build();
    assertEquals(TO_STRING, "[text=Name tooltip=Tooltip]", desc.toString());
}
Also used : Builder(org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor.Builder) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) TableColumnDescriptor(org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor) Builder(org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor.Builder) Test(org.junit.Test)

Example 4 with ITableColumnDescriptor

use of org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor in project tracecompass by tracecompass.

the class TmfTreeCompositeDataProvider method fetchTree.

@Override
public TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    boolean isComplete = true;
    List<Entry<M, Object>> entries = new ArrayList<>();
    List<ITableColumnDescriptor> columnDescriptor = null;
    Table<Object, Long, @NonNull M> scopedEntries = HashBasedTable.create();
    for (P dataProvider : fProviders) {
        Map<Long, AtomicInteger> indexMap = new HashMap<>();
        TmfModelResponse<TmfTreeModel<M>> response = dataProvider.fetchTree(fetchParameters, monitor);
        isComplete &= response.getStatus() == ITmfResponse.Status.COMPLETED;
        TmfTreeModel<M> model = response.getModel();
        if (model != null) {
            Object scope = (model.getScope() == null) ? dataProvider : model.getScope();
            Map<Long, @NonNull M> row = scopedEntries.row(scope);
            for (M entry : model.getEntries()) {
                M previous = row.putIfAbsent(entry.getId(), entry);
                // Ignore duplicate entries from different data providers
                if (previous == null) {
                    if (entry.getParentId() == -1) {
                        entries.add(new SimpleEntry(entry, scope));
                    } else {
                        /*
                             * Insert new entries from subsequent data providers
                             * at the correct position in the entries list. New
                             * entries are inserted before sibling entries from
                             * previous data providers.
                             */
                        int index = indexMap.computeIfAbsent(entry.getParentId(), l -> new AtomicInteger()).getAndIncrement();
                        int pos = 0;
                        while (pos < entries.size()) {
                            Entry<M, Object> added = entries.get(pos);
                            if (added.getValue().equals(scope) && added.getKey().getParentId() == entry.getParentId()) {
                                if (index == 0) {
                                    break;
                                }
                                index--;
                            }
                            pos++;
                        }
                        if (pos < entries.size()) {
                            entries.add(pos, new SimpleEntry(entry, scope));
                        } else {
                            entries.add(new SimpleEntry(entry, scope));
                        }
                    }
                } else {
                    indexMap.computeIfAbsent(entry.getParentId(), l -> new AtomicInteger()).getAndIncrement();
                }
            }
            // Use the column descriptor of the first model. All descriptors are supposed to be the same
            if (columnDescriptor == null) {
                columnDescriptor = model.getColumnDescriptors();
            }
        }
        if (monitor != null && monitor.isCanceled()) {
            return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
    }
    TmfTreeModel.Builder<M> treeModelBuilder = new TmfTreeModel.Builder<>();
    if (columnDescriptor == null) {
        columnDescriptor = Collections.emptyList();
    }
    treeModelBuilder.setColumnDescriptors(columnDescriptor).setEntries(Lists.transform(entries, e -> e.getKey()));
    if (isComplete) {
        return new TmfModelResponse<>(treeModelBuilder.build(), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    return new TmfModelResponse<>(treeModelBuilder.build(), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
Also used : DataProviderManager(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager) CommonStatusMessage(org.eclipse.tracecompass.tmf.core.model.CommonStatusMessage) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) HashMap(java.util.HashMap) HashBasedTable(com.google.common.collect.HashBasedTable) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Nullable(org.eclipse.jdt.annotation.Nullable) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) Map(java.util.Map) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) SimpleEntry(java.util.AbstractMap.SimpleEntry) ITmfResponse(org.eclipse.tracecompass.tmf.core.response.ITmfResponse) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Collection(java.util.Collection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Entry(java.util.Map.Entry) ITmfTreeDataProvider(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) AnnotationCategoriesModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationCategoriesModel) Table(com.google.common.collect.Table) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) SimpleEntry(java.util.AbstractMap.SimpleEntry) Entry(java.util.Map.Entry) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) SimpleEntry(java.util.AbstractMap.SimpleEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)

Example 5 with ITableColumnDescriptor

use of org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor in project tracecompass by tracecompass.

the class SegmentStoreStatisticsDataProviderTest method testFetchTreeWithMapperFullRange.

/**
 * Test to verify
 * {@link SegmentStoreStatisticsDataProvider#fetchTree(Map, org.eclipse.core.runtime.IProgressMonitor)}
 * for the full trace
 */
@Test
public void testFetchTreeWithMapperFullRange() {
    Map<@NonNull String, @NonNull Object> fetchParameters = new HashMap<>();
    TmfModelResponse<@NonNull TmfTreeModel<@NonNull SegmentStoreStatisticsModel>> response = fTestDataProvider2.fetchTree(fetchParameters, new NullProgressMonitor());
    assertNotNull(response);
    TmfTreeModel<@NonNull SegmentStoreStatisticsModel> treeModel = response.getModel();
    assertNotNull(treeModel);
    assertEquals("Header list size", EXPECTED_HEADER_LIST.size(), treeModel.getHeaders().size());
    assertEquals("Header list", EXPECTED_HEADER_LIST, treeModel.getHeaders());
    List<@NonNull ITableColumnDescriptor> columnDescriptors = treeModel.getColumnDescriptors();
    assertEquals("Header descriptor list size", EXPECTED_HEADER_LIST.size(), columnDescriptors.size());
    assertEquals("Column descriptor list", fExpectedDescriptors, columnDescriptors);
    assertNull("Scope", treeModel.getScope());
    List<@NonNull SegmentStoreStatisticsModel> entries = treeModel.getEntries();
    assertNotNull("Entries", entries);
    verifyEntries(LIST_OF_EXPECTED_LABELS_WITH_MAPPER_FULL, EXPECTED_STATS_WITH_MAPPER_FULL, entries, 0, EXPECTED_STATS_WITH_MAPPER_FULL.size());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SegmentStoreStatisticsModel(org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreStatisticsModel) HashMap(java.util.HashMap) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) Test(org.junit.Test)

Aggregations

ITableColumnDescriptor (org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor)10 Test (org.junit.Test)9 NonNull (org.eclipse.jdt.annotation.NonNull)4 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)4 HashMap (java.util.HashMap)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 SegmentStoreStatisticsModel (org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreStatisticsModel)3 TableColumnDescriptor (org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor)2 Builder (org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor.Builder)2 HashBasedTable (com.google.common.collect.HashBasedTable)1 Lists (com.google.common.collect.Lists)1 Table (com.google.common.collect.Table)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1