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