author | dadubrow |
Wed, 01 Apr 2009 14:49:26 -0500 | |
changeset 20 | 5c466f93ffe1 |
parent 2 | d760517a8095 |
permissions | -rw-r--r-- |
2 | 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 |
* A generic table viewer tab for Symbian OS view, which is parent for many other tabs such as Processes Tab. |
|
17 |
* |
|
18 |
*/ |
|
19 |
package com.nokia.carbide.cpp.debug.kernelaware.ui; |
|
20 |
||
21 |
import org.eclipse.debug.core.DebugException; |
|
22 |
import org.eclipse.jface.action.*; |
|
23 |
import org.eclipse.jface.viewers.IOpenListener; |
|
24 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
25 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
26 |
import org.eclipse.jface.viewers.OpenEvent; |
|
27 |
import org.eclipse.jface.viewers.TableViewer; |
|
28 |
import org.eclipse.jface.viewers.Viewer; |
|
29 |
import org.eclipse.jface.viewers.ViewerSorter; |
|
30 |
import org.eclipse.swt.SWT; |
|
31 |
import org.eclipse.swt.events.*; |
|
32 |
import org.eclipse.swt.graphics.Image; |
|
33 |
import org.eclipse.swt.layout.GridData; |
|
34 |
import org.eclipse.swt.layout.GridLayout; |
|
35 |
import org.eclipse.swt.widgets.Composite; |
|
36 |
import org.eclipse.swt.widgets.Display; |
|
37 |
import org.eclipse.swt.widgets.Label; |
|
38 |
import org.eclipse.swt.widgets.TabFolder; |
|
39 |
import org.eclipse.swt.widgets.TabItem; |
|
40 |
import org.eclipse.swt.widgets.Table; |
|
41 |
import org.eclipse.swt.widgets.TableColumn; |
|
42 |
import org.eclipse.swt.widgets.Text; |
|
43 |
import org.eclipse.ui.views.properties.IPropertyDescriptor; |
|
44 |
||
45 |
import com.nokia.carbide.cpp.debug.kernelaware.OSDataManager; |
|
46 |
import com.nokia.carbide.cpp.debug.kernelaware.OSObject; |
|
47 |
import com.nokia.carbide.cpp.debug.kernelaware.OSObjectChunk; |
|
48 |
import com.nokia.carbide.cpp.debug.kernelaware.OSObjectLibrary; |
|
49 |
import com.nokia.carbide.cpp.debug.kernelaware.OSObjectProcess; |
|
50 |
import com.nokia.carbide.cpp.debug.kernelaware.OSObjectThread; |
|
51 |
||
52 |
import cwdbg.EclipseDEConstants; |
|
53 |
||
54 |
public class GenericTableTab { |
|
55 |
||
56 |
class MyTableDataProvider implements IStructuredContentProvider { |
|
57 |
||
58 |
/* |
|
59 |
* (non-Javadoc) |
|
60 |
* |
|
61 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
62 |
*/ |
|
63 |
public Object[] getElements(Object inputElement) { |
|
64 |
if (inputElement == null) |
|
65 |
return new Object[0]; |
|
66 |
||
67 |
if (inputElement instanceof OSDataManager) { |
|
68 |
OSDataManager osDM = (OSDataManager) inputElement; |
|
69 |
try { |
|
70 |
switch (objectType) { |
|
71 |
case EclipseDEConstants.J_OSObjectType_Process: |
|
72 |
return osDM.getProcesses(); |
|
73 |
case EclipseDEConstants.J_OSObjectType_Thread: |
|
74 |
return osDM.getThreads(); |
|
75 |
case EclipseDEConstants.J_OSObjectType_Chunk: |
|
76 |
return osDM.getChunks(); |
|
77 |
case EclipseDEConstants.J_OSObjectType_Library: |
|
78 |
return osDM.getLibraries(); |
|
79 |
default: |
|
80 |
assert (false); |
|
81 |
break; |
|
82 |
} |
|
83 |
} catch (DebugException e) { |
|
84 |
e.printStackTrace(); |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
return new Object[0]; |
|
89 |
} |
|
90 |
||
91 |
/* |
|
92 |
* (non-Javadoc) |
|
93 |
* |
|
94 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
95 |
*/ |
|
96 |
public void dispose() { |
|
97 |
} |
|
98 |
||
99 |
/* |
|
100 |
* (non-Javadoc) |
|
101 |
* |
|
102 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, |
|
103 |
* java.lang.Object, java.lang.Object) |
|
104 |
*/ |
|
105 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
106 |
if (newInput == null) |
|
107 |
osDataManager = null; |
|
108 |
else if (newInput instanceof OSDataManager) |
|
109 |
osDataManager = (OSDataManager) newInput; |
|
110 |
} |
|
111 |
||
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* Label provider for table. |
|
116 |
*/ |
|
117 |
class MyTableLabelProvider extends OSViewLabelProvider implements |
|
118 |
ITableLabelProvider { |
|
119 |
||
120 |
MyTableLabelProvider(Viewer viewer) { |
|
121 |
super(viewer); |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* @see ITableLabelProvider#getColumnText(Object, int) |
|
126 |
*/ |
|
127 |
public String getColumnText(Object element, int columnIndex) { |
|
128 |
String value = null; |
|
129 |
||
130 |
if (element instanceof OSObject) { |
|
131 |
OSObject item = (OSObject) element; |
|
132 |
if (columnIndex < sortablePropertyDescriptors.length) { |
|
133 |
value = item |
|
134 |
.getFormatedPropertyValue(sortablePropertyDescriptors[columnIndex] |
|
135 |
.getId()); |
|
136 |
||
137 |
if (value == null) { |
|
138 |
// the property is not available. Hide the column from |
|
139 |
// the user. This may happen when, for instance, we |
|
140 |
// switch from a stop mode machine to a run mode machine |
|
141 |
columns[columnIndex].setWidth(0); |
|
142 |
columns[columnIndex].setResizable(false); |
|
143 |
} else { |
|
144 |
// make sure corresponding column is visible. This may |
|
145 |
// happen when we switch from a run mode machine to a stop |
|
146 |
// mode machine. |
|
147 |
if (columns[columnIndex].getResizable() == false) { |
|
148 |
columns[columnIndex].setResizable(true); |
|
149 |
// This may cause a bit of flickering, but no big |
|
150 |
// deal. |
|
151 |
columns[columnIndex].pack(); |
|
152 |
} |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
return value; |
|
158 |
} |
|
159 |
||
160 |
/** |
|
161 |
* @see ITableLabelProvider#getColumnImage(Object, int) |
|
162 |
*/ |
|
163 |
public Image getColumnImage(Object element, int columnIndex) { |
|
164 |
return null; |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
private IPropertyDescriptor[] sortablePropertyDescriptors = null; |
|
169 |
||
170 |
private int objectType; |
|
171 |
||
172 |
private Text filterText; |
|
173 |
||
174 |
private ToolBarManager clearFilterToolBar; |
|
175 |
||
176 |
private ItemFilter nameFilter = new ItemFilter(); |
|
177 |
||
178 |
private TableViewer viewer; |
|
179 |
||
180 |
private TableColumn[] columns = null; |
|
181 |
||
182 |
private int sortedColumnIndex = 0; |
|
183 |
||
184 |
// This is the model input for this tab. Refer to where it's set. |
|
185 |
@SuppressWarnings(value = { "unused" }) //$NON-NLS-1$ |
|
186 |
private OSDataManager osDataManager = null; |
|
187 |
||
188 |
public GenericTableTab(int objectType) { |
|
189 |
this.objectType = objectType; |
|
190 |
||
191 |
switch (objectType) { |
|
192 |
case EclipseDEConstants.J_OSObjectType_Process: |
|
193 |
sortablePropertyDescriptors = OSObjectProcess |
|
194 |
.getSortablePropertyDescriptorList(); |
|
195 |
break; |
|
196 |
||
197 |
case EclipseDEConstants.J_OSObjectType_Thread: |
|
198 |
sortablePropertyDescriptors = OSObjectThread |
|
199 |
.getSortablePropertyDescriptorList(); |
|
200 |
break; |
|
201 |
||
202 |
case EclipseDEConstants.J_OSObjectType_Chunk: |
|
203 |
sortablePropertyDescriptors = OSObjectChunk |
|
204 |
.getSortablePropertyDescriptorList(); |
|
205 |
break; |
|
206 |
||
207 |
case EclipseDEConstants.J_OSObjectType_Library: |
|
208 |
sortablePropertyDescriptors = OSObjectLibrary |
|
209 |
.getSortablePropertyDescriptorList(); |
|
210 |
break; |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
public TableViewer createControl(TabFolder tabFolder, TabItem tabItem) { |
|
215 |
final Composite composite = new Composite(tabFolder, SWT.NONE); |
|
216 |
final GridLayout gridLayout = new GridLayout(); |
|
217 |
gridLayout.numColumns = 3; |
|
218 |
gridLayout.marginWidth = 0; |
|
219 |
gridLayout.marginTop = 5; |
|
220 |
gridLayout.marginHeight = 0; |
|
221 |
composite.setLayout(gridLayout); |
|
222 |
tabItem.setControl(composite); |
|
223 |
||
224 |
final Label filterLabel = new Label(composite, SWT.NONE); |
|
225 |
final GridData gridData = new GridData(SWT.RIGHT, SWT.CENTER, false, false); |
|
226 |
gridData.horizontalIndent = 5; |
|
227 |
filterLabel.setLayoutData(gridData); |
|
228 |
filterLabel.setText(Messages.getString("SymbianOSView.NameFilterLabel")); //$NON-NLS-1$ |
|
229 |
||
230 |
filterText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.CANCEL); |
|
231 |
filterText.setText(Messages.getString("SymbianOSView.NameFilterInitialText")); //$NON-NLS-1$ |
|
232 |
filterText.setToolTipText(Messages.getString("SymbianOSView.NameFilterToolTip")); //$NON-NLS-1$ |
|
233 |
final GridData gd_filterText = new GridData(SWT.LEFT, SWT.CENTER, false, false); |
|
234 |
gd_filterText.widthHint = 200; |
|
235 |
filterText.setLayoutData(gd_filterText); |
|
236 |
filterText.addFocusListener(new FocusAdapter() { |
|
237 |
/* |
|
238 |
* (non-Javadoc) |
|
239 |
* |
|
240 |
* @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) |
|
241 |
*/ |
|
242 |
public void focusGained(FocusEvent e) { |
|
243 |
/* |
|
244 |
* Running in an asyncExec because the selectAll() does not |
|
245 |
* appear to work when using mouse to give focus to text. |
|
246 |
*/ |
|
247 |
Display display = filterText.getDisplay(); |
|
248 |
display.asyncExec(new Runnable() { |
|
249 |
public void run() { |
|
250 |
if (!filterText.isDisposed()) { |
|
251 |
filterText.selectAll(); |
|
252 |
} |
|
253 |
} |
|
254 |
}); |
|
255 |
} |
|
256 |
}); |
|
257 |
||
258 |
filterText.addModifyListener(new ModifyListener() { |
|
259 |
public void modifyText(ModifyEvent e) { |
|
260 |
FilterItems(); |
|
261 |
clearFilterToolBar.getControl().setVisible(filterText.getText().length() > 0); |
|
262 |
} |
|
263 |
}); |
|
264 |
clearFilterToolBar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL); |
|
265 |
clearFilterToolBar.createControl(composite); |
|
266 |
||
267 |
IAction clearTextAction = new Action("", IAction.AS_PUSH_BUTTON) {//$NON-NLS-1$ |
|
268 |
public void run() { |
|
269 |
filterText.setText(""); //$NON-NLS-1$ |
|
270 |
FilterItems(); |
|
271 |
} |
|
272 |
}; |
|
273 |
clearTextAction.setToolTipText(Messages.getString("SymbianOSView.ClearToolTip")); //$NON-NLS-1$ |
|
274 |
clearTextAction.setImageDescriptor(SymbianOSView.clearImageDesc); |
|
275 |
clearTextAction.setDisabledImageDescriptor(SymbianOSView.clearImageDesc); |
|
276 |
clearFilterToolBar.add(clearTextAction); |
|
277 |
clearFilterToolBar.update(false); |
|
278 |
// initially there is no text to clear |
|
279 |
clearFilterToolBar.getControl().setVisible(false); |
|
280 |
||
281 |
viewer = new TableViewer(composite, SWT.FULL_SELECTION); |
|
282 |
viewer.addOpenListener(new IOpenListener() { |
|
283 |
public void open(OpenEvent event) { |
|
284 |
return; |
|
285 |
} |
|
286 |
}); |
|
287 |
viewer.setContentProvider(new MyTableDataProvider()); |
|
288 |
viewer.setLabelProvider(new MyTableLabelProvider(viewer)); |
|
289 |
viewer.setInput(new Object()); |
|
290 |
viewer.addFilter(nameFilter); |
|
291 |
||
292 |
Table table = viewer.getTable(); |
|
293 |
table.setLinesVisible(true); |
|
294 |
table.setHeaderVisible(true); |
|
295 |
final GridData gridData_2 = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1); |
|
296 |
table.setLayoutData(gridData_2); |
|
297 |
||
298 |
int columnNum = sortablePropertyDescriptors.length; |
|
299 |
||
300 |
columns = new TableColumn[columnNum]; |
|
301 |
||
302 |
for (int i = 0; i < columnNum; i++) { |
|
303 |
columns[i] = new TableColumn(table, SWT.CENTER); |
|
304 |
final int columnIndex = i; |
|
305 |
final String propID = (String) sortablePropertyDescriptors[i] |
|
306 |
.getId(); |
|
307 |
columns[i].addSelectionListener(new SelectionAdapter() { |
|
308 |
public void widgetSelected(SelectionEvent e) { |
|
309 |
sortByProperty(propID, columnIndex); |
|
310 |
} |
|
311 |
}); |
|
312 |
columns[i].setWidth(118); |
|
313 |
columns[i].setAlignment(SWT.LEFT); |
|
314 |
columns[i].setText((String) sortablePropertyDescriptors[i] |
|
315 |
.getDisplayName()); |
|
316 |
} |
|
317 |
||
20
5c466f93ffe1
[Bug 8691] Add code to allow access to functional testing of SymbianOSView from automation.utils plugin
dadubrow
parents:
2
diff
changeset
|
318 |
viewer.setData("controller", this); //$NON-NLS-1$ |
2 | 319 |
return viewer; |
320 |
} |
|
321 |
||
322 |
private void sortByProperty(final String propertyID, final int columnIndex) { |
|
323 |
int sortDirection = SWT.UP; |
|
324 |
if (sortedColumnIndex == columnIndex) { |
|
325 |
if (viewer.getTable().getSortDirection() == SWT.UP) |
|
326 |
sortDirection = SWT.DOWN; |
|
327 |
} |
|
328 |
||
329 |
// Put an "arrow" mark on the current sorted column. |
|
330 |
sortedColumnIndex = columnIndex; |
|
331 |
viewer.getTable().setSortColumn(columns[sortedColumnIndex]); |
|
332 |
viewer.getTable().setSortDirection(sortDirection); |
|
333 |
||
334 |
final int f_sortDirection = sortDirection; |
|
335 |
viewer.setSorter(new ViewerSorter() { |
|
336 |
public int compare(Viewer viewer, Object e1, Object e2) { |
|
337 |
||
338 |
if (f_sortDirection == SWT.DOWN) // reverse sorting |
|
339 |
{ |
|
340 |
Object tmp = e1; |
|
341 |
e1 = e2; |
|
342 |
e2 = tmp; |
|
343 |
} |
|
344 |
||
345 |
if ((e1 instanceof OSObject) && (e2 instanceof OSObject)) { |
|
346 |
OSObject left = (OSObject) e1; |
|
347 |
OSObject right = (OSObject) e2; |
|
348 |
Object leftProp = left.getRawPropertyValue(propertyID); |
|
349 |
Object rightProp = right.getRawPropertyValue(propertyID); |
|
350 |
||
351 |
if (leftProp instanceof String) |
|
352 |
return ((String) leftProp) |
|
353 |
.compareToIgnoreCase((String) rightProp); |
|
354 |
else if (leftProp instanceof Integer) |
|
355 |
return ((Integer) leftProp) |
|
356 |
.compareTo((Integer) rightProp); |
|
357 |
else if (leftProp instanceof Long) |
|
358 |
return ((Long) leftProp).compareTo((Long) rightProp); |
|
359 |
else |
|
360 |
assert (false); // unsupported data type. |
|
361 |
} |
|
362 |
||
363 |
return super.compare(viewer, e1, e2); |
|
364 |
} |
|
365 |
||
366 |
public boolean isSorterProperty(Object element, String property) { |
|
367 |
return true; |
|
368 |
} |
|
369 |
}); |
|
370 |
} |
|
371 |
||
372 |
private void FilterItems() { |
|
373 |
String pattern = filterText.getText(); |
|
374 |
||
375 |
if (pattern.length() == 0) |
|
376 |
// This will call viewer.refresh(). |
|
377 |
viewer.removeFilter(nameFilter); |
|
378 |
else { |
|
379 |
nameFilter.setPattern(pattern); |
|
380 |
||
381 |
if (viewer.getFilters().length == 0) |
|
382 |
// This will call viewer.refresh(). |
|
383 |
viewer.addFilter(nameFilter); |
|
384 |
else |
|
385 |
viewer.refresh(); |
|
386 |
} |
|
387 |
} |
|
20
5c466f93ffe1
[Bug 8691] Add code to allow access to functional testing of SymbianOSView from automation.utils plugin
dadubrow
parents:
2
diff
changeset
|
388 |
|
5c466f93ffe1
[Bug 8691] Add code to allow access to functional testing of SymbianOSView from automation.utils plugin
dadubrow
parents:
2
diff
changeset
|
389 |
public Text getFilterText() { |
5c466f93ffe1
[Bug 8691] Add code to allow access to functional testing of SymbianOSView from automation.utils plugin
dadubrow
parents:
2
diff
changeset
|
390 |
return filterText; |
5c466f93ffe1
[Bug 8691] Add code to allow access to functional testing of SymbianOSView from automation.utils plugin
dadubrow
parents:
2
diff
changeset
|
391 |
} |
2 | 392 |
} |