|
1 /* |
|
2 * Copyright (c) 2008 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 * Control logic for property dialog |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.engine.propertydialog; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
|
23 |
|
24 import com.nokia.tracebuilder.engine.SourceContextManager; |
|
25 import com.nokia.tracebuilder.engine.TraceBuilderConfiguration; |
|
26 import com.nokia.tracebuilder.engine.TraceBuilderDialogs; |
|
27 import com.nokia.tracebuilder.engine.TraceBuilderGlobals; |
|
28 import com.nokia.tracebuilder.engine.TraceLocation; |
|
29 import com.nokia.tracebuilder.engine.TraceLocationList; |
|
30 import com.nokia.tracebuilder.engine.TraceObjectPropertyDialog; |
|
31 import com.nokia.tracebuilder.engine.TraceObjectPropertyDialogConfiguration; |
|
32 import com.nokia.tracebuilder.engine.TraceObjectPropertyDialogEnabler; |
|
33 import com.nokia.tracebuilder.engine.TraceObjectPropertyDialogFlag; |
|
34 import com.nokia.tracebuilder.engine.TraceObjectPropertyDialogTemplate; |
|
35 import com.nokia.tracebuilder.engine.TraceBuilderErrorCodes.TraceBuilderErrorCode; |
|
36 import com.nokia.tracebuilder.engine.utils.TraceUtils; |
|
37 import com.nokia.tracebuilder.model.Trace; |
|
38 import com.nokia.tracebuilder.model.TraceBuilderException; |
|
39 import com.nokia.tracebuilder.model.TraceConstantTable; |
|
40 import com.nokia.tracebuilder.model.TraceConstantTableEntry; |
|
41 import com.nokia.tracebuilder.model.TraceGroup; |
|
42 import com.nokia.tracebuilder.model.TraceModel; |
|
43 import com.nokia.tracebuilder.model.TraceModelExtension; |
|
44 import com.nokia.tracebuilder.model.TraceObject; |
|
45 import com.nokia.tracebuilder.model.TraceObjectUtils; |
|
46 import com.nokia.tracebuilder.model.TraceParameter; |
|
47 import com.nokia.tracebuilder.rules.ReadOnlyObjectRule; |
|
48 import com.nokia.tracebuilder.rules.TraceParameterRestrictionRule; |
|
49 |
|
50 /** |
|
51 * Control logic for property dialog. Separated from TraceBuilder, since it was |
|
52 * getting too complex |
|
53 * |
|
54 */ |
|
55 public class PropertyDialogEngine implements PropertyDialogConfigurationNames { |
|
56 |
|
57 /** |
|
58 * Properties dialog is used to add and edit trace objects |
|
59 */ |
|
60 private TraceObjectPropertyDialog propertyDialog; |
|
61 |
|
62 /** |
|
63 * Interface which is used to configure the property dialog |
|
64 */ |
|
65 private TraceObjectPropertyDialogConfiguration propertyDialogConfiguration; |
|
66 |
|
67 /** |
|
68 * Property dialog verifier |
|
69 */ |
|
70 private PropertyDialogVerifier propertyDialogVerifier; |
|
71 |
|
72 /** |
|
73 * Trace model |
|
74 */ |
|
75 private TraceModel model; |
|
76 |
|
77 /** |
|
78 * Constructor |
|
79 * |
|
80 * @param model |
|
81 * the trace model |
|
82 * @param dialogConfiguration |
|
83 * dialog configuration interface |
|
84 */ |
|
85 public PropertyDialogEngine(TraceModel model, |
|
86 TraceObjectPropertyDialogConfiguration dialogConfiguration) { |
|
87 this.model = model; |
|
88 propertyDialogConfiguration = dialogConfiguration; |
|
89 propertyDialogVerifier = new PropertyDialogVerifier(model, |
|
90 propertyDialog); |
|
91 } |
|
92 |
|
93 /** |
|
94 * Changes the property dialog |
|
95 * |
|
96 * @param propertyDialog |
|
97 * the new property dialog |
|
98 */ |
|
99 public void setPropertyDialog(TraceObjectPropertyDialog propertyDialog) { |
|
100 this.propertyDialog = propertyDialog; |
|
101 propertyDialogVerifier.setPropertyDialog(propertyDialog); |
|
102 } |
|
103 |
|
104 /** |
|
105 * Shows "Add Trace" dialog. |
|
106 * |
|
107 * @param group |
|
108 * group proposal |
|
109 * @param name |
|
110 * name proposal |
|
111 * @param value |
|
112 * value proposal |
|
113 * @param enabler |
|
114 * dialog enabler interface |
|
115 * @return the new trace |
|
116 */ |
|
117 public Trace showAddTraceDialog(TraceGroup group, String name, |
|
118 String value, PropertyDialogEnabler enabler) { |
|
119 return showAddTraceDialog(group, name, value, null, enabler); |
|
120 } |
|
121 |
|
122 /** |
|
123 * Shows "Add Trace" dialog. |
|
124 * |
|
125 * @param group |
|
126 * group proposal |
|
127 * @param name |
|
128 * name proposal |
|
129 * @param value |
|
130 * value proposal |
|
131 * @param extensions |
|
132 * extensions for the next object |
|
133 * @param enabler |
|
134 * dialog enabler interface |
|
135 * @return the new trace |
|
136 */ |
|
137 public Trace showAddTraceDialog(TraceGroup group, String name, |
|
138 String value, List<TraceModelExtension> extensions, |
|
139 PropertyDialogEnabler enabler) { |
|
140 TraceBuilderConfiguration config = TraceBuilderGlobals |
|
141 .getConfiguration(); |
|
142 // If a group has been selected, the selection is set to the dialog |
|
143 int id; |
|
144 if (group != null) { |
|
145 id = group.getNextTraceID(); |
|
146 } else { |
|
147 id = 1; |
|
148 } |
|
149 if (name == null) { |
|
150 name = config.getText(PROPERTY_DIALOG_TRACE_NAME); |
|
151 } |
|
152 if (value == null) { |
|
153 value = config.getText(PROPERTY_DIALOG_TRACE_TEXT); |
|
154 } |
|
155 if (group == null) { |
|
156 group = model.findGroupByName(config |
|
157 .getText(PROPERTY_DIALOG_TRACE_GROUP)); |
|
158 } |
|
159 name = TraceObjectUtils.modifyDuplicateTraceName(model, |
|
160 TraceUtils.convertName(name)).getData(); |
|
161 setAddDialogDefaults(TraceObjectPropertyDialog.ADD_TRACE, id, name, |
|
162 value, group, enabler); |
|
163 propertyDialog.setEnabler(enabler); |
|
164 CreateTraceCallback callback = new CreateTraceCallback(model, |
|
165 extensions); |
|
166 showDialog(callback); |
|
167 return callback.getTrace(); |
|
168 } |
|
169 |
|
170 /** |
|
171 * Shows the instrumenter dialog |
|
172 * |
|
173 * @param target |
|
174 * the selected group |
|
175 * @param enabler |
|
176 * dialog enabler interface |
|
177 * @param callback |
|
178 * callback processing the instrumentation |
|
179 */ |
|
180 public void showInstrumenterDialog(TraceGroup target, |
|
181 PropertyDialogEnabler enabler, RunInstrumenterCallback callback) { |
|
182 TraceBuilderConfiguration config = TraceBuilderGlobals |
|
183 .getConfiguration(); |
|
184 String name = config.getText(PROPERTY_DIALOG_INSTRUMENTER_NAME_FORMAT); |
|
185 if (name == null || name.length() == 0) { |
|
186 name = TraceUtils.getDefaultNameFormat(); |
|
187 } |
|
188 String trace = config |
|
189 .getText(PROPERTY_DIALOG_INSTRUMENTER_TRACE_FORMAT); |
|
190 if (trace == null || trace.length() == 0) { |
|
191 trace = TraceUtils.getDefaultTraceFormat(); |
|
192 } |
|
193 if (target == null) { |
|
194 target = model.findGroupByName(config |
|
195 .getText(PROPERTY_DIALOG_INSTRUMENTER_TRACE_GROUP)); |
|
196 } |
|
197 setAddDialogDefaults(TraceObjectPropertyDialog.INSTRUMENTER, 0, name, |
|
198 trace, target, enabler); |
|
199 SourceContextManager manager = TraceBuilderGlobals |
|
200 .getSourceContextManager(); |
|
201 manager.setInstrumenting(true); |
|
202 try { |
|
203 showDialog(callback); |
|
204 } finally { |
|
205 manager.setInstrumenting(false); |
|
206 } |
|
207 } |
|
208 |
|
209 /** |
|
210 * Shows "Add Parameter" dialog |
|
211 * |
|
212 * @param trace |
|
213 * owner of the new parameter |
|
214 * @param enabler |
|
215 * dialog enabler interface |
|
216 * @return the new parameter |
|
217 * @throws TraceBuilderException |
|
218 * if dialog cannot be shown |
|
219 */ |
|
220 public TraceParameter showAddParameterDialog(Trace trace, |
|
221 PropertyDialogEnabler enabler) throws TraceBuilderException { |
|
222 TraceParameter retval = null; |
|
223 // Trace rules are checked first |
|
224 TraceParameterRestrictionRule restriction = trace |
|
225 .getExtension(TraceParameterRestrictionRule.class); |
|
226 ReadOnlyObjectRule readOnly = trace |
|
227 .getExtension(ReadOnlyObjectRule.class); |
|
228 if (readOnly == null |
|
229 && (restriction == null || restriction.canAddParameters())) { |
|
230 int result = PropertyDialogCallback |
|
231 .showLocationConfirmationQuery(trace); |
|
232 if (result == TraceBuilderDialogs.OK) { |
|
233 retval = internalShowAddParameterDialog(trace, enabler); |
|
234 } |
|
235 } else { |
|
236 throw new TraceBuilderException( |
|
237 TraceBuilderErrorCode.PARAMETER_ADD_NOT_ALLOWED); |
|
238 } |
|
239 return retval; |
|
240 } |
|
241 |
|
242 /** |
|
243 * Shows "Select component" dialog |
|
244 */ |
|
245 public void showSelectComponentDialog() { |
|
246 |
|
247 if (propertyDialog != null) { |
|
248 |
|
249 // Create enabler |
|
250 PropertyDialogEnabler enabler = new PropertyDialogEnabler( |
|
251 PropertyDialogEnabler.ENABLE_TARGET); |
|
252 TraceBuilderConfiguration config = TraceBuilderGlobals |
|
253 .getConfiguration(); |
|
254 String name = config.getText(PROPERTY_DIALOG_COMPONENT_NAME); |
|
255 setAddDialogDefaults(TraceObjectPropertyDialog.SELECT_COMPONENT, 0, |
|
256 name, null, model, enabler); |
|
257 // Set default target to be same as previous software component |
|
258 propertyDialog.setTarget(TraceBuilderGlobals |
|
259 .getPreviousSoftwareComponentName()); |
|
260 showDialog(new SelectComponentCallback(model)); |
|
261 } |
|
262 } |
|
263 |
|
264 /** |
|
265 * Shows "Add Parameter" dialog |
|
266 * |
|
267 * @param trace |
|
268 * owner of the new parameter |
|
269 * @param enabler |
|
270 * dialog enabler interface |
|
271 * @return the new parameter |
|
272 */ |
|
273 private TraceParameter internalShowAddParameterDialog(Trace trace, |
|
274 PropertyDialogEnabler enabler) { |
|
275 TraceBuilderConfiguration config = TraceBuilderGlobals |
|
276 .getConfiguration(); |
|
277 int id = trace.getNextParameterID(); |
|
278 // Parameter proposal defaults to last used value |
|
279 String name = config.getText(PROPERTY_DIALOG_PARAMETER_NAME); |
|
280 String type = config.getText(PROPERTY_DIALOG_PARAMETER_TYPE); |
|
281 setAddDialogDefaults(TraceObjectPropertyDialog.ADD_PARAMETER, id, |
|
282 TraceObjectUtils.modifyDuplicateParameterName(trace, name) |
|
283 .getData(), null, trace, enabler); |
|
284 propertyDialog.setValue(type); |
|
285 TraceLocationList list = trace.getExtension(TraceLocationList.class); |
|
286 if (list != null && list.hasLocations()) { |
|
287 TraceLocation loc = (TraceLocation) list.iterator().next(); |
|
288 if (loc.getParameterCount() > trace.getParameterCount()) { |
|
289 String proposal = loc.getParameter(trace.getParameterCount()); |
|
290 if (proposal.length() > 0) { |
|
291 propertyDialog.setName(proposal); |
|
292 propertyDialog.setValue(proposal); |
|
293 } |
|
294 } |
|
295 } |
|
296 CreateParameterCallback callback = new CreateParameterCallback(model, |
|
297 trace); |
|
298 showDialog(callback); |
|
299 return callback.getParameter(); |
|
300 } |
|
301 |
|
302 /** |
|
303 * Shows "Add Constant" dialog |
|
304 * |
|
305 * @param table |
|
306 * target constant table |
|
307 * @param enabler |
|
308 * dialog enabler interface |
|
309 */ |
|
310 public void showAddConstantDialog(TraceConstantTable table, |
|
311 PropertyDialogEnabler enabler) { |
|
312 TraceBuilderConfiguration config = TraceBuilderGlobals |
|
313 .getConfiguration(); |
|
314 String name = config.getText(PROPERTY_DIALOG_CONSTANT_NAME); |
|
315 int id = 0; |
|
316 if (table != null) { |
|
317 id = table.getNextEntryID(); |
|
318 } |
|
319 setAddDialogDefaults(TraceObjectPropertyDialog.ADD_CONSTANT, id, |
|
320 TraceObjectUtils.modifyDuplicateConstantName(table, name) |
|
321 .getData(), null, table, enabler); |
|
322 showDialog(new CreateConstantCallback(model)); |
|
323 } |
|
324 |
|
325 /** |
|
326 * Shows the "Edit Group" dialog |
|
327 * |
|
328 * @param group |
|
329 * group to be edited |
|
330 */ |
|
331 public void showEditGroupDialog(TraceGroup group) { |
|
332 int result = PropertyDialogCallback |
|
333 .showLocationConfirmationQuery(group); |
|
334 if (result == TraceBuilderDialogs.OK) { |
|
335 setEditDialogDefaults(TraceObjectPropertyDialog.EDIT_GROUP, group); |
|
336 showDialog(new UpdateGroupCallback(model, group)); |
|
337 } |
|
338 } |
|
339 |
|
340 /** |
|
341 * Shows the "Edit Trace" dialog |
|
342 * |
|
343 * @param trace |
|
344 * trace to be edited |
|
345 */ |
|
346 public void showEditTraceDialog(Trace trace) { |
|
347 int result = PropertyDialogCallback |
|
348 .showLocationConfirmationQuery(trace); |
|
349 if (result == TraceBuilderDialogs.OK) { |
|
350 setEditDialogDefaults(TraceObjectPropertyDialog.EDIT_TRACE, trace); |
|
351 propertyDialog.setValue(trace.getTrace()); |
|
352 showDialog(new UpdateTraceCallback(model, trace)); |
|
353 } |
|
354 } |
|
355 |
|
356 /** |
|
357 * Shows the "Edit Constant Table" dialog |
|
358 * |
|
359 * @param table |
|
360 * the table to be edited |
|
361 */ |
|
362 public void showEditConstantTableDialog(TraceConstantTable table) { |
|
363 setEditDialogDefaults(TraceObjectPropertyDialog.EDIT_CONSTANT_TABLE, |
|
364 table); |
|
365 showDialog(new UpdateConstantTableCallback(model, table)); |
|
366 } |
|
367 |
|
368 /** |
|
369 * Shows the "Edit Constant" dialog |
|
370 * |
|
371 * @param entry |
|
372 * entry to be edited |
|
373 */ |
|
374 public void showEditConstantDialog(TraceConstantTableEntry entry) { |
|
375 setEditDialogDefaults(TraceObjectPropertyDialog.EDIT_CONSTANT, entry); |
|
376 showDialog(new UpdateConstantCallback(model, entry)); |
|
377 } |
|
378 |
|
379 /** |
|
380 * Sets the default values for the dialog |
|
381 * |
|
382 * @param dialogType |
|
383 * the dialog type |
|
384 * @param id |
|
385 * value for ID field |
|
386 * @param name |
|
387 * value for name field |
|
388 * @param value |
|
389 * value for value field |
|
390 * @param target |
|
391 * the target object |
|
392 * @param enabler |
|
393 * dialog enabler interface |
|
394 */ |
|
395 private void setAddDialogDefaults(int dialogType, int id, String name, |
|
396 String value, TraceObject target, PropertyDialogEnabler enabler) { |
|
397 ArrayList<TraceObjectPropertyDialogFlag> flags = initFlags(dialogType, |
|
398 enabler); |
|
399 ArrayList<TraceObjectPropertyDialogTemplate> templates = initTemplates( |
|
400 dialogType, enabler); |
|
401 TraceObjectPropertyDialogTemplate selectedTemplate = findTemplateByTitle( |
|
402 dialogType, templates); |
|
403 propertyDialog.setVerifier(propertyDialogVerifier); |
|
404 propertyDialog.setTargetObject(target); |
|
405 propertyDialog.setEnabler(enabler); |
|
406 propertyDialog.setDialogType(dialogType); |
|
407 propertyDialog.setFlags(flags); |
|
408 propertyDialog.setTemplates(templates, selectedTemplate); |
|
409 propertyDialog.setID(id); |
|
410 propertyDialog.setName(name); |
|
411 propertyDialog.setValue(value); |
|
412 } |
|
413 |
|
414 /** |
|
415 * Creates the dialog templates array |
|
416 * |
|
417 * @param dialogType |
|
418 * the dialog type |
|
419 * @param enabler |
|
420 * the dialog enabler interface |
|
421 * @return the templates array |
|
422 */ |
|
423 private ArrayList<TraceObjectPropertyDialogTemplate> initTemplates( |
|
424 int dialogType, PropertyDialogEnabler enabler) { |
|
425 ArrayList<TraceObjectPropertyDialogTemplate> templates; |
|
426 if (enabler == null || enabler.isTemplateEnabled()) { |
|
427 templates = new ArrayList<TraceObjectPropertyDialogTemplate>(); |
|
428 addViewTemplates(dialogType, templates); |
|
429 } else { |
|
430 // If enabler interface exists and disables templates, the templates |
|
431 // are not added to the dialog |
|
432 templates = null; |
|
433 } |
|
434 return templates; |
|
435 } |
|
436 |
|
437 /** |
|
438 * Creates the dialog flags array |
|
439 * |
|
440 * @param dialogType |
|
441 * the dialog type |
|
442 * @param enabler |
|
443 * dialog enabler interface |
|
444 * @return the flags array |
|
445 */ |
|
446 private ArrayList<TraceObjectPropertyDialogFlag> initFlags(int dialogType, |
|
447 PropertyDialogEnabler enabler) { |
|
448 ArrayList<TraceObjectPropertyDialogFlag> flags; |
|
449 if (enabler == null || enabler.isFlagsEnabled()) { |
|
450 flags = new ArrayList<TraceObjectPropertyDialogFlag>(); |
|
451 propertyDialogConfiguration.addViewFlags(flags, dialogType); |
|
452 } else { |
|
453 // If enabler interface exists and disables flags, the flags |
|
454 // are not added to the dialog |
|
455 flags = null; |
|
456 } |
|
457 if (flags != null) { |
|
458 String flagPrefix = null; |
|
459 switch (dialogType) { |
|
460 case TraceObjectPropertyDialog.ADD_TRACE: |
|
461 flagPrefix = PROPERTY_DIALOG_TRACE_FLAG; |
|
462 break; |
|
463 case TraceObjectPropertyDialog.ADD_PARAMETER: |
|
464 flagPrefix = PROPERTY_DIALOG_PARAMETER_FLAG; |
|
465 break; |
|
466 case TraceObjectPropertyDialog.ADD_CONSTANT: |
|
467 flagPrefix = PROPERTY_DIALOG_CONSTANT_FLAG; |
|
468 break; |
|
469 case TraceObjectPropertyDialog.INSTRUMENTER: |
|
470 flagPrefix = PROPERTY_DIALOG_INSTRUMENTER_FLAG; |
|
471 break; |
|
472 } |
|
473 // The flag values are set to what has been stored into preferences |
|
474 if (flagPrefix != null) { |
|
475 TraceBuilderConfiguration config = TraceBuilderGlobals |
|
476 .getConfiguration(); |
|
477 for (TraceObjectPropertyDialogFlag flag : flags) { |
|
478 String flagName = flagPrefix + flag.getText(); |
|
479 if (config.hasEntry(flagName)) { |
|
480 flag.setEnabled(config.getFlag(flagName)); |
|
481 } |
|
482 } |
|
483 } |
|
484 } |
|
485 return flags; |
|
486 } |
|
487 |
|
488 /** |
|
489 * Finds a template from given list by title stored into configuration |
|
490 * |
|
491 * @param dialogType |
|
492 * the dialog type |
|
493 * @param templates |
|
494 * the templates list |
|
495 * @return the template that should be activated |
|
496 */ |
|
497 private TraceObjectPropertyDialogTemplate findTemplateByTitle( |
|
498 int dialogType, List<TraceObjectPropertyDialogTemplate> templates) { |
|
499 TraceBuilderConfiguration config = TraceBuilderGlobals |
|
500 .getConfiguration(); |
|
501 String templateTitle = null; |
|
502 switch (dialogType) { |
|
503 case TraceObjectPropertyDialog.ADD_TRACE: |
|
504 templateTitle = config.getText(PROPERTY_DIALOG_TRACE_TEMPLATE); |
|
505 break; |
|
506 case TraceObjectPropertyDialog.ADD_PARAMETER: |
|
507 templateTitle = config.getText(PROPERTY_DIALOG_PARAMETER_TEMPLATE); |
|
508 break; |
|
509 case TraceObjectPropertyDialog.ADD_CONSTANT: |
|
510 templateTitle = config.getText(PROPERTY_DIALOG_CONSTANT_TEMPLATE); |
|
511 break; |
|
512 case TraceObjectPropertyDialog.INSTRUMENTER: |
|
513 templateTitle = config |
|
514 .getText(PROPERTY_DIALOG_INSTRUMENTER_TEMPLATE); |
|
515 break; |
|
516 } |
|
517 // Selects the template which has the title stored into preferences |
|
518 TraceObjectPropertyDialogTemplate template = null; |
|
519 if (templateTitle != null && templates != null) { |
|
520 for (TraceObjectPropertyDialogTemplate temp : templates) { |
|
521 if (temp.getTitle().equals(templateTitle)) { |
|
522 template = temp; |
|
523 break; |
|
524 } |
|
525 } |
|
526 } |
|
527 return template; |
|
528 } |
|
529 |
|
530 /** |
|
531 * Adds the templates to "Add" dialog |
|
532 * |
|
533 * @param dialogType |
|
534 * the dialog type |
|
535 * @param templates |
|
536 * the list of templates |
|
537 */ |
|
538 private void addViewTemplates(int dialogType, |
|
539 ArrayList<TraceObjectPropertyDialogTemplate> templates) { |
|
540 propertyDialogConfiguration.addViewTemplates(templates, dialogType); |
|
541 if (dialogType != TraceObjectPropertyDialog.INSTRUMENTER) { |
|
542 // Removes all templates that are not available in current context |
|
543 // Instrumenter affects multiple contexts, so templates are always |
|
544 // available at this point |
|
545 for (int i = 0; i < templates.size(); i++) { |
|
546 TraceObjectPropertyDialogTemplate template = templates.get(i); |
|
547 if (template instanceof ContextBasedTemplate) { |
|
548 if (!((ContextBasedTemplate) template) |
|
549 .isAvailableInContext(TraceBuilderGlobals |
|
550 .getSourceContextManager().getContext())) { |
|
551 templates.remove(i); |
|
552 i--; |
|
553 } |
|
554 } |
|
555 } |
|
556 } |
|
557 } |
|
558 |
|
559 /** |
|
560 * Initializes the edit dialog with values from object |
|
561 * |
|
562 * @param dialogType |
|
563 * the dialog type |
|
564 * @param object |
|
565 * the object to be edited |
|
566 */ |
|
567 private void setEditDialogDefaults(int dialogType, TraceObject object) { |
|
568 ArrayList<TraceObjectPropertyDialogFlag> list = new ArrayList<TraceObjectPropertyDialogFlag>(); |
|
569 propertyDialogConfiguration.addViewFlags(list, dialogType); |
|
570 propertyDialog.setVerifier(propertyDialogVerifier); |
|
571 propertyDialog.setTargetObject(object); |
|
572 propertyDialog.setEnabler(object |
|
573 .getExtension(TraceObjectPropertyDialogEnabler.class)); |
|
574 propertyDialog.setDialogType(dialogType); |
|
575 propertyDialog.setFlags(list); |
|
576 propertyDialog.setTemplates(null, null); |
|
577 propertyDialog.setID(object.getID()); |
|
578 propertyDialog.setName(object.getName()); |
|
579 propertyDialog.setValue(null); |
|
580 } |
|
581 |
|
582 /** |
|
583 * Shows the property dialog |
|
584 * |
|
585 * @param callback |
|
586 * the callback for OK processing |
|
587 */ |
|
588 private void showDialog(PropertyDialogEngineCallback callback) { |
|
589 TraceBuilderErrorCode valid; |
|
590 do { |
|
591 int res = propertyDialog.open(); |
|
592 if (res == TraceObjectPropertyDialog.OK) { |
|
593 valid = TraceBuilderErrorCode.OK; |
|
594 try { |
|
595 callback.okSelected(propertyDialog); |
|
596 saveData(); |
|
597 } catch (TraceBuilderException e) { |
|
598 valid = (TraceBuilderErrorCode) e.getErrorCode(); |
|
599 TraceBuilderGlobals.getEvents().postError(e); |
|
600 } |
|
601 } else { |
|
602 valid = TraceBuilderErrorCode.OK; |
|
603 } |
|
604 } while (valid != TraceBuilderErrorCode.OK); |
|
605 } |
|
606 |
|
607 /** |
|
608 * Saves the data into properties for later use |
|
609 */ |
|
610 private void saveData() { |
|
611 TraceBuilderConfiguration config = TraceBuilderGlobals |
|
612 .getConfiguration(); |
|
613 String templateTitle = null; |
|
614 TraceObjectPropertyDialogTemplate template = propertyDialog |
|
615 .getTemplate(); |
|
616 // Template is saved based on localized title -> Not so good but works |
|
617 if (template != null) { |
|
618 templateTitle = template.getTitle(); |
|
619 } |
|
620 if (templateTitle == null) { |
|
621 templateTitle = ""; //$NON-NLS-1$ |
|
622 } |
|
623 String flagPrefix = getFlagPrefix(config, templateTitle); |
|
624 if (flagPrefix != null) { |
|
625 List<TraceObjectPropertyDialogFlag> flags = propertyDialog |
|
626 .getFlags(); |
|
627 if (flags != null) { |
|
628 for (int i = 0; i < flags.size(); i++) { |
|
629 TraceObjectPropertyDialogFlag flag = flags.get(i); |
|
630 config.setFlag(flagPrefix + flag.getText(), flag |
|
631 .isEnabled()); |
|
632 } |
|
633 } |
|
634 } |
|
635 } |
|
636 |
|
637 /** |
|
638 * Gets the prefix for flags and saves other properties |
|
639 * |
|
640 * @param config |
|
641 * the configuration |
|
642 * @param templateTitle |
|
643 * the template title |
|
644 * @return the prefix |
|
645 */ |
|
646 private String getFlagPrefix(TraceBuilderConfiguration config, |
|
647 String templateTitle) { |
|
648 String flagPrefix = null; |
|
649 // Each dialog type is separately saved |
|
650 switch (propertyDialog.getDialogType()) { |
|
651 case TraceObjectPropertyDialog.ADD_TRACE: |
|
652 config |
|
653 .setText(PROPERTY_DIALOG_TRACE_NAME, propertyDialog |
|
654 .getName()); |
|
655 config.setText(PROPERTY_DIALOG_TRACE_TEXT, propertyDialog |
|
656 .getValue()); |
|
657 config.setText(PROPERTY_DIALOG_TRACE_TEMPLATE, templateTitle); |
|
658 config.setText(PROPERTY_DIALOG_TRACE_GROUP, propertyDialog |
|
659 .getTarget()); |
|
660 flagPrefix = PROPERTY_DIALOG_TRACE_FLAG; |
|
661 break; |
|
662 case TraceObjectPropertyDialog.ADD_PARAMETER: |
|
663 config.setText(PROPERTY_DIALOG_PARAMETER_NAME, propertyDialog |
|
664 .getName()); |
|
665 config.setText(PROPERTY_DIALOG_PARAMETER_TYPE, propertyDialog |
|
666 .getValue()); |
|
667 config.setText(PROPERTY_DIALOG_PARAMETER_TEMPLATE, templateTitle); |
|
668 flagPrefix = PROPERTY_DIALOG_PARAMETER_FLAG; |
|
669 break; |
|
670 case TraceObjectPropertyDialog.SELECT_COMPONENT: |
|
671 config.setText(PROPERTY_DIALOG_COMPONENT_NAME, propertyDialog |
|
672 .getName()); |
|
673 config.setText(PROPERTY_DIALOG_SELECT_COMPONENT_TEMPLATE, |
|
674 templateTitle); |
|
675 flagPrefix = PROPERTY_DIALOG_COMPONENT_FLAG; |
|
676 break; |
|
677 case TraceObjectPropertyDialog.ADD_CONSTANT: |
|
678 config.setText(PROPERTY_DIALOG_CONSTANT_NAME, propertyDialog |
|
679 .getName()); |
|
680 config.setText(PROPERTY_DIALOG_CONSTANT_TEMPLATE, templateTitle); |
|
681 flagPrefix = PROPERTY_DIALOG_CONSTANT_FLAG; |
|
682 break; |
|
683 case TraceObjectPropertyDialog.INSTRUMENTER: |
|
684 config.setText(PROPERTY_DIALOG_INSTRUMENTER_NAME_FORMAT, |
|
685 propertyDialog.getName()); |
|
686 config.setText(PROPERTY_DIALOG_INSTRUMENTER_TRACE_FORMAT, |
|
687 propertyDialog.getValue()); |
|
688 config |
|
689 .setText(PROPERTY_DIALOG_INSTRUMENTER_TEMPLATE, |
|
690 templateTitle); |
|
691 flagPrefix = PROPERTY_DIALOG_INSTRUMENTER_FLAG; |
|
692 config.setText(PROPERTY_DIALOG_INSTRUMENTER_TRACE_GROUP, |
|
693 propertyDialog.getTarget()); |
|
694 break; |
|
695 } |
|
696 return flagPrefix; |
|
697 } |
|
698 } |