~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.structures/src/org/eclipse/linuxtools/systemtap/ui/structures/TreeNode.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2006 IBM Corporation.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.ui.structures;
 
13
 
 
14
import java.util.ArrayList;
 
15
 
 
16
public class TreeNode {
 
17
        public TreeNode(Object d, boolean c) {
 
18
                children = new ArrayList<TreeNode>();
 
19
                data = d;
 
20
                clickable = c;
 
21
 
 
22
                if(null == data)
 
23
                        display = null;
 
24
                else
 
25
                        display = d.toString();
 
26
        }
 
27
        
 
28
        public TreeNode(Object d, String disp, boolean c) {
 
29
                children = new ArrayList<TreeNode>();
 
30
                data = d;
 
31
                display = disp;
 
32
                clickable = c;
 
33
        }
 
34
 
 
35
        public void add(TreeNode item) {
 
36
                children.add(item);
 
37
        }
 
38
        
 
39
        public void addAt(TreeNode item, int location) {
 
40
                children.add(Math.min(children.size(), location), item);
 
41
        }
 
42
        
 
43
        public int getChildCount() {
 
44
                return children.size();
 
45
        }
 
46
        
 
47
        public TreeNode getChildAt(int i){
 
48
                if(children.size() > i)
 
49
                        return (TreeNode)children.get(i);
 
50
                else
 
51
                        return null;
 
52
        }
 
53
        
 
54
        public Object getData() {
 
55
                return data;
 
56
        }
 
57
        
 
58
        public boolean isClickable() {
 
59
                return clickable;
 
60
        }
 
61
        
 
62
        public boolean remove(int i) {
 
63
                if(children.size() > i)
 
64
                        return(null != children.remove(i));
 
65
                else 
 
66
                        return false;
 
67
        }
 
68
        
 
69
        public boolean removeAll() {
 
70
                for(int i=children.size()-1; i>=0; i--) {
 
71
                        this.remove(i);
 
72
                }
 
73
                return true;
 
74
        }
 
75
        
 
76
        public void setData(Object d) {
 
77
                data = d;
 
78
        }
 
79
 
 
80
        public void setDisplay(String disp) {
 
81
                display = disp;
 
82
        }
 
83
 
 
84
        /**
 
85
         * Restructures the tree so that probes are grouped by type and
 
86
         * functions are sorted alphabetically.
 
87
         */
 
88
        public void sortTree() {
 
89
                TreeNode temp = null;
 
90
                
 
91
                sortLevel();
 
92
                for(int i=0; i<this.getChildCount(); i++) {
 
93
                        temp = this.getChildAt(i);
 
94
                        
 
95
                        temp.sortTree();
 
96
                }
 
97
        }
 
98
 
 
99
        /**
 
100
         * Performs quicksort on the level.
 
101
         */
 
102
        public void sortLevel() {
 
103
                int j;
 
104
                
 
105
                Object children[] = this.children.toArray();
 
106
                this.removeAll();
 
107
                Sort.quicksort(children, 0, children.length-1);
 
108
                
 
109
                for(j=0; j<children.length; j++)
 
110
                        this.add((TreeNode)children[j]);
 
111
        }
 
112
        
 
113
        public String toString() {
 
114
                return display;
 
115
        }
 
116
        
 
117
        public void dispose() {
 
118
                if(null != children)
 
119
                        for(int i=children.size()-1; i>=0; i--)
 
120
                                ((TreeNode)children.get(i)).dispose();
 
121
                children = null;
 
122
                data = null;
 
123
                display = null;
 
124
        }
 
125
        
 
126
        private ArrayList<TreeNode> children;
 
127
        private Object data;
 
128
        private String display;
 
129
        private boolean clickable;
 
130
}