tmf: Make it possible to hide trace package elements
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / wizards / tracepkg / TracePackageElement.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.ui.model.WorkbenchAdapter;
20
21 /**
22 * An ExportTraceElement represents an item in the ExportTraceWizard tree.
23 *
24 * @author Marc-Andre Laperle
25 */
26 public abstract class TracePackageElement extends WorkbenchAdapter {
27 private TracePackageElement[] fChildren;
28 private final TracePackageElement fParent;
29 private boolean fEnabled;
30 private boolean fChecked;
31 private boolean fVisible;
32
33 /**
34 *
35 * @param parent
36 * the parent of this element, can be set to null
37 */
38 public TracePackageElement(TracePackageElement parent) {
39 fParent = parent;
40 fEnabled = true;
41 fVisible = true;
42 fChildren = new TracePackageElement[0];
43 }
44
45 /**
46 * @return the parent of this element or null if there is no parent
47 */
48 public TracePackageElement getParent() {
49 return fParent;
50 }
51
52 /**
53 * Get the text representation of this element to be displayed in the tree.
54 *
55 * @return the text representation
56 */
57 abstract public String getText();
58
59 /**
60 * Get the children of this element
61 *
62 * @return the children of this element
63 */
64 public TracePackageElement[] getChildren() {
65 return fChildren;
66 }
67
68 /**
69 * Get the visible children of this element
70 *
71 * @return the visible children of this element
72 */
73 public TracePackageElement[] getVisibleChildren() {
74 List<TracePackageElement> visibleChildren = new ArrayList<>();
75 for (TracePackageElement child : fChildren) {
76 if (child.isVisible()) {
77 visibleChildren.add(child);
78 }
79 }
80 return visibleChildren.toArray(new TracePackageElement[0]);
81 }
82
83 /**
84 * Set the children of this element
85 *
86 * @param children
87 * the children of this element
88 */
89 public void setChildren(TracePackageElement[] children) {
90 this.fChildren = children;
91 }
92
93 /**
94 * Get the total size of the element including its children
95 *
96 * @param checkedOnly
97 * only count checked elements
98 *
99 * @return the total size of the element
100 */
101 public long getSize(boolean checkedOnly) {
102 long size = 0;
103 if (fChildren != null) {
104 for (TracePackageElement child : fChildren) {
105 size += child.getSize(checkedOnly);
106 }
107 }
108
109 return size;
110 }
111
112 /**
113 * Get the image representation of this element to be displayed in the tree.
114 *
115 * @return the image representation
116 */
117 public Image getImage() {
118 return null;
119 }
120
121 /**
122 * Returns whether or not the element is enabled (grayed and not
123 * modifiable).
124 *
125 * @return whether or not the element is enabled
126 */
127 public boolean isEnabled() {
128 return fEnabled;
129 }
130
131 /**
132 * Returns whether or not the element is checked.
133 *
134 * @return whether or not the element is checked
135 */
136 public boolean isChecked() {
137 return fChecked;
138 }
139
140 /**
141 * Returns whether or not the element is visible.
142 *
143 * @return whether or not the element is visible
144 */
145 public boolean isVisible() {
146 return fVisible;
147 }
148
149 /**
150 * Sets whether or not the element should be enabled (grayed and not
151 * modifiable).
152 *
153 * @param enabled
154 * if the element should be enabled
155 */
156 public void setEnabled(boolean enabled) {
157 fEnabled = enabled;
158 }
159
160 /**
161 * Sets whether or not the element should be checked.
162 *
163 * @param checked
164 * if the element should be checked
165 */
166 public void setChecked(boolean checked) {
167 fChecked = checked;
168 }
169
170 /**
171 * Sets whether or not the element is visible.
172 *
173 * @param visible
174 * if the element should be visible
175 */
176 public void setVisible(boolean visible) {
177 fVisible = visible;
178 }
179 }
This page took 0.035767 seconds and 6 git commands to generate.