|
1 /* |
|
2 * Copyright (c) 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 * |
|
20 */ |
|
21 package com.nokia.carbide.cpp.internal.pi.actions; |
|
22 |
|
23 import java.text.DecimalFormat; |
|
24 import java.util.Enumeration; |
|
25 |
|
26 import org.eclipse.swt.SWT; |
|
27 import org.eclipse.swt.events.FocusAdapter; |
|
28 import org.eclipse.swt.events.FocusEvent; |
|
29 import org.eclipse.swt.events.SelectionAdapter; |
|
30 import org.eclipse.swt.events.SelectionEvent; |
|
31 import org.eclipse.swt.events.SelectionListener; |
|
32 import org.eclipse.swt.layout.FillLayout; |
|
33 import org.eclipse.swt.layout.GridData; |
|
34 import org.eclipse.swt.layout.GridLayout; |
|
35 import org.eclipse.swt.widgets.Button; |
|
36 import org.eclipse.swt.widgets.Display; |
|
37 import org.eclipse.swt.widgets.Event; |
|
38 import org.eclipse.swt.widgets.Group; |
|
39 import org.eclipse.swt.widgets.Label; |
|
40 import org.eclipse.swt.widgets.Shell; |
|
41 import org.eclipse.swt.widgets.Text; |
|
42 |
|
43 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository; |
|
44 import com.nokia.carbide.cpp.internal.pi.analyser.PIChangeEvent; |
|
45 import com.nokia.carbide.cpp.internal.pi.manager.PluginInitialiser; |
|
46 import com.nokia.carbide.cpp.internal.pi.plugin.model.IEventListener; |
|
47 import com.nokia.carbide.cpp.pi.editors.PIPageEditor; |
|
48 |
|
49 |
|
50 public class SetThresholdsDialog { |
|
51 |
|
52 private Shell shell; |
|
53 |
|
54 private Group threadGroup; |
|
55 private Label threadLoadLabel; |
|
56 private Label threadCountLabel; |
|
57 private Text threadLoadText; |
|
58 private Text threadCountText; |
|
59 |
|
60 private Button button; |
|
61 |
|
62 private Group binaryGroup; |
|
63 private Label binaryLoadLabel; |
|
64 private Label binaryCountLabel; |
|
65 private Text binaryLoadText; |
|
66 private Text binaryCountText; |
|
67 |
|
68 private Group functionGroup; |
|
69 private Label functionLoadLabel; |
|
70 private Label functionCountLabel; |
|
71 private Text functionLoadText; |
|
72 private Text functionCountText; |
|
73 |
|
74 private Button ok; |
|
75 private Button cancel; |
|
76 private GridData gridData; |
|
77 private DecimalFormat timeFormat = new DecimalFormat(Messages.getString("SetThresholdsDialog.decimalFormat")); //$NON-NLS-1$ |
|
78 |
|
79 private double thresholdLoadThread; |
|
80 private double thresholdLoadBinary; |
|
81 private double thresholdLoadFunction; |
|
82 private int thresholdCountThread; |
|
83 private int thresholdCountBinary; |
|
84 private int thresholdCountFunction; |
|
85 |
|
86 public SetThresholdsDialog(Display display) |
|
87 { |
|
88 thresholdLoadThread = (Double) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdLoadThread"); //$NON-NLS-1$ |
|
89 thresholdLoadBinary = (Double) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdLoadBinary"); //$NON-NLS-1$ |
|
90 thresholdLoadFunction = (Double) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdLoadFunction"); //$NON-NLS-1$ |
|
91 thresholdCountThread = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountThread"); //$NON-NLS-1$ |
|
92 thresholdCountBinary = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountBinary"); //$NON-NLS-1$ |
|
93 thresholdCountFunction = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountFunction"); //$NON-NLS-1$ |
|
94 |
|
95 shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); |
|
96 shell.setText(Messages.getString("SetThresholdsDialog.thresholdTitle")); //$NON-NLS-1$ |
|
97 shell.setLayout(new GridLayout(4, false)); |
|
98 |
|
99 // thread threshold |
|
100 threadGroup = new Group(shell, SWT.NONE); |
|
101 threadGroup.setText(Messages.getString("SetThresholdsDialog.threadThreshold")); //$NON-NLS-1$ |
|
102 threadGroup.setFont(PIPageEditor.helvetica_10); |
|
103 gridData = new GridData(SWT.FILL, SWT.CENTER, true, true); |
|
104 gridData.horizontalSpan = 4; |
|
105 threadGroup.setLayoutData(gridData); |
|
106 threadGroup.setLayout(new FillLayout()); |
|
107 |
|
108 threadLoadLabel = new Label(threadGroup, SWT.RIGHT); |
|
109 threadLoadLabel.setText(Messages.getString("SetThresholdsDialog.averageLoad")); //$NON-NLS-1$ |
|
110 threadLoadLabel.setFont(PIPageEditor.helvetica_9); |
|
111 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
112 gridData.horizontalSpan = 1; |
|
113 |
|
114 threadLoadText = new Text(threadGroup, SWT.BORDER | SWT.RIGHT); |
|
115 threadLoadText.setFont(PIPageEditor.helvetica_9); |
|
116 threadLoadText.setData(Messages.getString("SetThresholdsDialog.minimumPercent")); //$NON-NLS-1$ |
|
117 threadLoadText.setText(timeFormat.format(thresholdLoadThread * 100.0)); |
|
118 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
119 gridData.horizontalSpan = 1; |
|
120 |
|
121 threadCountLabel = new Label(threadGroup, SWT.LEFT); |
|
122 threadCountLabel.setText(Messages.getString("SetThresholdsDialog.totalSamples")); //$NON-NLS-1$ |
|
123 threadCountLabel.setFont(PIPageEditor.helvetica_9); |
|
124 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
125 gridData.horizontalSpan = 1; |
|
126 |
|
127 threadCountText = new Text(threadGroup, SWT.BORDER | SWT.RIGHT); |
|
128 threadCountText.setFont(PIPageEditor.helvetica_9); |
|
129 threadCountText.setData(Messages.getString("SetThresholdsDialog.minimumSamples")); //$NON-NLS-1$ |
|
130 threadCountText.setText("" + thresholdCountThread); //$NON-NLS-1$ |
|
131 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
132 gridData.horizontalSpan = 1; |
|
133 |
|
134 // add the thread listeners |
|
135 threadLoadText.addFocusListener(new FocusAdapter() { |
|
136 public void focusLost(FocusEvent e) { |
|
137 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
138 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
139 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
140 thresholdLoadThread = convert(threadLoadText, thresholdLoadThread, 0, 100, timeFormat) / 100.0; |
|
141 thresholdCountThread = (int) ((totalSampleCount / samplingInterval) * thresholdLoadThread + 0.5); |
|
142 threadLoadText.setText(timeFormat.format(thresholdLoadThread * 100.0)); |
|
143 threadCountText.setText("" + thresholdCountThread); //$NON-NLS-1$ |
|
144 |
|
145 Boolean useOnlyThreadThresholds = (Boolean) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.useOnlyThreadThresholds"); //$NON-NLS-1$ |
|
146 if (useOnlyThreadThresholds) { |
|
147 copyThreadThresholds(); |
|
148 } |
|
149 } |
|
150 }); |
|
151 |
|
152 threadLoadText.addSelectionListener(new SelectionAdapter() { |
|
153 public void widgetDefaultSelected(SelectionEvent e) { |
|
154 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
155 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
156 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
157 thresholdLoadThread = convert(threadLoadText, thresholdLoadThread, 0, 100, timeFormat) / 100.0; |
|
158 thresholdCountThread = (int) ((totalSampleCount / samplingInterval) * thresholdLoadThread + 0.5); |
|
159 threadLoadText.setText(timeFormat.format(thresholdLoadThread * 100.0)); |
|
160 threadCountText.setText("" + thresholdCountThread); //$NON-NLS-1$ |
|
161 |
|
162 Boolean useOnlyThreadThresholds = (Boolean) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.useOnlyThreadThresholds"); //$NON-NLS-1$ |
|
163 if (useOnlyThreadThresholds) { |
|
164 copyThreadThresholds(); |
|
165 } |
|
166 } |
|
167 }); |
|
168 |
|
169 threadCountText.addFocusListener(new FocusAdapter() { |
|
170 public void focusLost(FocusEvent e) { |
|
171 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
172 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
173 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
174 thresholdCountThread = convert(threadCountText, thresholdCountThread, 0, totalSampleCount / samplingInterval); |
|
175 thresholdLoadThread = ((double)thresholdCountThread * samplingInterval) / ((double)totalSampleCount); |
|
176 threadLoadText.setText(timeFormat.format(thresholdLoadThread * 100.0)); |
|
177 threadCountText.setText("" + thresholdCountThread); //$NON-NLS-1$ |
|
178 |
|
179 Boolean useOnlyThreadThresholds = (Boolean) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.useOnlyThreadThresholds"); //$NON-NLS-1$ |
|
180 if (useOnlyThreadThresholds) { |
|
181 copyThreadThresholds(); |
|
182 } |
|
183 } |
|
184 }); |
|
185 |
|
186 threadCountText.addSelectionListener(new SelectionAdapter() { |
|
187 public void widgetDefaultSelected(SelectionEvent e) { |
|
188 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
189 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
190 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
191 thresholdCountThread = convert(threadCountText, thresholdCountThread, 0, totalSampleCount / samplingInterval); |
|
192 thresholdLoadThread = ((double)thresholdCountThread * samplingInterval) / ((double)totalSampleCount); |
|
193 threadLoadText.setText(timeFormat.format(thresholdLoadThread * 100.0)); |
|
194 threadCountText.setText("" + thresholdCountThread); //$NON-NLS-1$ |
|
195 |
|
196 Boolean useOnlyThreadThresholds = (Boolean) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.useOnlyThreadThresholds"); //$NON-NLS-1$ |
|
197 if (useOnlyThreadThresholds) { |
|
198 copyThreadThresholds(); |
|
199 } |
|
200 } |
|
201 }); |
|
202 |
|
203 threadGroup.pack(); |
|
204 |
|
205 button = new Button(shell, SWT.LEFT | SWT.CHECK); |
|
206 button.setText(Messages.getString("SetThresholdsDialog.useThreadForAll")); //$NON-NLS-1$ |
|
207 button.setFont(PIPageEditor.helvetica_8); |
|
208 button.setSelection((Boolean) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.useOnlyThreadThresholds")); //$NON-NLS-1$ |
|
209 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
210 gridData.horizontalSpan = 10; |
|
211 button.setLayoutData(gridData); |
|
212 |
|
213 // add the button listeners |
|
214 button.addSelectionListener(new SelectionListener() { |
|
215 public void widgetDefaultSelected(SelectionEvent e) { |
|
216 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.address.useOnlyThreadThresholds", button.getSelection()); //$NON-NLS-1$ |
|
217 Boolean useOnlyThreadThresholds = (Boolean) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.useOnlyThreadThresholds"); //$NON-NLS-1$ |
|
218 |
|
219 if (useOnlyThreadThresholds) { |
|
220 // disable the other numbers |
|
221 binaryLoadText.setEnabled(false); |
|
222 binaryCountText.setEnabled(false); |
|
223 functionLoadText.setEnabled(false); |
|
224 functionCountText.setEnabled(false); |
|
225 copyThreadThresholds(); |
|
226 } else { |
|
227 binaryLoadText.setEnabled(true); |
|
228 binaryCountText.setEnabled(true); |
|
229 functionLoadText.setEnabled(true); |
|
230 functionCountText.setEnabled(true); |
|
231 } |
|
232 } |
|
233 |
|
234 public void widgetSelected(SelectionEvent e) { |
|
235 widgetDefaultSelected(e); |
|
236 } |
|
237 }); |
|
238 |
|
239 // binary threshold |
|
240 binaryGroup = new Group(shell, SWT.LEFT); |
|
241 binaryGroup.setText(Messages.getString("SetThresholdsDialog.binaryThreshold")); //$NON-NLS-1$ |
|
242 binaryGroup.setFont(PIPageEditor.helvetica_10); |
|
243 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
244 gridData.horizontalSpan = 4; |
|
245 binaryGroup.setLayoutData(gridData); |
|
246 binaryGroup.setLayout(new FillLayout()); |
|
247 |
|
248 binaryLoadLabel = new Label(binaryGroup, SWT.RIGHT); |
|
249 binaryLoadLabel.setText(Messages.getString("SetThresholdsDialog.averageLoad")); //$NON-NLS-1$ |
|
250 binaryLoadLabel.setFont(PIPageEditor.helvetica_9); |
|
251 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
252 gridData.horizontalSpan = 1; |
|
253 |
|
254 binaryLoadText = new Text(binaryGroup, SWT.BORDER | SWT.RIGHT); |
|
255 binaryLoadText.setFont(PIPageEditor.helvetica_9); |
|
256 binaryLoadText.setData(Messages.getString("SetThresholdsDialog.minimumPercent")); //$NON-NLS-1$ |
|
257 binaryLoadText.setText(timeFormat.format(thresholdLoadBinary * 100.0)); |
|
258 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
259 gridData.horizontalSpan = 1; |
|
260 |
|
261 binaryCountLabel = new Label(binaryGroup, SWT.LEFT); |
|
262 binaryCountLabel.setText(Messages.getString("SetThresholdsDialog.totalSamples")); //$NON-NLS-1$ |
|
263 binaryCountLabel.setFont(PIPageEditor.helvetica_9); |
|
264 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
265 gridData.horizontalSpan = 1; |
|
266 |
|
267 binaryCountText = new Text(binaryGroup, SWT.BORDER | SWT.RIGHT); |
|
268 binaryCountText.setFont(PIPageEditor.helvetica_9); |
|
269 binaryCountText.setData(Messages.getString("SetThresholdsDialog.minimumSamples")); //$NON-NLS-1$ |
|
270 binaryCountText.setText("" + thresholdCountBinary); //$NON-NLS-1$ |
|
271 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
272 gridData.horizontalSpan = 1; |
|
273 |
|
274 // add the listeners |
|
275 binaryLoadText.addFocusListener(new FocusAdapter() { |
|
276 public void focusLost(FocusEvent e) { |
|
277 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
278 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
279 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
280 thresholdLoadBinary = convert(binaryLoadText, thresholdLoadBinary, 0, 100, timeFormat) / 100.0; |
|
281 thresholdCountBinary = (int) ((totalSampleCount / samplingInterval) * thresholdLoadBinary + 0.5); |
|
282 binaryLoadText.setText(timeFormat.format(thresholdLoadBinary * 100.0)); |
|
283 binaryCountText.setText("" + thresholdCountBinary); //$NON-NLS-1$ |
|
284 } |
|
285 }); |
|
286 |
|
287 binaryLoadText.addSelectionListener(new SelectionAdapter() { |
|
288 public void widgetDefaultSelected(SelectionEvent e) { |
|
289 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
290 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
291 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
292 thresholdLoadBinary = convert(binaryLoadText, thresholdLoadBinary, 0, 100, timeFormat) / 100.0; |
|
293 thresholdCountBinary = (int) ((totalSampleCount / samplingInterval) * thresholdLoadBinary + 0.5); |
|
294 binaryLoadText.setText(timeFormat.format(thresholdLoadBinary * 100.0)); |
|
295 binaryCountText.setText("" + thresholdCountBinary); //$NON-NLS-1$ |
|
296 } |
|
297 }); |
|
298 |
|
299 binaryCountText.addFocusListener(new FocusAdapter() { |
|
300 public void focusLost(FocusEvent e) { |
|
301 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
302 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
303 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
304 thresholdCountBinary = convert(binaryCountText, thresholdCountBinary, 0, totalSampleCount / samplingInterval); |
|
305 thresholdLoadBinary = ((double)thresholdCountBinary * samplingInterval) / ((double)totalSampleCount); |
|
306 binaryLoadText.setText(timeFormat.format(thresholdLoadBinary * 100.0)); |
|
307 binaryCountText.setText("" + thresholdCountBinary); //$NON-NLS-1$ |
|
308 } |
|
309 }); |
|
310 |
|
311 binaryCountText.addSelectionListener(new SelectionAdapter() { |
|
312 public void widgetDefaultSelected(SelectionEvent e) { |
|
313 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
314 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
315 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
316 thresholdCountBinary = convert(binaryCountText, thresholdCountBinary, 0, totalSampleCount / samplingInterval); |
|
317 thresholdLoadBinary = ((double)thresholdCountBinary * samplingInterval) / ((double)totalSampleCount); |
|
318 binaryLoadText.setText(timeFormat.format(thresholdLoadBinary * 100.0)); |
|
319 binaryCountText.setText("" + thresholdCountBinary); //$NON-NLS-1$ |
|
320 } |
|
321 }); |
|
322 |
|
323 binaryGroup.pack(); |
|
324 |
|
325 // function threshold |
|
326 functionGroup = new Group(shell, SWT.LEFT); |
|
327 functionGroup.setText(Messages.getString("SetThresholdsDialog.functionThreshold")); //$NON-NLS-1$ |
|
328 functionGroup.setFont(PIPageEditor.helvetica_10); |
|
329 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
330 gridData.horizontalSpan = 4; |
|
331 functionGroup.setLayoutData(gridData); |
|
332 functionGroup.setLayout(new FillLayout()); |
|
333 |
|
334 functionLoadLabel = new Label(functionGroup, SWT.RIGHT); |
|
335 functionLoadLabel.setText(Messages.getString("SetThresholdsDialog.averageLoad")); //$NON-NLS-1$ |
|
336 functionLoadLabel.setFont(PIPageEditor.helvetica_9); |
|
337 |
|
338 functionLoadText = new Text(functionGroup, SWT.BORDER | SWT.RIGHT); |
|
339 functionLoadText.setFont(PIPageEditor.helvetica_9); |
|
340 functionLoadText.setData(Messages.getString("SetThresholdsDialog.minimumPercent")); //$NON-NLS-1$ |
|
341 functionLoadText.setText(timeFormat.format(thresholdLoadFunction * 100.0)); |
|
342 |
|
343 functionCountLabel = new Label(functionGroup, SWT.LEFT); |
|
344 functionCountLabel.setText(Messages.getString("SetThresholdsDialog.totalSamples")); //$NON-NLS-1$ |
|
345 functionCountLabel.setFont(PIPageEditor.helvetica_9); |
|
346 |
|
347 functionCountText = new Text(functionGroup, SWT.BORDER | SWT.RIGHT); |
|
348 functionCountText.setFont(PIPageEditor.helvetica_9); |
|
349 functionCountText.setData(Messages.getString("SetThresholdsDialog.minimumSamples")); //$NON-NLS-1$ |
|
350 functionCountText.setText("" + thresholdCountFunction); //$NON-NLS-1$ |
|
351 |
|
352 // add the listeners |
|
353 functionLoadText.addFocusListener(new FocusAdapter() { |
|
354 public void focusLost(FocusEvent e) { |
|
355 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
356 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
357 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
358 thresholdLoadFunction = convert(functionLoadText, thresholdLoadFunction, 0, 100, timeFormat) / 100.0; |
|
359 thresholdCountFunction = (int) ((totalSampleCount / samplingInterval) * thresholdLoadFunction + 0.5); |
|
360 functionLoadText.setText(timeFormat.format(thresholdLoadFunction * 100.0)); |
|
361 functionCountText.setText("" + thresholdCountFunction); //$NON-NLS-1$ |
|
362 } |
|
363 }); |
|
364 |
|
365 functionLoadText.addSelectionListener(new SelectionAdapter() { |
|
366 public void widgetDefaultSelected(SelectionEvent e) { |
|
367 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
368 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
369 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
370 thresholdLoadFunction = convert(functionLoadText, thresholdLoadFunction, 0, 100, timeFormat) / 100.0; |
|
371 thresholdCountFunction = (int) ((totalSampleCount / samplingInterval) * thresholdLoadFunction + 0.5); |
|
372 functionLoadText.setText(timeFormat.format(thresholdLoadFunction * 100.0)); |
|
373 functionCountText.setText("" + thresholdCountFunction); //$NON-NLS-1$ |
|
374 } |
|
375 }); |
|
376 |
|
377 functionCountText.addFocusListener(new FocusAdapter() { |
|
378 public void focusLost(FocusEvent e) { |
|
379 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
380 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
381 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
382 thresholdCountFunction = convert(functionCountText, thresholdCountFunction, 0, totalSampleCount / samplingInterval); |
|
383 thresholdLoadFunction = ((double)thresholdCountFunction * samplingInterval) / ((double)totalSampleCount); |
|
384 functionLoadText.setText(timeFormat.format(thresholdLoadFunction * 100.0)); |
|
385 functionCountText.setText("" + thresholdCountFunction); //$NON-NLS-1$ |
|
386 } |
|
387 }); |
|
388 |
|
389 functionCountText.addSelectionListener(new SelectionAdapter() { |
|
390 public void widgetDefaultSelected(SelectionEvent e) { |
|
391 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
392 int totalSampleCount = NpiInstanceRepository.getInstance().getProfilePage(uid, PIPageEditor.THREADS_PAGE).getLastSampleX(); |
|
393 int samplingInterval = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.samplingInterval"); //$NON-NLS-1$ |
|
394 thresholdCountFunction = convert(functionCountText, thresholdCountFunction, 0, totalSampleCount / samplingInterval); |
|
395 thresholdLoadFunction = ((double)thresholdCountFunction * samplingInterval) / ((double)totalSampleCount); |
|
396 functionLoadText.setText(timeFormat.format(thresholdLoadFunction * 100.0)); |
|
397 functionCountText.setText("" + thresholdCountFunction); //$NON-NLS-1$ |
|
398 } |
|
399 }); |
|
400 |
|
401 functionGroup.pack(); |
|
402 |
|
403 // create the OK button |
|
404 ok = new Button(shell, SWT.NONE); |
|
405 ok.setEnabled(false); |
|
406 ok.setVisible(false); |
|
407 |
|
408 ok = new Button(shell, SWT.NONE); |
|
409 ok.setText(Messages.getString("SetThresholdsDialog.ok")); //$NON-NLS-1$ |
|
410 gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true); |
|
411 gridData.minimumWidth = 60; |
|
412 ok.setLayoutData(gridData); |
|
413 ok.addSelectionListener(new SelectionListener(){ |
|
414 |
|
415 public void widgetSelected(SelectionEvent e) { |
|
416 boolean changedThread = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountThread") != thresholdCountThread; //$NON-NLS-1$ |
|
417 boolean changedBinary = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountBinary") != thresholdCountBinary; //$NON-NLS-1$ |
|
418 boolean changedFunction = (Integer) NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountFunction") != thresholdCountFunction; //$NON-NLS-1$ |
|
419 |
|
420 if (changedThread) { |
|
421 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.address.thresholdLoadThread", new Double(thresholdLoadThread)); //$NON-NLS-1$ |
|
422 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountThread", new Integer(thresholdCountThread)); //$NON-NLS-1$ |
|
423 PIChangeEvent.action("changeThresholdThread"); //$NON-NLS-1$ |
|
424 PIChangeEvent.action("changeSelection"); //$NON-NLS-1$ |
|
425 } |
|
426 |
|
427 if (changedBinary) { |
|
428 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.address.thresholdLoadBinary", new Double(thresholdLoadBinary)); //$NON-NLS-1$ |
|
429 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountBinary", new Integer(thresholdCountBinary)); //$NON-NLS-1$ |
|
430 PIChangeEvent.action("changeThresholdBinary"); //$NON-NLS-1$ |
|
431 PIChangeEvent.action("changeSelection"); //$NON-NLS-1$ |
|
432 } |
|
433 |
|
434 if (changedFunction) { |
|
435 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.address.thresholdLoadFunction", new Double(thresholdLoadFunction)); //$NON-NLS-1$ |
|
436 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.address.thresholdCountFunction", new Integer(thresholdCountFunction)); //$NON-NLS-1$ |
|
437 PIChangeEvent.action("changeThresholdFunction"); //$NON-NLS-1$ |
|
438 PIChangeEvent.action("changeSelection"); //$NON-NLS-1$ |
|
439 } |
|
440 |
|
441 // after the graphs have been updated, notify plugins that might have tables but no graphs |
|
442 Enumeration enu = PluginInitialiser.getPluginInstances( |
|
443 "com.nokia.carbide.cpp.internal.pi.plugin.model.IEventListener"); //$NON-NLS-1$ |
|
444 if (enu != null) { |
|
445 Event event = new Event(); |
|
446 |
|
447 while (enu.hasMoreElements()) |
|
448 { |
|
449 IEventListener plugin = (IEventListener)enu.nextElement(); |
|
450 if (changedThread) { |
|
451 event.data = new Double(thresholdLoadThread); |
|
452 event.count = thresholdCountThread; |
|
453 plugin.receiveEvent("changeThresholdThread", event); //$NON-NLS-1$ |
|
454 } |
|
455 |
|
456 if (changedBinary) { |
|
457 event.data = new Double(thresholdLoadBinary); |
|
458 event.count = thresholdCountBinary; |
|
459 plugin.receiveEvent("changeThresholdBinary", event); //$NON-NLS-1$ |
|
460 } |
|
461 |
|
462 if (changedFunction) { |
|
463 event.data = new Double(thresholdLoadFunction); |
|
464 event.count = thresholdCountFunction; |
|
465 plugin.receiveEvent("changeThresholdFunction", event); //$NON-NLS-1$ |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 shell.close(); |
|
471 } |
|
472 |
|
473 public void widgetDefaultSelected(SelectionEvent e) { |
|
474 widgetSelected(e); |
|
475 } |
|
476 }); |
|
477 |
|
478 ok = new Button(shell, SWT.NONE); |
|
479 ok.setEnabled(false); |
|
480 ok.setVisible(false); |
|
481 |
|
482 // create the Cancel button |
|
483 cancel = new Button(shell, SWT.NONE); |
|
484 cancel.setText(Messages.getString("SetThresholdsDialog.cancel")); //$NON-NLS-1$ |
|
485 gridData = new GridData(SWT.LEFT, SWT.CENTER, true, true); |
|
486 gridData.minimumWidth = 60; |
|
487 cancel.setLayoutData(gridData); |
|
488 cancel.addSelectionListener(new SelectionListener(){ |
|
489 |
|
490 public void widgetSelected(SelectionEvent e) { |
|
491 shell.close(); |
|
492 } |
|
493 |
|
494 public void widgetDefaultSelected(SelectionEvent e) { |
|
495 widgetSelected(e); |
|
496 } |
|
497 }); |
|
498 |
|
499 if ((Boolean)NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.address.useOnlyThreadThresholds") == true) { //$NON-NLS-1$ |
|
500 // disable the other numbers |
|
501 binaryLoadText.setEnabled(false); |
|
502 binaryCountText.setEnabled(false); |
|
503 functionLoadText.setEnabled(false); |
|
504 functionCountText.setEnabled(false); |
|
505 } |
|
506 |
|
507 shell.pack(); |
|
508 shell.open(); |
|
509 |
|
510 while (!shell.isDisposed()) { |
|
511 if (!shell.getDisplay().readAndDispatch()) { |
|
512 shell.getDisplay().sleep(); |
|
513 } |
|
514 } |
|
515 } |
|
516 |
|
517 private double convert(Text text, double currentDouble, double minimum, double maximum, DecimalFormat format) |
|
518 { |
|
519 double new_double; |
|
520 |
|
521 // convert, catch (NumberFormatException e1) |
|
522 try { |
|
523 new_double = Double.parseDouble(text.getText().replace(',','.')); |
|
524 if (new_double >= 0) |
|
525 currentDouble = new_double; |
|
526 } catch (NumberFormatException exc) { |
|
527 // just keep the old value |
|
528 } |
|
529 |
|
530 if (currentDouble > maximum) |
|
531 currentDouble = maximum; |
|
532 else if (currentDouble < minimum) |
|
533 currentDouble = minimum; |
|
534 |
|
535 text.setText(format.format(currentDouble)); |
|
536 |
|
537 return currentDouble; |
|
538 } |
|
539 |
|
540 private int convert(Text text, int currentInt, int minimum, int maximum) |
|
541 { |
|
542 int new_int; |
|
543 |
|
544 // convert, catch (NumberFormatException e1) |
|
545 try { |
|
546 new_int = Integer.parseInt(text.getText().replace(',','.')); |
|
547 if (new_int >= 0) |
|
548 currentInt = new_int; |
|
549 } catch (NumberFormatException exc) { |
|
550 // just keep the old value |
|
551 } |
|
552 |
|
553 if (currentInt > maximum) |
|
554 currentInt = maximum; |
|
555 else if (currentInt < minimum) |
|
556 currentInt = minimum; |
|
557 |
|
558 text.setText("" + currentInt); //$NON-NLS-1$ |
|
559 |
|
560 return currentInt; |
|
561 } |
|
562 |
|
563 private void copyThreadThresholds() { |
|
564 thresholdLoadBinary = thresholdLoadThread; |
|
565 thresholdCountBinary = thresholdCountThread; |
|
566 thresholdLoadFunction = thresholdLoadThread; |
|
567 thresholdCountFunction = thresholdCountThread; |
|
568 binaryLoadText.setText(timeFormat.format(thresholdLoadBinary * 100.0)); |
|
569 binaryCountText.setText("" + thresholdCountBinary); //$NON-NLS-1$ |
|
570 functionLoadText.setText(timeFormat.format(thresholdLoadFunction * 100.0)); |
|
571 functionCountText.setText("" + thresholdCountFunction); //$NON-NLS-1$ |
|
572 } |
|
573 |
|
574 public void dispose() |
|
575 { |
|
576 if (this.shell != null) { |
|
577 if (!this.shell.isDisposed()) { |
|
578 this.shell.close(); |
|
579 } |
|
580 this.shell.dispose(); |
|
581 } |
|
582 |
|
583 this.shell = null; |
|
584 } |
|
585 } |