77 public ChartContainer(Composite parent, int style) { |
86 public ChartContainer(Composite parent, int style) { |
78 super(parent, SWT.NONE); |
87 super(parent, SWT.NONE); |
79 setBackground(parent.getBackground()); |
88 setBackground(parent.getBackground()); |
80 constructChartArea(); |
89 constructChartArea(); |
81 } |
90 } |
82 |
91 |
83 /** |
92 /** |
84 * Builds up the main composite when opening for the first time |
93 * Builds up the main composite when opening for the first time |
85 */ |
94 */ |
86 private void constructChartArea(){ |
95 private void constructChartArea() { |
87 setLayout(new FormLayout()); |
96 setLayout(new FormLayout()); |
88 |
97 |
89 Label processLabel = new Label(this, SWT.CENTER); |
98 Label processLabel = new Label(this, SWT.CENTER); |
90 processLabel.setText("Process:"); |
99 processLabel.setText("Process:"); |
91 processCombo = new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); |
100 processCombo = new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); |
92 |
101 |
93 |
102 ToolBar toolBar = new ToolBar(this, SWT.RIGHT | SWT.FLAT); |
94 ToolBar toolBar = new ToolBar (this, SWT.RIGHT | SWT.FLAT); |
103 |
95 |
104 settingsButton = new ToolItem(toolBar, SWT.PUSH | SWT.FLAT); |
96 //toolbar button to open the Eclipse Properties view |
105 settingsButton.addSelectionListener(new SelectionListener() { |
97 ToolItem propViewItem = new ToolItem (toolBar, SWT.PUSH | SWT.FLAT ); |
|
98 propViewItem.addSelectionListener(new SelectionListener(){ |
|
99 |
106 |
100 public void widgetDefaultSelected(SelectionEvent e) { |
107 public void widgetDefaultSelected(SelectionEvent e) { |
101 //do nothing by design |
108 // do nothing by design |
102 } |
109 } |
103 |
110 |
104 public void widgetSelected(SelectionEvent e) { |
111 public void widgetSelected(SelectionEvent e) { |
105 try { |
112 // SettingsInputDialog dialog = new |
106 PlatformUI.getWorkbench() |
113 // SettingsInputDialog(thresholdVal, getShell()); |
107 .getActiveWorkbenchWindow().getActivePage() |
114 GraphSettingsDialog dialog = new GraphSettingsDialog( |
108 .showView("org.eclipse.ui.views.PropertySheet");//$NON-NLS-1$ |
115 getShell(), thresholdVal, thresholdAbove); |
109 } catch (PartInitException ex) { |
116 if (dialog.open() == Window.OK) { |
110 Activator.getDefault().log(IStatus.ERROR, ex.getMessage(), ex); |
117 thresholdVal = dialog.getThresholdString(); |
111 } |
118 thresholdAbove = dialog.getAbove(); |
112 } |
119 graphCanvas.setThreshold(dialog.getThreshold(), |
113 |
120 thresholdAbove); |
|
121 graphCanvas.redraw(); |
|
122 } |
|
123 } |
|
124 }); |
|
125 settingsButton.setImage(Activator.getDefault().getImage( |
|
126 ICON_GRAPH_SETTINGS)); |
|
127 settingsButton.setToolTipText("Graph Settings"); |
|
128 thresholdAbove = true; // initial value |
|
129 |
|
130 // toolbar button to open the Eclipse Properties view |
|
131 ToolItem propViewItem = new ToolItem(toolBar, SWT.PUSH | SWT.FLAT); |
|
132 propViewItem.addSelectionListener(new SelectionListener() { |
|
133 |
|
134 public void widgetDefaultSelected(SelectionEvent e) { |
|
135 // do nothing by design |
|
136 } |
|
137 |
|
138 public void widgetSelected(SelectionEvent e) { |
|
139 try { |
|
140 PlatformUI.getWorkbench().getActiveWorkbenchWindow() |
|
141 .getActivePage().showView( |
|
142 "org.eclipse.ui.views.PropertySheet");//$NON-NLS-1$ |
|
143 } catch (PartInitException ex) { |
|
144 Activator.getDefault().log(IStatus.ERROR, ex.getMessage(), |
|
145 ex); |
|
146 } |
|
147 } |
|
148 |
114 }); |
149 }); |
115 propViewItem.setImage(Activator.getDefault().getImage(ICON_PROPVIEW)); |
150 propViewItem.setImage(Activator.getDefault().getImage(ICON_PROPVIEW)); |
116 propViewItem.setToolTipText("Show Properties View"); |
151 propViewItem.setToolTipText("Show Properties View"); |
117 |
152 |
118 //toolbar button to show some navigation help and open the F1 help |
153 // toolbar button to show some navigation help and open the F1 help |
119 ToolItem helpItem = new ToolItem (toolBar, SWT.PUSH | SWT.FLAT ); |
154 ToolItem helpItem = new ToolItem(toolBar, SWT.PUSH | SWT.FLAT); |
120 helpItem.addSelectionListener(new SelectionListener(){ |
155 helpItem.addSelectionListener(new SelectionListener() { |
121 |
156 |
122 public void widgetDefaultSelected(SelectionEvent e) { |
157 public void widgetDefaultSelected(SelectionEvent e) { |
123 //do nothing by design |
158 // do nothing by design |
124 } |
159 } |
125 |
160 |
126 public void widgetSelected(SelectionEvent e) { |
161 public void widgetSelected(SelectionEvent e) { |
127 PlatformUI.getWorkbench().getHelpSystem().displayHelp(AnalyzeToolHelpContextIDs.ANALYZE_GRAPH); |
162 PlatformUI.getWorkbench().getHelpSystem().displayHelp( |
128 } |
163 AnalyzeToolHelpContextIDs.ANALYZE_GRAPH); |
129 |
164 } |
|
165 |
130 }); |
166 }); |
131 helpItem.setImage(Activator.getDefault().getImage(ICON_HELP)); |
167 helpItem.setImage(Activator.getDefault().getImage(ICON_HELP)); |
132 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"); |
168 helpItem |
133 |
169 .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"); |
|
170 |
134 yAxis = new YAxis(this); |
171 yAxis = new YAxis(this); |
135 yAxis.createContent(); |
172 yAxis.createContent(); |
136 graphCanvas = new AnalyzeToolGraph(this); |
173 graphCanvas = new AnalyzeToolGraph(this); |
137 graphCanvas.setSize(500, 450); |
174 graphCanvas.setSize(500, 450); |
138 |
175 |
139 FormData formData = new FormData(); |
176 FormData formData = new FormData(); |
140 formData.top = new FormAttachment(0,2); |
177 formData.top = new FormAttachment(0, 2); |
141 formData.left = new FormAttachment(0, 2); |
178 formData.left = new FormAttachment(0, 2); |
142 formData.height = processCombo.getBounds().height; |
179 formData.height = processCombo.getBounds().height; |
143 processLabel.setLayoutData(formData); |
180 processLabel.setLayoutData(formData); |
144 |
181 |
145 formData = new FormData(); |
182 formData = new FormData(); |
146 formData.top = new FormAttachment(0); |
183 formData.top = new FormAttachment(0); |
147 formData.left = new FormAttachment(processLabel, 10, SWT.BOTTOM); |
184 formData.left = new FormAttachment(processLabel, 10, SWT.BOTTOM); |
148 processCombo.setLayoutData(formData); |
185 processCombo.setLayoutData(formData); |
149 |
186 |
150 formData = new FormData(); |
187 formData = new FormData(); |
151 formData.top = new FormAttachment(0, 2); |
188 formData.top = new FormAttachment(0, 2); |
152 formData.right = new FormAttachment(100, 2); |
189 formData.right = new FormAttachment(100, 2); |
153 toolBar.setLayoutData(formData); |
190 toolBar.setLayoutData(formData); |
154 |
191 |
155 formData = new FormData(); |
192 formData = new FormData(); |
156 formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM); |
193 formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM); |
157 formData.bottom = new FormAttachment(100); |
194 formData.bottom = new FormAttachment(100); |
158 formData.left = new FormAttachment(0); |
195 formData.left = new FormAttachment(0); |
159 formData.width = 60; |
196 formData.width = 60; |
160 yAxis.setLayoutData(formData); |
197 yAxis.setLayoutData(formData); |
161 |
198 |
162 formData = new FormData(); |
199 formData = new FormData(); |
163 formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM); |
200 formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM); |
164 formData.bottom = new FormAttachment(100); |
201 formData.bottom = new FormAttachment(100); |
165 formData.left = new FormAttachment(yAxis, 0, SWT.RIGHT); |
202 formData.left = new FormAttachment(yAxis, 0, SWT.RIGHT); |
166 formData.right = new FormAttachment(100); |
203 formData.right = new FormAttachment(100); |
167 graphCanvas.setLayoutData(formData); |
204 graphCanvas.setLayoutData(formData); |
168 |
205 |
169 yAxis.setBackground(ColorConstants.white); |
206 yAxis.setBackground(ColorConstants.white); |
170 yAxis.addPaintListener(new PaintListener() |
207 yAxis.addPaintListener(new PaintListener() { |
171 { |
|
172 |
208 |
173 public void paintControl(PaintEvent event) { |
209 public void paintControl(PaintEvent event) { |
174 |
210 |
175 if(yAxis != null) |
211 if (yAxis != null) |
176 yAxis.paintYAxis(event.gc); |
212 yAxis.paintYAxis(event.gc); |
177 } |
213 } |
178 }); |
214 }); |
179 |
215 |
180 graphCanvas.setBackground(new Color(Display.getDefault(), new RGB(255,255,255))); |
216 graphCanvas.setBackground(new Color(Display.getDefault(), new RGB(255, |
|
217 255, 255))); |
181 graphCanvas.createContent(); |
218 graphCanvas.createContent(); |
182 graphCanvas.addControlListener(new ControlAdapter() { |
219 graphCanvas.addControlListener(new ControlAdapter() { |
183 @Override |
220 @Override |
184 public void controlResized(ControlEvent e) { |
221 public void controlResized(ControlEvent e) { |
185 //the client area of the graph panel might change if a scrollbar gets added/removed |
222 // the client area of the graph panel might change if a |
186 //this needs to be passed on to the y axis |
223 // scrollbar gets added/removed |
187 if (yAxis.getHeight() != graphCanvas.getClientArea().height){ |
224 // this needs to be passed on to the y axis |
|
225 if (yAxis.getHeight() != graphCanvas.getClientArea().height) { |
188 yAxis.setHeight(graphCanvas.getClientArea().height); |
226 yAxis.setHeight(graphCanvas.getClientArea().height); |
189 yAxis.redraw(); |
227 yAxis.redraw(); |
190 } |
228 } |
191 } |
229 } |
192 |
230 |
193 }); |
231 }); |
194 |
232 |
195 iRefreshUIJob = new UIJob("Updating process combo box"){ |
233 iRefreshUIJob = new UIJob("Updating process combo box") { |
196 |
234 |
197 @Override |
235 @Override |
198 public IStatus runInUIThread(IProgressMonitor arg0) { |
236 public IStatus runInUIThread(IProgressMonitor arg0) { |
199 processCombo.removeAll(); |
237 processCombo.removeAll(); |
200 // Update combo box |
238 // Update combo box |
201 if (model.getProcesses().size() == 0){ |
239 if (model.getProcesses().size() == 0) { |
202 processCombo.add("No data available"); |
240 processCombo.add("No data available"); |
203 processCombo.select(0); |
241 processCombo.select(0); |
|
242 settingsButton.setEnabled(false); |
204 } else { |
243 } else { |
205 for (ProcessInfo p : model.getProcesses()) { |
244 for (ProcessInfo p : model.getProcesses()) { |
206 processCombo.add(String.format("%s with %d leak(s)",p.getProcessName() != null ? p.getProcessName() : p.getProcessID(), p.getMemLeaksNumber())); |
245 processCombo.add(String.format("%s with %d leak(s)", p |
|
246 .getProcessName() != null ? p.getProcessName() |
|
247 : p.getProcessID(), p.getMemLeaksNumber())); |
207 } |
248 } |
208 processCombo.setVisibleItemCount(10); |
249 processCombo.setVisibleItemCount(10); |
209 } |
250 } |
210 processCombo.pack(); |
251 processCombo.pack(); |
211 return Status.OK_STATUS; |
252 return Status.OK_STATUS; |
212 } |
253 } |
213 |
254 |
214 }; |
255 }; |
215 iRefreshUIJob.setSystem(true); |
256 iRefreshUIJob.setSystem(true); |
216 |
257 |
217 processCombo.addSelectionListener(new SelectionListener(){ |
258 processCombo.addSelectionListener(new SelectionListener() { |
218 |
259 |
219 public void widgetDefaultSelected(SelectionEvent e) { |
260 public void widgetDefaultSelected(SelectionEvent e) { |
220 //do nothing by design |
261 // do nothing by design |
221 } |
262 } |
222 |
263 |
223 public void widgetSelected(SelectionEvent e) { |
264 public void widgetSelected(SelectionEvent e) { |
224 int sel = processCombo.getSelectionIndex(); |
265 int sel = processCombo.getSelectionIndex(); |
225 if (model.getProcesses().size()>sel){ |
266 if (model.getProcesses().size() > sel) { |
226 ProcessInfo process = model.getProcesses().get(processCombo.getSelectionIndex()); |
267 ProcessInfo process = model.getProcesses().get( |
|
268 processCombo.getSelectionIndex()); |
227 model.setSelectedProcess(process); |
269 model.setSelectedProcess(process); |
228 processCombo.setSize(processCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
270 processCombo.setSize(processCombo.computeSize(SWT.DEFAULT, |
229 } |
271 SWT.DEFAULT)); |
230 } |
272 int ops = model.getSelectedProcess().getAllocsFrees() |
231 |
273 .size(); |
232 }); |
274 settingsButton.setEnabled(ops > 0 |
233 |
275 && ops <= OPT_DRAWING_LIMIT ? true : false); |
234 |
276 } |
|
277 } |
|
278 }); |
|
279 |
235 layout(); |
280 layout(); |
236 PlatformUI.getWorkbench().getHelpSystem().setHelp( |
281 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, |
237 this, |
|
238 AnalyzeToolHelpContextIDs.ANALYZE_GRAPH); |
282 AnalyzeToolHelpContextIDs.ANALYZE_GRAPH); |
239 } |
283 } |
240 |
284 |
241 /** |
285 /** |
242 * Sets a new model. Note the redraw of the new content only happens on |
286 * Sets a new model. Note the redraw of the new content only happens on |
243 * callbacks to model change listeners. |
287 * callbacks to model change listeners. |
244 * @param aProject The currently selected project in the IDE, used for pinpointing |
288 * |
245 * |
289 * @param aProject |
246 * @param newModel the new IMemoryActivityModel to set |
290 * The currently selected project in the IDE, used for |
|
291 * pinpointing |
|
292 * |
|
293 * @param newModel |
|
294 * the new IMemoryActivityModel to set |
247 */ |
295 */ |
248 public void setInput(IProject aProject, IMemoryActivityModel newModel) { |
296 public void setInput(IProject aProject, IMemoryActivityModel newModel) { |
249 if (this.model != null){ |
297 if (this.model != null) { |
250 this.model.removeListener(this); |
298 this.model.removeListener(this); |
251 } |
299 } |
252 this.model = newModel; |
300 this.model = newModel; |
253 this.model.addListener(this); |
301 this.model.addListener(this); |
254 |
302 |