~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.callgraph.genericzestdemo/src/org/eclipse/linuxtools/sleepingthreads/XMLGraphingView.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.eclipse.linuxtools.sleepingthreads;
2
 
 
3
 
import java.util.ArrayList;
4
 
import java.util.List;
5
 
 
6
 
import org.eclipse.core.runtime.IProgressMonitor;
7
 
import org.eclipse.core.runtime.IStatus;
8
 
import org.eclipse.core.runtime.Status;
9
 
import org.eclipse.draw2d.IFigure;
10
 
import org.eclipse.draw2d.Label;
11
 
import org.eclipse.linuxtools.internal.callgraph.core.SystemTapParser;
12
 
import org.eclipse.linuxtools.internal.callgraph.core.SystemTapView;
13
 
import org.eclipse.swt.SWT;
14
 
import org.eclipse.swt.graphics.Color;
15
 
import org.eclipse.swt.widgets.Composite;
16
 
import org.eclipse.swt.widgets.Display;
17
 
import org.eclipse.zest.core.widgets.Graph;
18
 
import org.eclipse.zest.core.widgets.GraphConnection;
19
 
import org.eclipse.zest.core.widgets.GraphNode;
20
 
import org.eclipse.zest.core.widgets.ZestStyles;
21
 
import org.eclipse.zest.layouts.LayoutAlgorithm;
22
 
import org.eclipse.zest.layouts.LayoutStyles;
23
 
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
24
 
 
25
 
public class XMLGraphingView extends SystemTapView{
26
 
        private Graph graph;
27
 
        private ArrayList<GraphNode> nodes;
28
 
        GraphNode node1;
29
 
        public static final Color MARKED = new Color(Display.getCurrent(), 210, 112, 214);
30
 
        protected SleepingThreadsParser parser;
31
 
 
32
 
        
33
 
        @Override
34
 
        protected boolean createOpenAction() {
35
 
                return false;
36
 
        }
37
 
 
38
 
        @Override
39
 
        protected boolean createOpenDefaultAction() {
40
 
                return false;
41
 
        }
42
 
 
43
 
        @Override
44
 
        public IStatus initializeView(Display targetDisplay, IProgressMonitor monitor) {
45
 
                if (nodes != null) {
46
 
                        for (GraphNode n : nodes)
47
 
                                if (n != null) n.dispose();
48
 
                }
49
 
                nodes = new ArrayList<GraphNode>();
50
 
                return Status.OK_STATUS;
51
 
        }
52
 
 
53
 
 
54
 
        @Override
55
 
        public void setViewID() {
56
 
                viewID = "org.eclipse.linuxtools.sleepingthreads.xmlview";
57
 
        }
58
 
 
59
 
        @Override
60
 
        public boolean setParser(SystemTapParser p) {
61
 
                if (p instanceof SleepingThreadsParser) {
62
 
                        parser = (SleepingThreadsParser) p;
63
 
                        return true;
64
 
                }
65
 
                return false;
66
 
        }
67
 
        
68
 
        @Override
69
 
        public void updateMethod() {
70
 
                if (nodes == null)
71
 
                        nodes = new ArrayList<GraphNode>();
72
 
                if (parser.getData() instanceof List<?>) {
73
 
                        List<?> list = (List<?>) parser.getData();
74
 
                        if (list.size() == 0)
75
 
                                return;
76
 
                        if (list.get(0) instanceof XMLData) {
77
 
                                for (Object o : list) {
78
 
                                        if (o instanceof XMLData) {
79
 
                                                XMLData data = (XMLData) o;
80
 
                                                
81
 
                                                if (data.isNode()) {
82
 
                                                        
83
 
                                                        handleNode(data);
84
 
 
85
 
                                                } else {
86
 
                                                        int parent = data.getParent();
87
 
                                                        if (parent >= nodes.size())
88
 
                                                                continue;
89
 
                                                        GraphNode node = nodes.get(parent);
90
 
                                                        
91
 
                                                        handleData(node, data);
92
 
                                                }
93
 
                                                
94
 
                                        }
95
 
                                }
96
 
                        }
97
 
                }
98
 
                parser.setData(null);
99
 
                graph.applyLayout();
100
 
        }
101
 
        
102
 
        @Override
103
 
        public void createPartControl(Composite parent) {
104
 
                // Graph will hold all other objects
105
 
                graph = new Graph(parent, SWT.NONE);
106
 
                nodes = new ArrayList<GraphNode>();
107
 
                graph.setLayoutAlgorithm(getLayoutAlgorithm(), true);
108
 
                addKillButton();
109
 
                
110
 
        }
111
 
        
112
 
        /**
113
 
         * Overwrite to change the layout algorithm used. By default uses
114
 
         * SpringLayoutAlgorithm with no resizing.
115
 
         * @return
116
 
         */
117
 
        private LayoutAlgorithm getLayoutAlgorithm() {
118
 
                return new SpringLayoutAlgorithm(
119
 
                                LayoutStyles.NO_LAYOUT_NODE_RESIZING);
120
 
        }
121
 
 
122
 
        @Override
123
 
        public void setFocus() {
124
 
                // TODO Auto-generated method stub
125
 
                
126
 
        }
127
 
 
128
 
        @Override
129
 
        public SystemTapParser getParser() {
130
 
                return parser;
131
 
        }
132
 
        
133
 
        /**
134
 
         * Overwrite to process data differently. By default, this method will add data.getText()
135
 
         * to the current tooltip for the node. Will be called with the XMLData object being processed
136
 
         * as well as the node to which it belongs.
137
 
         * @param node
138
 
         * @param data
139
 
         */
140
 
        private void handleData(GraphNode node, XMLData data) {
141
 
                IFigure fig = node.getTooltip();
142
 
                String currText =  "";
143
 
                if (fig instanceof Label)
144
 
                        currText = ((Label) fig).getText();
145
 
                node.setTooltip(new Label( currText + "\n" + data.getText()));
146
 
                node.setBackgroundColor(MARKED);
147
 
        }
148
 
 
149
 
        
150
 
        /**
151
 
         * Overwrite to handle nodes differently. By default will create a node with name
152
 
         * data.getName() and connect it to its parent if its parent exists. Will also
153
 
         * add the node to the list of nodes.
154
 
         * @param data
155
 
         */
156
 
        private void handleNode(XMLData data) {
157
 
                int parent = data.getParent();
158
 
                GraphNode node = new GraphNode(graph, SWT.NONE, data.getName());
159
 
                
160
 
                if (parent < nodes.size() && parent >= 0)
161
 
                        new GraphConnection (graph, ZestStyles.CONNECTIONS_DASH, node, nodes.get(parent));
162
 
                nodes.add(node);
163
 
        }
164
 
}