tmf: Move plugins to their own sub-directory
[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 @NonNull
32 private final List<ITmfTreeViewerEntry> fChildren = new CopyOnWriteArrayList<>();
33
34 /** Name of this entry (default text to show in first column) */
35 private String fName;
36
37 /**
38 * Constructor
39 *
40 * @param name
41 * The name of this entry
42 */
43 public TmfTreeViewerEntry(String name) {
44 fName = name;
45 }
46
47 // ---------------------------------------------
48 // Getters and setters
49 // ---------------------------------------------
50
51 @Override
52 public ITmfTreeViewerEntry getParent() {
53 return fParent;
54 }
55
56 /**
57 * Sets the entry's parent
58 *
59 * @param entry The new parent entry
60 */
61 protected void setParent(ITmfTreeViewerEntry entry) {
62 fParent = entry;
63 }
64
65 @Override
66 public boolean hasChildren() {
67 return fChildren.size() > 0;
68 }
69
70 @Override
71 public List<ITmfTreeViewerEntry> getChildren() {
72 return fChildren;
73 }
74
75 @Override
76 public String getName() {
77 return fName;
78 }
79
80 /**
81 * Update the entry name
82 *
83 * @param name
84 * the updated entry name
85 */
86 public void setName(String name) {
87 fName = name;
88 }
89
90 /**
91 * Add a child entry to this one
92 *
93 * @param child
94 * The child entry
95 */
96 public void addChild(TmfTreeViewerEntry child) {
97 child.fParent = this;
98 fChildren.add(child);
99 }
100
101 @Override
102 public String toString() {
103 return getClass().getSimpleName() + '[' + fName + ']';
104 }
105
106 }
This page took 0.033255 seconds and 5 git commands to generate.