|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Definitions for the class ChartContainer |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.s60tools.analyzetool.internal.ui.graph; |
|
19 |
|
20 import org.eclipse.core.resources.IProject; |
|
21 import org.eclipse.core.runtime.IProgressMonitor; |
|
22 import org.eclipse.core.runtime.IStatus; |
|
23 import org.eclipse.core.runtime.Status; |
|
24 import org.eclipse.draw2d.ColorConstants; |
|
25 import org.eclipse.swt.SWT; |
|
26 import org.eclipse.swt.events.ControlAdapter; |
|
27 import org.eclipse.swt.events.ControlEvent; |
|
28 import org.eclipse.swt.events.PaintEvent; |
|
29 import org.eclipse.swt.events.PaintListener; |
|
30 import org.eclipse.swt.events.SelectionEvent; |
|
31 import org.eclipse.swt.events.SelectionListener; |
|
32 import org.eclipse.swt.graphics.Color; |
|
33 import org.eclipse.swt.graphics.RGB; |
|
34 import org.eclipse.swt.layout.FormAttachment; |
|
35 import org.eclipse.swt.layout.FormData; |
|
36 import org.eclipse.swt.layout.FormLayout; |
|
37 import org.eclipse.swt.widgets.Combo; |
|
38 import org.eclipse.swt.widgets.Composite; |
|
39 import org.eclipse.swt.widgets.Display; |
|
40 import org.eclipse.swt.widgets.Label; |
|
41 import org.eclipse.swt.widgets.ToolBar; |
|
42 import org.eclipse.swt.widgets.ToolItem; |
|
43 import org.eclipse.ui.PartInitException; |
|
44 import org.eclipse.ui.PlatformUI; |
|
45 import org.eclipse.ui.progress.UIJob; |
|
46 |
|
47 import com.nokia.s60tools.analyzetool.Activator; |
|
48 import com.nokia.s60tools.analyzetool.AnalyzeToolHelpContextIDs; |
|
49 import com.nokia.s60tools.analyzetool.engine.IMemoryActivityModel; |
|
50 import com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener; |
|
51 import com.nokia.s60tools.analyzetool.engine.statistic.ProcessInfo; |
|
52 |
|
53 /** |
|
54 * Container for the complete AnalyzeTool chart (x and y axis as well as graph) |
|
55 * |
|
56 */ |
|
57 public class ChartContainer extends Composite implements IMemoryActivityModelChangeListener{ |
|
58 |
|
59 private static final String ICON_PROPVIEW = "icons/properties.gif";//$NON-NLS-1$ |
|
60 private static final String ICON_HELP = "icons/linkto_help.gif";//$NON-NLS-1$ |
|
61 |
|
62 private AnalyzeToolGraph graphCanvas; |
|
63 private YAxis yAxis; |
|
64 private Combo processCombo; |
|
65 private IMemoryActivityModel model; |
|
66 private UIJob iRefreshUIJob; |
|
67 |
|
68 /** |
|
69 * Constructor |
|
70 * |
|
71 * @param parent |
|
72 * a widget which will be the parent of the new instance (cannot |
|
73 * be null) |
|
74 * @param style |
|
75 * the style of widget to construct |
|
76 */ |
|
77 public ChartContainer(Composite parent, int style) { |
|
78 super(parent, SWT.NONE); |
|
79 setBackground(parent.getBackground()); |
|
80 constructChartArea(); |
|
81 } |
|
82 |
|
83 /** |
|
84 * Builds up the main composite when opening for the first time |
|
85 */ |
|
86 private void constructChartArea(){ |
|
87 setLayout(new FormLayout()); |
|
88 |
|
89 Label processLabel = new Label(this, SWT.CENTER); |
|
90 processLabel.setText("Process:"); |
|
91 processCombo = new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); |
|
92 |
|
93 |
|
94 ToolBar toolBar = new ToolBar (this, SWT.RIGHT | SWT.FLAT); |
|
95 |
|
96 //toolbar button to open the Eclipse Properties view |
|
97 ToolItem propViewItem = new ToolItem (toolBar, SWT.PUSH | SWT.FLAT ); |
|
98 propViewItem.addSelectionListener(new SelectionListener(){ |
|
99 |
|
100 public void widgetDefaultSelected(SelectionEvent e) { |
|
101 } |
|
102 |
|
103 public void widgetSelected(SelectionEvent e) { |
|
104 try { |
|
105 PlatformUI.getWorkbench() |
|
106 .getActiveWorkbenchWindow().getActivePage() |
|
107 .showView("org.eclipse.ui.views.PropertySheet");//$NON-NLS-1$ |
|
108 } catch (PartInitException ex) { |
|
109 Activator.getDefault().log(IStatus.ERROR, ex.getMessage(), ex); |
|
110 } |
|
111 } |
|
112 |
|
113 }); |
|
114 propViewItem.setImage(Activator.getDefault().getImage(ICON_PROPVIEW)); |
|
115 propViewItem.setToolTipText("Show Properties View"); |
|
116 |
|
117 //toolbar button to show some navigation help and open the F1 help |
|
118 ToolItem helpItem = new ToolItem (toolBar, SWT.PUSH | SWT.FLAT ); |
|
119 helpItem.addSelectionListener(new SelectionListener(){ |
|
120 |
|
121 public void widgetDefaultSelected(SelectionEvent e) { |
|
122 } |
|
123 |
|
124 public void widgetSelected(SelectionEvent e) { |
|
125 PlatformUI.getWorkbench().getHelpSystem().displayHelp(AnalyzeToolHelpContextIDs.ANALYZE_GRAPH); |
|
126 } |
|
127 |
|
128 }); |
|
129 helpItem.setImage(Activator.getDefault().getImage(ICON_HELP)); |
|
130 helpItem.setToolTipText("Quick navigtion help\n-------------------------\nZoom in: select a region of the graph (mouse left-click and drag).\nZoom out: mouse right-click.\n\nSelect memory operation: mouse left-click in the graph.\nMove selection to next or previous using arrow left and arrow right keys.\n\nFor more help press F1"); |
|
131 |
|
132 yAxis = new YAxis(this); |
|
133 yAxis.createContent(); |
|
134 graphCanvas = new AnalyzeToolGraph(this); |
|
135 graphCanvas.setSize(500, 450); |
|
136 |
|
137 FormData formData = new FormData(); |
|
138 formData.top = new FormAttachment(0,2); |
|
139 formData.left = new FormAttachment(0, 2); |
|
140 formData.height = processCombo.getBounds().height; |
|
141 processLabel.setLayoutData(formData); |
|
142 |
|
143 formData = new FormData(); |
|
144 formData.top = new FormAttachment(0); |
|
145 formData.left = new FormAttachment(processLabel, 10, SWT.BOTTOM); |
|
146 processCombo.setLayoutData(formData); |
|
147 |
|
148 formData = new FormData(); |
|
149 formData.top = new FormAttachment(0, 2); |
|
150 formData.right = new FormAttachment(100, 2); |
|
151 toolBar.setLayoutData(formData); |
|
152 |
|
153 formData = new FormData(); |
|
154 formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM); |
|
155 formData.bottom = new FormAttachment(100); |
|
156 formData.left = new FormAttachment(0); |
|
157 formData.width = 60; |
|
158 yAxis.setLayoutData(formData); |
|
159 |
|
160 formData = new FormData(); |
|
161 formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM); |
|
162 formData.bottom = new FormAttachment(100); |
|
163 formData.left = new FormAttachment(yAxis, 0, SWT.RIGHT); |
|
164 formData.right = new FormAttachment(100); |
|
165 graphCanvas.setLayoutData(formData); |
|
166 |
|
167 yAxis.setBackground(ColorConstants.white); |
|
168 yAxis.addPaintListener(new PaintListener() |
|
169 { |
|
170 |
|
171 public void paintControl(PaintEvent event) { |
|
172 |
|
173 if(yAxis != null) |
|
174 yAxis.paintYAxis(event.gc); |
|
175 } |
|
176 }); |
|
177 |
|
178 graphCanvas.setBackground(new Color(Display.getDefault(), new RGB(255,255,255))); |
|
179 graphCanvas.createContent(); |
|
180 graphCanvas.addControlListener(new ControlAdapter() { |
|
181 public void controlResized(ControlEvent e) { |
|
182 //the client area of the graph panel might change if a scrollbar gets added/removed |
|
183 //this needs to be passed on to the y axis |
|
184 if (yAxis.getHeight() != graphCanvas.getClientArea().height){ |
|
185 yAxis.setHeight(graphCanvas.getClientArea().height); |
|
186 yAxis.redraw(); |
|
187 } |
|
188 } |
|
189 |
|
190 }); |
|
191 |
|
192 iRefreshUIJob = new UIJob("Updating process combo box"){ |
|
193 |
|
194 @Override |
|
195 public IStatus runInUIThread(IProgressMonitor arg0) { |
|
196 processCombo.removeAll(); |
|
197 // Update combo box |
|
198 if (model.getProcesses().size() == 0){ |
|
199 processCombo.add("No data available"); |
|
200 processCombo.select(0); |
|
201 } else { |
|
202 for (ProcessInfo p : model.getProcesses()) { |
|
203 processCombo.add(String.format("%s with %d leak(s)",p.getProcessName() != null ? p.getProcessName() : p.getProcessID(), p.getMemLeaksNumber())); |
|
204 } |
|
205 processCombo.setVisibleItemCount(10); |
|
206 } |
|
207 processCombo.pack(); |
|
208 return Status.OK_STATUS; |
|
209 } |
|
210 |
|
211 }; |
|
212 iRefreshUIJob.setSystem(true); |
|
213 |
|
214 processCombo.addSelectionListener(new SelectionListener(){ |
|
215 |
|
216 public void widgetDefaultSelected(SelectionEvent e) {} |
|
217 |
|
218 public void widgetSelected(SelectionEvent e) { |
|
219 int sel = processCombo.getSelectionIndex(); |
|
220 if (model.getProcesses().size()>sel){ |
|
221 ProcessInfo process = model.getProcesses().get(processCombo.getSelectionIndex()); |
|
222 model.setSelectedProcess(process); |
|
223 processCombo.setSize(processCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
|
224 } |
|
225 } |
|
226 |
|
227 }); |
|
228 |
|
229 |
|
230 layout(); |
|
231 PlatformUI.getWorkbench().getHelpSystem().setHelp( |
|
232 this, |
|
233 AnalyzeToolHelpContextIDs.ANALYZE_GRAPH); |
|
234 } |
|
235 |
|
236 /** |
|
237 * Sets a new model. Note the redraw of the new content only happens on |
|
238 * callbacks to model change listeners. |
|
239 * @param aProject The currently selected project in the IDE, used for pinpointing |
|
240 * |
|
241 * @param model the new IMemoryActivityModel to set |
|
242 */ |
|
243 public void setInput(IProject aProject, IMemoryActivityModel model) { |
|
244 if (this.model != null){ |
|
245 this.model.removeListener(this); |
|
246 } |
|
247 this.model = model; |
|
248 this.model.addListener(this); |
|
249 |
|
250 graphCanvas.setInput(model); |
|
251 yAxis.setInput(model); |
|
252 if (aProject != null) { |
|
253 graphCanvas.setProject(aProject); |
|
254 } |
|
255 } |
|
256 |
|
257 /* (non-Javadoc) |
|
258 * @see com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener#onProcessSelected(com.nokia.s60tools.analyzetool.engine.statistic.ProcessInfo) |
|
259 */ |
|
260 public void onProcessSelected(ProcessInfo p) { |
|
261 } |
|
262 |
|
263 /* (non-Javadoc) |
|
264 * @see com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener#onProcessesAdded() |
|
265 */ |
|
266 public void onProcessesAdded() { |
|
267 iRefreshUIJob.cancel(); |
|
268 iRefreshUIJob.schedule(); |
|
269 |
|
270 } |
|
271 |
|
272 public void update(){ |
|
273 graphCanvas.zoomGraph(); |
|
274 graphCanvas.redraw(); |
|
275 yAxis.redraw(); |
|
276 } |
|
277 } |