Adapt views plugins to TMF
[deliverable/tracecompass.git] / tmf / org.lttng.scope.tmf2.views.core / src / org / lttng / scope / tmf2 / views / core / timegraph / model / render / tree / TimeGraphTreeRender.java
CommitLineData
735b1ca2
AM
1/*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10package org.lttng.scope.tmf2.views.core.timegraph.model.render.tree;
11
12import java.util.List;
13import java.util.Objects;
14import java.util.stream.Collectors;
15
16import org.eclipse.jdt.annotation.Nullable;
a2fb04cd 17import org.eclipse.tracecompass.common.core.StreamUtils.StreamFlattener;
735b1ca2
AM
18
19/**
20 * Render of a tree of the timegraph. Contains the tree elements that compose
21 * the current tree.
22 *
23 * In a timegraph, the "tree" part is usually shown on the left-hand side, and
24 * lists the tree elements, which represent attributes of a model. A tree render
25 * is a "snapshot" of this tree that is valid for a given timestamp or
26 * timerange.
27 *
28 * Some timegraphs may use a tree that is valid for the whole time range of a
29 * trace. Other timegraphs may display a different tree for different parts of
30 * the trace.
31 *
32 * @author Alexandre Montplaisir
33 */
34public class TimeGraphTreeRender {
35
36 /**
37 * A static reference to an empty render, which can be used to represent an
38 * uninitialized state for example (by comparing with ==).
39 */
40 public static final TimeGraphTreeRender EMPTY_RENDER = new TimeGraphTreeRender(TimeGraphTreeElement.DUMMY_ELEMENT);
41
42 private final TimeGraphTreeElement fRootElement;
43
44 /**
45 * Constructor
46 *
47 * @param rootElement
48 * The root element of the tree
49 */
50 public TimeGraphTreeRender(TimeGraphTreeElement rootElement) {
51 fRootElement = rootElement;
52 }
53
54 /**
55 * Return the root element of this tree.
56 *
57 * @return The root element
58 */
59 public TimeGraphTreeElement getRootElement() {
60 return fRootElement;
61 }
62
63 /**
64 * Get a flattened view of all the tree elements in this render.
65 *
66 * This should also contains all the child elements that are also contained
67 * in each element's {@link TimeGraphTreeElement#getChildElements()}. It can
68 * be used to run an action on all elements of a render.
69 *
70 * @return A list of all the tree elements
71 */
72 public List<TimeGraphTreeElement> getAllTreeElements() {
73 StreamFlattener<TimeGraphTreeElement> flattener = new StreamFlattener<>(i -> i.getChildElements().stream());
74 return flattener.flatten(getRootElement()).collect(Collectors.toList());
75 }
76
77 @Override
78 public int hashCode() {
79 return Objects.hash(fRootElement);
80 }
81
82 @Override
83 public boolean equals(@Nullable Object obj) {
84 if (this == obj) {
85 return true;
86 }
87 if (obj == null) {
88 return false;
89 }
90 if (getClass() != obj.getClass()) {
91 return false;
92 }
93 TimeGraphTreeRender other = (TimeGraphTreeRender) obj;
94 return (Objects.equals(fRootElement, other.fRootElement));
95 }
96
97}
This page took 0.042689 seconds and 5 git commands to generate.