|
1 /* |
|
2 * Copyright (c) 2007-2010 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: |
|
15 * |
|
16 * Trigger Property Dialog class |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.dialog; |
|
20 |
|
21 import org.eclipse.swt.SWT; |
|
22 import org.eclipse.swt.events.SelectionAdapter; |
|
23 import org.eclipse.swt.events.SelectionEvent; |
|
24 import org.eclipse.swt.layout.GridData; |
|
25 import org.eclipse.swt.layout.GridLayout; |
|
26 import org.eclipse.swt.widgets.Button; |
|
27 import org.eclipse.swt.widgets.Combo; |
|
28 import org.eclipse.swt.widgets.Composite; |
|
29 import org.eclipse.swt.widgets.Label; |
|
30 import org.eclipse.swt.widgets.Shell; |
|
31 import org.eclipse.swt.widgets.Text; |
|
32 |
|
33 import com.nokia.traceviewer.dialog.treeitem.TreeItemListener; |
|
34 import com.nokia.traceviewer.dialog.treeitem.TriggerTreeItem; |
|
35 import com.nokia.traceviewer.dialog.treeitem.TriggerTreeTextItem; |
|
36 import com.nokia.traceviewer.engine.TraceViewerGlobals; |
|
37 |
|
38 /** |
|
39 * Trigger Property Dialog class |
|
40 * |
|
41 */ |
|
42 public class TriggerPropertyDialog extends BasePropertyDialog { |
|
43 |
|
44 /** |
|
45 * Text to show when Text rule is selected |
|
46 */ |
|
47 private static final String TEXT_RULE_INFORMATION_TEXT = Messages |
|
48 .getString("TriggerPropertyDialog.TextRuleInfo"); //$NON-NLS-1$ |
|
49 |
|
50 /** |
|
51 * Text to show when Activation rule is selected |
|
52 */ |
|
53 private static final String ACTIVATION_RULE_INFORMATION_TEXT = Messages |
|
54 .getString("TriggerPropertyDialog.ActivationRuleInfo"); //$NON-NLS-1$ |
|
55 |
|
56 /** |
|
57 * Stop trigger text |
|
58 */ |
|
59 private static final String STOP_TRIGGER_TEXT = Messages |
|
60 .getString("TriggerPropertyDialog.StopTrigger"); //$NON-NLS-1$ |
|
61 |
|
62 /** |
|
63 * Start trigger text |
|
64 */ |
|
65 private static final String START_TRIGGER_TEXT = Messages |
|
66 .getString("TriggerPropertyDialog.StartTrigger"); //$NON-NLS-1$ |
|
67 |
|
68 /** |
|
69 * Activation trigger text |
|
70 */ |
|
71 private static final String ACTIVATION_TRIGGER_TEXT = Messages |
|
72 .getString("TriggerPropertyDialog.ActivationTrigger"); //$NON-NLS-1$ |
|
73 |
|
74 /** |
|
75 * Activation rule index in the type array |
|
76 */ |
|
77 private static final int ACTIVATION_RULE_INDEX = 2; |
|
78 |
|
79 /** |
|
80 * Old item when editing |
|
81 */ |
|
82 private TriggerTreeItem oldItem; |
|
83 |
|
84 /** |
|
85 * Selected item in the tree |
|
86 */ |
|
87 private final TriggerTreeItem selectedItem; |
|
88 |
|
89 /** |
|
90 * Combo box for trigger type |
|
91 */ |
|
92 private Combo typeCombo; |
|
93 |
|
94 /** |
|
95 * Configuration file label |
|
96 */ |
|
97 private Label configurationFileLabel; |
|
98 |
|
99 /** |
|
100 * Activation configuration text field |
|
101 */ |
|
102 private Text activationConfText; |
|
103 |
|
104 /** |
|
105 * Load activation configuration button |
|
106 */ |
|
107 private Button loadActivationConfButton; |
|
108 |
|
109 /** |
|
110 * Configuration file path |
|
111 */ |
|
112 private String configurationFilePath; |
|
113 |
|
114 /** |
|
115 * Configuration name |
|
116 */ |
|
117 private String configurationName; |
|
118 |
|
119 /** |
|
120 * TreeItem listener |
|
121 */ |
|
122 private final TreeItemListener listener; |
|
123 |
|
124 /** |
|
125 * Constructor |
|
126 * |
|
127 * @param parent |
|
128 * Parent shell |
|
129 * @param newItem |
|
130 * TreeItem to modify, null if creating new one |
|
131 * @param listener |
|
132 * Tree item listener |
|
133 * @param selected |
|
134 * selected object |
|
135 */ |
|
136 public TriggerPropertyDialog(Shell parent, TriggerTreeItem newItem, |
|
137 TreeItemListener listener, Object selected) { |
|
138 super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); |
|
139 this.newItem = newItem; |
|
140 this.selectedItem = (TriggerTreeItem) selected; |
|
141 this.listener = listener; |
|
142 |
|
143 // If edit, save the old item to insert info to fields |
|
144 if (newItem != null) { |
|
145 oldItem = newItem; |
|
146 textFieldTouched = true; |
|
147 nameFieldTouched = true; |
|
148 |
|
149 if (oldItem instanceof TriggerTreeTextItem) { |
|
150 configurationFilePath = ((TriggerTreeTextItem) oldItem) |
|
151 .getConfigurationFilePath(); |
|
152 configurationName = ((TriggerTreeTextItem) oldItem) |
|
153 .getConfigurationName(); |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 /* |
|
159 * (non-Javadoc) |
|
160 * |
|
161 * @see com.nokia.traceviewer.dialog.BaseDialog#createDialogContents() |
|
162 */ |
|
163 @Override |
|
164 protected void createDialogContents() { |
|
165 getShell().setText( |
|
166 Messages.getString("TriggerPropertyDialog.TriggerDialogTitle")); //$NON-NLS-1$ |
|
167 composite.setLayout(new GridLayout()); |
|
168 createMainComposite(); |
|
169 } |
|
170 |
|
171 /* |
|
172 * (non-Javadoc) |
|
173 * |
|
174 * @see |
|
175 * com.nokia.traceviewer.dialog.BasePropertyDialog#createRightUnderComposite |
|
176 * () |
|
177 */ |
|
178 @Override |
|
179 protected void createRightUnderComposite() { |
|
180 // Dispose changeable elements |
|
181 if (rightUnderComposite != null) { |
|
182 disposeChangeableElements(); |
|
183 } else { |
|
184 // Right under composite |
|
185 GridLayout rightUnderCompositeGridLayout = new GridLayout(); |
|
186 rightUnderCompositeGridLayout.marginHeight = 14; |
|
187 rightUnderCompositeGridLayout.numColumns = 3; |
|
188 GridData rightUnderCompositeGridData = new GridData(); |
|
189 rightUnderCompositeGridData.heightHint = 114; |
|
190 rightUnderCompositeGridData.verticalAlignment = GridData.BEGINNING; |
|
191 rightUnderCompositeGridData.horizontalAlignment = SWT.FILL; |
|
192 rightUnderComposite = new Composite(mainComposite, SWT.BORDER); |
|
193 rightUnderComposite.setLayoutData(rightUnderCompositeGridData); |
|
194 rightUnderComposite.setLayout(rightUnderCompositeGridLayout); |
|
195 |
|
196 // Text label |
|
197 textLabel = new Label(rightUnderComposite, SWT.NONE); |
|
198 textLabel.setText(Messages |
|
199 .getString("TriggerPropertyDialog.TextString")); //$NON-NLS-1$ |
|
200 |
|
201 // Text text |
|
202 GridData textTextGridData = new GridData(); |
|
203 textTextGridData.horizontalIndent = 28; |
|
204 textTextGridData.horizontalAlignment = SWT.FILL; |
|
205 textTextGridData.horizontalSpan = 2; |
|
206 textTextGridData.grabExcessHorizontalSpace = true; |
|
207 textText = new Text(rightUnderComposite, SWT.BORDER); |
|
208 textText.setLayoutData(textTextGridData); |
|
209 if (oldItem instanceof TriggerTreeTextItem) { |
|
210 TriggerTreeTextItem item = (TriggerTreeTextItem) oldItem; |
|
211 textText.setText(item.getText()); |
|
212 } |
|
213 |
|
214 // Spacer |
|
215 spacer = new Label(rightUnderComposite, SWT.NONE); |
|
216 |
|
217 // Match case checkbox |
|
218 GridData matchCaseCheckBoxGridData = new GridData(); |
|
219 matchCaseCheckBoxGridData.horizontalIndent = 28; |
|
220 matchCaseCheckBoxGridData.horizontalSpan = 2; |
|
221 matchCaseCheckBox = new Button(rightUnderComposite, SWT.CHECK); |
|
222 matchCaseCheckBox.setText(Messages |
|
223 .getString("TriggerPropertyDialog.MatchCaseString")); //$NON-NLS-1$ |
|
224 matchCaseCheckBox.setLayoutData(matchCaseCheckBoxGridData); |
|
225 |
|
226 // Set match case checkbox value |
|
227 if (oldItem instanceof TriggerTreeTextItem) { |
|
228 TriggerTreeTextItem item = (TriggerTreeTextItem) oldItem; |
|
229 matchCaseCheckBox.setSelection(item.isMatchCase()); |
|
230 } |
|
231 |
|
232 // Type label |
|
233 Label typeLabel = new Label(rightUnderComposite, SWT.NONE); |
|
234 typeLabel.setText(Messages |
|
235 .getString("TriggerPropertyDialog.TypeString")); //$NON-NLS-1$ |
|
236 createTypeCombo(); |
|
237 } |
|
238 |
|
239 // Activation trigger type |
|
240 if (typeCombo.getSelectionIndex() == ACTIVATION_RULE_INDEX) { |
|
241 // Add new UI component, create action listeners for opening a file |
|
242 // Configuration file label |
|
243 configurationFileLabel = new Label(rightUnderComposite, SWT.NONE); |
|
244 configurationFileLabel.setText(Messages |
|
245 .getString("TriggerPropertyDialog.ConfFileString")); //$NON-NLS-1$ |
|
246 |
|
247 GridData activationConfGridData = new GridData(); |
|
248 activationConfGridData.horizontalIndent = 28; |
|
249 activationConfGridData.horizontalAlignment = SWT.FILL; |
|
250 activationConfGridData.grabExcessHorizontalSpace = true; |
|
251 activationConfText = new Text(rightUnderComposite, SWT.BORDER); |
|
252 activationConfText.setEditable(false); |
|
253 activationConfText.setLayoutData(activationConfGridData); |
|
254 if (oldItem instanceof TriggerTreeTextItem) { |
|
255 TriggerTreeTextItem item = (TriggerTreeTextItem) oldItem; |
|
256 activationConfText.setText(item.getConfigurationName()); |
|
257 } |
|
258 |
|
259 GridData loadActivationConfButtonGridData = new GridData(); |
|
260 loadActivationConfButtonGridData.heightHint = 25; |
|
261 loadActivationConfButtonGridData.widthHint = 30; |
|
262 loadActivationConfButton = new Button(rightUnderComposite, SWT.PUSH); |
|
263 loadActivationConfButton.setText("..."); //$NON-NLS-1$ |
|
264 loadActivationConfButton |
|
265 .setLayoutData(loadActivationConfButtonGridData); |
|
266 loadActivationConfButton |
|
267 .addSelectionListener(new SelectionAdapter() { |
|
268 @Override |
|
269 public void widgetSelected(SelectionEvent e) { |
|
270 |
|
271 // Open "Load configuration" dialog |
|
272 TraceConfigurationLoadDialog dialog = new TraceConfigurationLoadDialog( |
|
273 false, configurationFilePath); |
|
274 dialog.open(); |
|
275 |
|
276 configurationFilePath = dialog |
|
277 .getLoadedConfigurationFilePath(); |
|
278 configurationName = dialog |
|
279 .getLoadedConfigurationName(); |
|
280 activationConfText.setText(configurationName); |
|
281 } |
|
282 }); |
|
283 |
|
284 } else { |
|
285 // Remove extra UI component |
|
286 if (configurationFileLabel != null) { |
|
287 configurationFileLabel.dispose(); |
|
288 } |
|
289 if (activationConfText != null) { |
|
290 activationConfText.dispose(); |
|
291 } |
|
292 if (loadActivationConfButton != null) { |
|
293 loadActivationConfButton.dispose(); |
|
294 } |
|
295 } |
|
296 |
|
297 // Layout again |
|
298 rightUnderComposite.layout(); |
|
299 } |
|
300 |
|
301 /** |
|
302 * This method initializes typeCombo |
|
303 * |
|
304 */ |
|
305 private void createTypeCombo() { |
|
306 GridData typeComboGridData = new GridData(); |
|
307 typeComboGridData.horizontalIndent = 28; |
|
308 typeComboGridData.horizontalAlignment = SWT.FILL; |
|
309 typeComboGridData.horizontalSpan = 2; |
|
310 typeComboGridData.grabExcessHorizontalSpace = true; |
|
311 typeCombo = new Combo(rightUnderComposite, SWT.READ_ONLY); |
|
312 typeCombo.setLayoutData(typeComboGridData); |
|
313 |
|
314 // Keep in this order |
|
315 typeCombo.add(START_TRIGGER_TEXT); |
|
316 typeCombo.add(STOP_TRIGGER_TEXT); |
|
317 typeCombo.add(ACTIVATION_TRIGGER_TEXT); |
|
318 |
|
319 // Set match case checkbox value |
|
320 if (oldItem instanceof TriggerTreeTextItem) { |
|
321 TriggerTreeTextItem item = (TriggerTreeTextItem) oldItem; |
|
322 typeCombo.setText(typeCombo.getItem(item.getType().ordinal())); |
|
323 matchCaseCheckBox.setSelection(item.isMatchCase()); |
|
324 } else { |
|
325 typeCombo.setText(typeCombo.getItem(0)); |
|
326 } |
|
327 } |
|
328 |
|
329 /* |
|
330 * (non-Javadoc) |
|
331 * |
|
332 * @see |
|
333 * com.nokia.traceviewer.dialog.BasePropertyDialog#insertDataToUpperComposite |
|
334 * () |
|
335 */ |
|
336 @Override |
|
337 protected void insertDataToUpperComposite() { |
|
338 nameLabel.setText(Messages |
|
339 .getString("TriggerPropertyDialog.RuleNameString")); //$NON-NLS-1$ |
|
340 // Set data from old item |
|
341 if (oldItem != null) { |
|
342 nameText.setText(oldItem.getName()); |
|
343 if (oldItem.getRule() == TriggerTreeItem.Rule.TEXT_RULE) { |
|
344 selectedRuleLabel.setText(TEXT_RULE_NAME); |
|
345 } else { |
|
346 selectedRuleLabel.setText(TEXT_RULE_NAME); |
|
347 } |
|
348 } else { |
|
349 selectedRuleLabel.setText(TEXT_RULE_NAME); |
|
350 } |
|
351 } |
|
352 |
|
353 /* |
|
354 * (non-Javadoc) |
|
355 * |
|
356 * @see |
|
357 * com.nokia.traceviewer.dialog.BasePropertyDialog#insertDataToTextFields() |
|
358 */ |
|
359 @Override |
|
360 protected void insertDataToTextFields() { |
|
361 if (oldItem instanceof TriggerTreeTextItem) { |
|
362 TriggerTreeTextItem item = (TriggerTreeTextItem) oldItem; |
|
363 if (item.getText() != null) { |
|
364 textText.setText(item.getText()); |
|
365 } |
|
366 matchCaseCheckBox.setSelection(item.isMatchCase()); |
|
367 } |
|
368 } |
|
369 |
|
370 /* |
|
371 * (non-Javadoc) |
|
372 * |
|
373 * @see |
|
374 * com.nokia.traceviewer.dialog.BasePropertyDialog#insertDataToComponentFields |
|
375 * () |
|
376 */ |
|
377 @Override |
|
378 protected void insertDataToComponentFields() { |
|
379 } |
|
380 |
|
381 /* |
|
382 * (non-Javadoc) |
|
383 * |
|
384 * @see com.nokia.traceviewer.dialog.BasePropertyDialog#setListSelection() |
|
385 */ |
|
386 @Override |
|
387 protected void setListSelection() { |
|
388 ruleList.add(TEXT_RULE_NAME, TEXT_RULE_INDEX); |
|
389 // Set list selection |
|
390 if (oldItem != null) { |
|
391 if (oldItem.getRule() == TriggerTreeItem.Rule.TEXT_RULE) { |
|
392 ruleList.setSelection(TEXT_RULE_INDEX); |
|
393 } |
|
394 } else { |
|
395 ruleList.setSelection(TEXT_RULE_INDEX); |
|
396 } |
|
397 } |
|
398 |
|
399 @Override |
|
400 protected void okPressed() { |
|
401 TraceViewerGlobals.postUiEvent("OkButton", "1"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
402 // Save the position of this item to set it back after creation |
|
403 // and remove the old child |
|
404 int pos = 0; |
|
405 TriggerTreeItem parent = selectedItem; |
|
406 if (oldItem != null) { |
|
407 pos = getOldPosition(); |
|
408 parent = (TriggerTreeItem) oldItem.getParent(); |
|
409 parent.removeChild(oldItem); |
|
410 } |
|
411 |
|
412 // Create new TriggerTreeTextItem |
|
413 if (ruleList.getSelectionIndex() == TEXT_RULE_INDEX) { |
|
414 newItem = new TriggerTreeTextItem( |
|
415 listener, |
|
416 parent, |
|
417 nameText.getText(), |
|
418 TriggerTreeItem.Rule.TEXT_RULE, |
|
419 textText.getText(), |
|
420 matchCaseCheckBox.getSelection(), |
|
421 TriggerTreeItem.Type.values()[typeCombo.getSelectionIndex()], |
|
422 configurationFilePath, configurationName); |
|
423 |
|
424 // Add mode |
|
425 if (parent.equals(selectedItem)) { |
|
426 parent.addChild(newItem); |
|
427 |
|
428 // Edit mode |
|
429 } else { |
|
430 parent.addChild(pos, newItem); |
|
431 } |
|
432 |
|
433 } else { |
|
434 // No other rules yet |
|
435 } |
|
436 |
|
437 super.okPressed(); |
|
438 TraceViewerGlobals.postUiEvent("OkButton", "0"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
439 |
|
440 } |
|
441 |
|
442 /* |
|
443 * (non-Javadoc) |
|
444 * |
|
445 * @see |
|
446 * com.nokia.traceviewer.dialog.BasePropertyDialog#createActionListeners() |
|
447 */ |
|
448 @Override |
|
449 protected void createActionListeners() { |
|
450 super.createActionListeners(); |
|
451 super.createActionListenersForTextRule(); |
|
452 |
|
453 // Add selection listener to Trigger type combobox |
|
454 typeCombo.addSelectionListener(new SelectionAdapter() { |
|
455 |
|
456 @Override |
|
457 public void widgetSelected(SelectionEvent event) { |
|
458 // If type changes, we might need more or less UI components |
|
459 createRightUnderComposite(); |
|
460 setInformationLabel(); |
|
461 } |
|
462 }); |
|
463 } |
|
464 |
|
465 /* |
|
466 * (non-Javadoc) |
|
467 * |
|
468 * @see |
|
469 * com.nokia.traceviewer.dialog.BasePropertyDialog#setInformationLabel() |
|
470 */ |
|
471 @Override |
|
472 protected void setInformationLabel() { |
|
473 if (ruleList.getSelectionIndex() == TEXT_RULE_INDEX) { |
|
474 informationLabel.setText(TEXT_RULE_INFORMATION_TEXT); |
|
475 selectedRuleLabel.setText(TEXT_RULE_NAME); |
|
476 |
|
477 // Activation configuration |
|
478 if (typeCombo.getSelectionIndex() == ACTIVATION_RULE_INDEX) { |
|
479 informationLabel.setText(TEXT_RULE_INFORMATION_TEXT |
|
480 + ACTIVATION_RULE_INFORMATION_TEXT); |
|
481 } |
|
482 |
|
483 } |
|
484 } |
|
485 |
|
486 /** |
|
487 * Gets old position of this item |
|
488 * |
|
489 * @return old position |
|
490 */ |
|
491 protected int getOldPosition() { |
|
492 TriggerTreeItem item = (TriggerTreeItem) oldItem.getParent(); |
|
493 Object[] children = item.getChildren(); |
|
494 int pos = 0; |
|
495 for (int i = 0; i < children.length; i++) { |
|
496 if (children[i].equals(oldItem)) { |
|
497 pos = i; |
|
498 break; |
|
499 } |
|
500 } |
|
501 |
|
502 return pos; |
|
503 } |
|
504 |
|
505 /** |
|
506 * Disposes changeable elements if they exist. Is called when selection is |
|
507 * changed from the trigger type list and some ui components are changed |
|
508 */ |
|
509 private void disposeChangeableElements() { |
|
510 |
|
511 } |
|
512 } |