|
1 /* |
|
2 * Copyright (c) 2009-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 * Composite for target label and combo box |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.view; |
|
20 |
|
21 import java.util.Iterator; |
|
22 |
|
23 import org.eclipse.swt.SWT; |
|
24 import org.eclipse.swt.events.ModifyListener; |
|
25 import org.eclipse.swt.events.SelectionListener; |
|
26 import org.eclipse.swt.widgets.Combo; |
|
27 import org.eclipse.swt.widgets.Composite; |
|
28 import org.eclipse.swt.widgets.Label; |
|
29 |
|
30 import com.nokia.tracebuilder.engine.SoftwareComponent; |
|
31 import com.nokia.tracebuilder.engine.TraceBuilderGlobals; |
|
32 import com.nokia.tracebuilder.engine.TraceObjectPropertyDialog; |
|
33 import com.nokia.tracebuilder.engine.rules.RuleUtils; |
|
34 import com.nokia.tracebuilder.model.TraceConstantTable; |
|
35 import com.nokia.tracebuilder.project.FormattingUtils; |
|
36 import com.nokia.tracebuilder.project.GroupNameHandlerBase; |
|
37 |
|
38 /** |
|
39 * Composite for target label and combo box |
|
40 * |
|
41 */ |
|
42 final class PropertyDialogUITarget extends PropertyDialogComposite { |
|
43 |
|
44 /** |
|
45 * Target label |
|
46 */ |
|
47 private Label targetLabel = null; |
|
48 |
|
49 /** |
|
50 * Target selector |
|
51 */ |
|
52 private Combo targetCombo = null; |
|
53 |
|
54 /** |
|
55 * Property dialog UI |
|
56 */ |
|
57 private PropertyDialogUI dialogUI; |
|
58 |
|
59 /** |
|
60 * Constructor |
|
61 * |
|
62 * @param parent |
|
63 * parent composite |
|
64 * @param uiType |
|
65 * the type of UI |
|
66 * @param modifyListener |
|
67 * combobox text change listener |
|
68 * @param selectionListener |
|
69 * combobox selection change listener |
|
70 */ |
|
71 PropertyDialogUITarget(Composite parent, int uiType, |
|
72 ModifyListener modifyListener, SelectionListener selectionListener) { |
|
73 super(parent); |
|
74 this.dialogUI = (PropertyDialogUI) parent; |
|
75 create(uiType, modifyListener, selectionListener); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Creates the label and combo box |
|
80 * |
|
81 * @param uiType |
|
82 * the UI type |
|
83 * @param modifyListener |
|
84 * combobox text change listener |
|
85 * @param selectionListener |
|
86 * combobox selection change listener |
|
87 */ |
|
88 private void create(int uiType, ModifyListener modifyListener, |
|
89 SelectionListener selectionListener) { |
|
90 targetLabel = new Label(getParent(), SWT.NONE); |
|
91 |
|
92 if (uiType == TraceObjectPropertyDialog.SELECT_COMPONENT) { |
|
93 targetCombo = new Combo(getParent(), SWT.READ_ONLY); |
|
94 } else { |
|
95 targetCombo = new Combo(getParent(), SWT.NONE); |
|
96 } |
|
97 |
|
98 int selid = 0; |
|
99 String text; |
|
100 if (uiType == TraceObjectPropertyDialog.SELECT_COMPONENT) { |
|
101 text = Messages |
|
102 .getString("PropertyDialogUI.SelectComponentNameLabel"); //$NON-NLS-1$ |
|
103 Iterator<SoftwareComponent> components = TraceBuilderGlobals |
|
104 .getSoftwareComponents(); |
|
105 while (components.hasNext()) { |
|
106 SoftwareComponent component = components.next(); |
|
107 targetCombo.add(component.getName()); |
|
108 } |
|
109 } else if (uiType == TraceObjectPropertyDialog.ADD_CONSTANT) { |
|
110 text = Messages |
|
111 .getString("PropertyDialogUITarget.AddConstantTargetLabel"); //$NON-NLS-1$ |
|
112 Iterator<TraceConstantTable> tables = TraceBuilderGlobals |
|
113 .getTraceModel().getConstantTables(); |
|
114 while (tables.hasNext()) { |
|
115 targetCombo.add(tables.next().getName()); |
|
116 } |
|
117 } else { |
|
118 text = Messages.getString("PropertyDialogUI.AddTraceTargetLabel"); //$NON-NLS-1$ |
|
119 Iterator<String> groups = FormattingUtils |
|
120 .getGroupNames(TraceBuilderGlobals.getTraceModel()); |
|
121 while (groups.hasNext()) { |
|
122 String group = groups.next(); |
|
123 |
|
124 // TRACE_STATE and TRACE_PERFORMACE group names are not added |
|
125 // to combo, those can be used only via templates |
|
126 GroupNameHandlerBase groupNameHandler = TraceBuilderGlobals.getGroupNameHandler(); |
|
127 String[] defaultGroups = groupNameHandler.getDefaultGroups(); |
|
128 if (group != defaultGroups[groupNameHandler.getStateGroupIdIndex()] |
|
129 && group != defaultGroups[groupNameHandler.getPerformanceGroupIdIndex()]) { |
|
130 targetCombo.add(group); |
|
131 } |
|
132 } |
|
133 } |
|
134 |
|
135 targetLabel.setText(text); |
|
136 targetCombo.select(selid); |
|
137 targetCombo.addSelectionListener(selectionListener); |
|
138 targetCombo.addModifyListener(modifyListener); |
|
139 setFieldButtonLayoutData(targetCombo, null); |
|
140 } |
|
141 |
|
142 /** |
|
143 * Gets the target trace object |
|
144 * |
|
145 * @return the target |
|
146 */ |
|
147 String getTarget() { |
|
148 return targetCombo.getText(); |
|
149 } |
|
150 |
|
151 /** |
|
152 * Sets the target object |
|
153 * |
|
154 * @param target |
|
155 * the new target |
|
156 */ |
|
157 void setTarget(String target) { |
|
158 int found = -1; |
|
159 for (int i = 0; i < targetCombo.getItemCount() && found == -1; i++) { |
|
160 if (targetCombo.getItem(i).equals(target)) { |
|
161 found = i; |
|
162 } |
|
163 } |
|
164 int uiType = dialogUI.getUiType(); |
|
165 if (found >= 0) { |
|
166 targetCombo.select(found); |
|
167 } else if (uiType == TraceObjectPropertyDialog.ADD_PARAMETER |
|
168 || uiType == TraceObjectPropertyDialog.ADD_TRACE |
|
169 || uiType == TraceObjectPropertyDialog.INSTRUMENTER) { |
|
170 int templateIndex = dialogUI.templateComposite.getTemplateIndex(); |
|
171 GroupNameHandlerBase groupNameHandler = TraceBuilderGlobals.getGroupNameHandler(); |
|
172 String[] defaultGroups = groupNameHandler.getDefaultGroups(); |
|
173 if (((!target |
|
174 .equals(defaultGroups[groupNameHandler.getStateGroupIdIndex()]) && !target |
|
175 .equals(defaultGroups[groupNameHandler.getPerformanceGroupIdIndex()])) && templateIndex == 0) |
|
176 || (target |
|
177 .equals(defaultGroups[groupNameHandler.getStateGroupIdIndex()]) && templateIndex == RuleUtils.TYPE_STATE_TRACE + 1) |
|
178 || (target |
|
179 .equals(defaultGroups[groupNameHandler.getPerformanceGroupIdIndex()]) && templateIndex == RuleUtils.TYPE_PERF_EVENT + 1) |
|
180 || (target |
|
181 .equals(defaultGroups[groupNameHandler.getFlowGroupIdIndex()]) && templateIndex == RuleUtils.TYPE_ENTRY_EXIT + 1)) { |
|
182 targetCombo.setText(target); |
|
183 } else { |
|
184 targetCombo.select(groupNameHandler.getNormalGroupIdIndex() - 1); |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 /** |
|
190 * Enables / disables the target field |
|
191 * |
|
192 * @param flag |
|
193 * new enabled state |
|
194 */ |
|
195 void setEnabled(boolean flag) { |
|
196 targetCombo.setEnabled(flag); |
|
197 } |
|
198 } |