1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.wizards
.tracepkg
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.swt
.graphics
.Image
;
19 import org
.eclipse
.ui
.model
.WorkbenchAdapter
;
22 * An ExportTraceElement represents an item in the ExportTraceWizard tree.
24 * @author Marc-Andre Laperle
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
;
36 * the parent of this element, can be set to null
38 public TracePackageElement(TracePackageElement parent
) {
42 fChildren
= new TracePackageElement
[0];
46 * @return the parent of this element or null if there is no parent
48 public TracePackageElement
getParent() {
53 * Get the text representation of this element to be displayed in the tree.
55 * @return the text representation
57 abstract public String
getText();
60 * Get the children of this element
62 * @return the children of this element
64 public TracePackageElement
[] getChildren() {
69 * Get the visible children of this element
71 * @return the visible children of this element
73 public TracePackageElement
[] getVisibleChildren() {
74 List
<TracePackageElement
> visibleChildren
= new ArrayList
<>();
75 for (TracePackageElement child
: fChildren
) {
76 if (child
.isVisible()) {
77 visibleChildren
.add(child
);
80 return visibleChildren
.toArray(new TracePackageElement
[0]);
84 * Set the children of this element
87 * the children of this element
89 public void setChildren(TracePackageElement
[] children
) {
90 this.fChildren
= children
;
94 * Get the total size of the element including its children
97 * only count checked elements
99 * @return the total size of the element
101 public long getSize(boolean checkedOnly
) {
103 if (fChildren
!= null) {
104 for (TracePackageElement child
: fChildren
) {
105 size
+= child
.getSize(checkedOnly
);
113 * Get the image representation of this element to be displayed in the tree.
115 * @return the image representation
117 public Image
getImage() {
122 * Returns whether or not the element is enabled (grayed and not
125 * @return whether or not the element is enabled
127 public boolean isEnabled() {
132 * Returns whether or not the element is checked.
134 * @return whether or not the element is checked
136 public boolean isChecked() {
141 * Returns whether or not the element is visible.
143 * @return whether or not the element is visible
145 public boolean isVisible() {
150 * Sets whether or not the element should be enabled (grayed and not
154 * if the element should be enabled
156 public void setEnabled(boolean enabled
) {
161 * Sets whether or not the element should be checked.
164 * if the element should be checked
166 public void setChecked(boolean checked
) {
171 * Sets whether or not the element is visible.
174 * if the element should be visible
176 public void setVisible(boolean visible
) {