Fix some null warnings
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / tree / TmfTreeViewerEntry.java
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
13 package org.eclipse.tracecompass.tmf.ui.viewers.tree;
14
15 import java.util.List;
16 import java.util.concurrent.CopyOnWriteArrayList;
17
18 import org.eclipse.jdt.annotation.NonNull;
19
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 */
25 public class TmfTreeViewerEntry implements ITmfTreeViewerEntry {
26
27 /** Entry's parent */
28 private ITmfTreeViewerEntry fParent = null;
29
30 /** List of child entries */
31 private final @NonNull List<@NonNull ITmfTreeViewerEntry> fChildren = new CopyOnWriteArrayList<>();
32
33 /** Name of this entry (default text to show in first column) */
34 private String fName;
35
36 /**
37 * Constructor
38 *
39 * @param name
40 * The name of this entry
41 */
42 public TmfTreeViewerEntry(String name) {
43 fName = name;
44 }
45
46 // ---------------------------------------------
47 // Getters and setters
48 // ---------------------------------------------
49
50 @Override
51 public ITmfTreeViewerEntry getParent() {
52 return fParent;
53 }
54
55 /**
56 * Sets the entry's parent
57 *
58 * @param entry The new parent entry
59 */
60 protected void setParent(ITmfTreeViewerEntry entry) {
61 fParent = entry;
62 }
63
64 @Override
65 public boolean hasChildren() {
66 return fChildren.size() > 0;
67 }
68
69 @Override
70 public List<@NonNull ITmfTreeViewerEntry> getChildren() {
71 return fChildren;
72 }
73
74 @Override
75 public String getName() {
76 return fName;
77 }
78
79 /**
80 * Update the entry name
81 *
82 * @param name
83 * the updated entry name
84 */
85 public void setName(String name) {
86 fName = name;
87 }
88
89 /**
90 * Add a child entry to this one
91 *
92 * @param child
93 * The child entry
94 */
95 public void addChild(TmfTreeViewerEntry child) {
96 child.fParent = this;
97 fChildren.add(child);
98 }
99
100 @Override
101 public String toString() {
102 return getClass().getSimpleName() + '[' + fName + ']';
103 }
104
105 }
This page took 0.032215 seconds and 5 git commands to generate.