Search in sources :

Example 1 with ITmfTreeViewerEntry

use of org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry in project tracecompass by tracecompass.

the class TreeUtil method getPath.

/**
 * Gets the path of an entry
 *
 * @param entry
 *            the entry (e.g. /root/foo/bar)
 * @return the path as a collection (e.g. ["root", "foo", "bar"])
 */
public static Collection<String> getPath(@NonNull ITmfTreeViewerEntry entry) {
    Deque<String> retVal = new ArrayDeque<>();
    ITmfTreeViewerEntry current = entry;
    while (current.getParent() != null) {
        retVal.addFirst(current.getName());
        current = current.getParent();
    }
    return retVal;
}
Also used : ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) ArrayDeque(java.util.ArrayDeque)

Example 2 with ITmfTreeViewerEntry

use of org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry in project tracecompass by tracecompass.

the class TreeUtil method findEquivalent.

/**
 * Find an element in a new tree with the same path as the item to search
 * for. e.g. if there is a tree
 * <ul>
 * <li>root
 * <ul>
 * <li>foo
 * <ul>
 * <li>baz</li>
 * </ul>
 * </li>
 * <li>baz</li>
 * </ul>
 * </ul>
 *
 * and we search for <strong>/foo/bar</strong>
 *
 * then it will return the bolded entry
 *
 * <ul>
 * <li>root
 * <ul>
 * <li>foo
 * <ul>
 * <li><strong>baz</strong></li>
 * </ul>
 * </li>
 * <li>baz</li>
 * </ul>
 * </ul>
 *
 * @param entriesToSearch
 *            the root of the entries to search
 * @param selectedItem
 *            the item to search
 * @return the equivalent item in the new tree or null if not found
 */
@Nullable
private static ITmfTreeViewerEntry findEquivalent(@NonNull ITmfTreeViewerEntry entriesToSearch, @NonNull ITmfTreeViewerEntry selectedItem) {
    Collection<String> path = getPath(selectedItem);
    Iterator<String> iter = path.iterator();
    ITmfTreeViewerEntry currentEntry = entriesToSearch;
    while (iter.hasNext()) {
        String current = iter.next();
        boolean found = false;
        for (ITmfTreeViewerEntry child : currentEntry.getChildren()) {
            if (Objects.equals(child.getName(), current)) {
                found = true;
                currentEntry = child;
                break;
            }
        }
        if (!found) {
            return null;
        }
    }
    return currentEntry;
}
Also used : ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with ITmfTreeViewerEntry

use of org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry in project tracecompass by tracecompass.

the class TreeUtil method getNewSelection.

/**
 * Find new selected item
 *
 * @param selection
 *            the selected element
 * @param rootEntry
 *            the element to search through recursively
 * @return the new selected element
 */
public static ISelection getNewSelection(ISelection selection, @NonNull ITmfTreeViewerEntry rootEntry) {
    if (selection instanceof StructuredSelection && !selection.isEmpty()) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        Object element = structuredSelection.getFirstElement();
        if (element instanceof ITmfTreeViewerEntry) {
            ITmfTreeViewerEntry newSelection = findEquivalent(rootEntry, (ITmfTreeViewerEntry) element);
            return newSelection != null ? new StructuredSelection(newSelection) : StructuredSelection.EMPTY;
        }
    }
    return selection;
}
Also used : ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 4 with ITmfTreeViewerEntry

use of org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry in project tracecompass by tracecompass.

the class TmfFilteredXYChartViewer method handleCheckStateChangedEvent.

/**
 * Update the chart depending on the selected entries.
 *
 * @param entries
 *            Counters to display on the chart
 */
@Override
public void handleCheckStateChangedEvent(Collection<ITmfTreeViewerEntry> entries) {
    cancelUpdate();
    Iterable<TmfGenericTreeEntry> counterEntries = Iterables.filter(entries, TmfGenericTreeEntry.class);
    Collection<@NonNull Long> selectedIds = Sets.newHashSet(Iterables.transform(counterEntries, e -> e.getModel().getId()));
    if (!selectedIds.containsAll(fSelectedIds)) {
        clearContent();
    }
    fSelectedIds = selectedIds;
    // Update the styles as well
    BaseXYPresentationProvider presProvider = getPresentationProvider();
    for (ITmfTreeViewerEntry entry : entries) {
        if (entry instanceof TmfGenericTreeEntry) {
            TmfGenericTreeEntry<TmfTreeDataModel> genericEntry = (TmfGenericTreeEntry<TmfTreeDataModel>) entry;
            TmfTreeDataModel model = genericEntry.getModel();
            OutputElementStyle style = model.getStyle();
            if (style != null) {
                presProvider.setStyle(model.getId(), style);
            }
        }
    }
    updateContent();
}
Also used : Iterables(com.google.common.collect.Iterables) Chart(org.eclipse.swtchart.Chart) DataProviderManager(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager) ITmfTreeXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider) HashMap(java.util.HashMap) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) ICheckboxTreeViewerListener(org.eclipse.tracecompass.tmf.ui.viewers.tree.ICheckboxTreeViewerListener) Multimap(com.google.common.collect.Multimap) TmfGenericTreeEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfGenericTreeEntry) Nullable(org.eclipse.jdt.annotation.Nullable) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) TmfTraceSelectedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Collection(java.util.Collection) FetchParametersUtils(org.eclipse.tracecompass.internal.tmf.core.model.filters.FetchParametersUtils) IOutputStyleProvider(org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider) DataProviderParameterUtils(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils) Sets(com.google.common.collect.Sets) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) IYAppearance(org.eclipse.tracecompass.tmf.core.presentation.IYAppearance) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider) ITmfXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXYDataProvider) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) TmfGenericTreeEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfGenericTreeEntry) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider)

Example 5 with ITmfTreeViewerEntry

use of org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry in project tracecompass by tracecompass.

the class CpuUsageTreeViewer method modelToTree.

@Override
protected ITmfTreeViewerEntry modelToTree(long start, long end, List<ITmfTreeDataModel> model) {
    double time = end - start;
    Map<Long, TmfTreeViewerEntry> map = new HashMap<>();
    // $NON-NLS-1$
    TmfTreeViewerEntry root = new TmfTreeViewerEntry("");
    map.put(-1L, root);
    for (CpuUsageEntryModel entryModel : Iterables.filter(model, CpuUsageEntryModel.class)) {
        // Add a total series to the presentation provider if the tid is < 0
        int tid = entryModel.getTid();
        if (tid < 0) {
            fPresentationProvider.addTotalSeries(entryModel.getId());
        }
        CpuUsageEntry cpuUsageEntry = new CpuUsageEntry(entryModel, entryModel.getTime() / time);
        map.put(entryModel.getId(), cpuUsageEntry);
        TmfTreeViewerEntry parent = map.get(entryModel.getParentId());
        if (parent != null) {
            parent.addChild(cpuUsageEntry);
        }
    }
    return root;
}
Also used : TmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry) ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) HashMap(java.util.HashMap) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)

Aggregations

ITmfTreeViewerEntry (org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry)5 HashMap (java.util.HashMap)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 ArrayDeque (java.util.ArrayDeque)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Composite (org.eclipse.swt.widgets.Composite)1 Chart (org.eclipse.swtchart.Chart)1 CpuUsageEntryModel (org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)1 BaseXYPresentationProvider (org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider)1 FetchParametersUtils (org.eclipse.tracecompass.internal.tmf.core.model.filters.FetchParametersUtils)1 DataProviderManager (org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager)1 DataProviderParameterUtils (org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils)1 IOutputStyleProvider (org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider)1