Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / tree / TmfTreeViewerEntry.java
CommitLineData
c0188b25
GB
1/*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.ui.viewers.tree;
14
15import java.util.List;
16import java.util.concurrent.CopyOnWriteArrayList;
17
59c8ff34
MAL
18import org.eclipse.jdt.annotation.NonNull;
19
c0188b25
GB
20/**
21 * Basic implementation of an entry for the TMF tree viewer. A name is all that is needed for this entry.
22 *
23 * @author Geneviève Bastien
24 * @since 3.0
25 */
26public class TmfTreeViewerEntry implements ITmfTreeViewerEntry {
27
28 /** Entry's parent */
29 private ITmfTreeViewerEntry fParent = null;
30
31 /** List of child entries */
59c8ff34 32 @NonNull
c0188b25
GB
33 private final List<ITmfTreeViewerEntry> fChildren = new CopyOnWriteArrayList<>();
34
35 /** Name of this entry (default text to show in first column) */
36 private String fName;
37
38 /**
39 * Constructor
40 *
41 * @param name
42 * The name of this entry
43 */
44 public TmfTreeViewerEntry(String name) {
45 fName = name;
46 }
47
48 // ---------------------------------------------
49 // Getters and setters
50 // ---------------------------------------------
51
52 @Override
53 public ITmfTreeViewerEntry getParent() {
54 return fParent;
55 }
56
57 /**
58 * Sets the entry's parent
59 *
60 * @param entry The new parent entry
61 */
62 protected void setParent(ITmfTreeViewerEntry entry) {
63 fParent = entry;
64 }
65
66 @Override
67 public boolean hasChildren() {
68 return fChildren.size() > 0;
69 }
70
71 @Override
72 public List<ITmfTreeViewerEntry> getChildren() {
73 return fChildren;
74 }
75
76 @Override
77 public String getName() {
78 return fName;
79 }
80
81 /**
82 * Update the entry name
83 *
84 * @param name
85 * the updated entry name
86 */
87 public void setName(String name) {
88 fName = name;
89 }
90
91 /**
92 * Add a child entry to this one
93 *
94 * @param child
95 * The child entry
96 */
97 public void addChild(TmfTreeViewerEntry child) {
98 child.fParent = this;
99 fChildren.add(child);
100 }
101
7c246810
PT
102 @Override
103 public String toString() {
104 return getClass().getSimpleName() + '[' + fName + ']';
105 }
106
c0188b25 107}
This page took 0.040357 seconds and 5 git commands to generate.