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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations