trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/dialog/SearchDialog.java
changeset 11 5b9d4d8641ce
equal deleted inserted replaced
10:ed1c9f64298a 11:5b9d4d8641ce
       
     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  * Search Dialog class
       
    17  *
       
    18  */
       
    19 package com.nokia.traceviewer.dialog;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 import java.util.List;
       
    23 import java.util.regex.PatternSyntaxException;
       
    24 
       
    25 import org.eclipse.jface.dialogs.IDialogConstants;
       
    26 import org.eclipse.jface.text.BadLocationException;
       
    27 import org.eclipse.jface.text.FindReplaceDocumentAdapter;
       
    28 import org.eclipse.jface.text.IDocument;
       
    29 import org.eclipse.jface.text.IRegion;
       
    30 import org.eclipse.jface.text.TextViewer;
       
    31 import org.eclipse.swt.SWT;
       
    32 import org.eclipse.swt.custom.StyledText;
       
    33 import org.eclipse.swt.events.KeyAdapter;
       
    34 import org.eclipse.swt.events.KeyEvent;
       
    35 import org.eclipse.swt.events.ModifyEvent;
       
    36 import org.eclipse.swt.events.ModifyListener;
       
    37 import org.eclipse.swt.events.SelectionAdapter;
       
    38 import org.eclipse.swt.events.SelectionEvent;
       
    39 import org.eclipse.swt.layout.GridData;
       
    40 import org.eclipse.swt.layout.GridLayout;
       
    41 import org.eclipse.swt.widgets.Button;
       
    42 import org.eclipse.swt.widgets.Combo;
       
    43 import org.eclipse.swt.widgets.Display;
       
    44 import org.eclipse.swt.widgets.Group;
       
    45 import org.eclipse.swt.widgets.Label;
       
    46 import org.eclipse.swt.widgets.ProgressBar;
       
    47 import org.eclipse.swt.widgets.Shell;
       
    48 import org.eclipse.ui.PlatformUI;
       
    49 
       
    50 import com.nokia.traceviewer.TraceViewerHelpContextIDs;
       
    51 import com.nokia.traceviewer.engine.StateHolder;
       
    52 import com.nokia.traceviewer.engine.TraceInformation;
       
    53 import com.nokia.traceviewer.engine.TraceProperties;
       
    54 import com.nokia.traceviewer.engine.TraceViewerGlobals;
       
    55 import com.nokia.traceviewer.engine.TraceViewerTraceViewInterface;
       
    56 import com.nokia.traceviewer.engine.dataprocessor.SearchProperties;
       
    57 import com.nokia.traceviewer.engine.dataprocessor.SearchUtils;
       
    58 import com.nokia.traceviewer.engine.dataprocessor.TimestampParser;
       
    59 
       
    60 /**
       
    61  * Search Dialog class
       
    62  * 
       
    63  */
       
    64 public final class SearchDialog extends BaseDialog {
       
    65 
       
    66 	/**
       
    67 	 * Display used to get UI thread
       
    68 	 */
       
    69 	private final Display display;
       
    70 
       
    71 	/**
       
    72 	 * UI Label for line count field
       
    73 	 */
       
    74 	private Label lineCountLabel;
       
    75 
       
    76 	/**
       
    77 	 * UI Combo box for find texts
       
    78 	 */
       
    79 	private Combo findCombo;
       
    80 
       
    81 	/**
       
    82 	 * UI Find button
       
    83 	 */
       
    84 	private Button searchButton;
       
    85 
       
    86 	/**
       
    87 	 * UI Checkbox for match whole word
       
    88 	 */
       
    89 	private Button matchWholeWordCheckBox;
       
    90 
       
    91 	/**
       
    92 	 * UI Checkbox for match case
       
    93 	 */
       
    94 	private Button matchCaseCheckBox;
       
    95 
       
    96 	/**
       
    97 	 * UI Checkbox for regular expression search
       
    98 	 */
       
    99 	private Button regularExpressionCheckBox;
       
   100 
       
   101 	/**
       
   102 	 * UI Radio button for up direction
       
   103 	 */
       
   104 	private Button upDirectionRadioButton;
       
   105 
       
   106 	/**
       
   107 	 * UI Radio button for down direction
       
   108 	 */
       
   109 	private Button downDirectionRadioButton;
       
   110 
       
   111 	/**
       
   112 	 * UI Button for stop search
       
   113 	 */
       
   114 	private Button stopSearchButton;
       
   115 
       
   116 	/**
       
   117 	 * Progressbar showing file position
       
   118 	 */
       
   119 	private ProgressBar progressBar;
       
   120 
       
   121 	/**
       
   122 	 * Reference to View
       
   123 	 */
       
   124 	private final TraceViewerTraceViewInterface view;
       
   125 
       
   126 	/**
       
   127 	 * Search properties used when searching
       
   128 	 */
       
   129 	private final SearchProperties searchProperties;
       
   130 
       
   131 	/**
       
   132 	 * Widget used in searching
       
   133 	 */
       
   134 	private StyledText widget;
       
   135 
       
   136 	/**
       
   137 	 * Document used by viewer
       
   138 	 */
       
   139 	private IDocument document;
       
   140 
       
   141 	/**
       
   142 	 * Contains combo list items that are saved and restored
       
   143 	 */
       
   144 	private String[] comboList;
       
   145 
       
   146 	/**
       
   147 	 * Finder object
       
   148 	 */
       
   149 	private FindReplaceDocumentAdapter finder;
       
   150 
       
   151 	/**
       
   152 	 * Checks if DataReader was paused when we entered dialog -> Don't pause
       
   153 	 * again and don't unpause in exit
       
   154 	 */
       
   155 	private boolean wasPausedWhenEntered;
       
   156 
       
   157 	/**
       
   158 	 * Key listener for this dialog
       
   159 	 */
       
   160 	private KeyAdapter searchDialogKeyListener;
       
   161 
       
   162 	/**
       
   163 	 * Constructor
       
   164 	 * 
       
   165 	 * @param parent
       
   166 	 *            parent shell
       
   167 	 * @param view
       
   168 	 *            view reference
       
   169 	 */
       
   170 	public SearchDialog(Shell parent, TraceViewerTraceViewInterface view) {
       
   171 		// Pass the default styles here
       
   172 		super(parent, SWT.DIALOG_TRIM | SWT.MODELESS | SWT.MIN);
       
   173 		this.view = view;
       
   174 		this.display = view.getViewer().getControl().getDisplay();
       
   175 		searchProperties = new SearchProperties();
       
   176 	}
       
   177 
       
   178 	/*
       
   179 	 * (non-Javadoc)
       
   180 	 * 
       
   181 	 * @see com.nokia.traceviewer.dialog.BaseDialog#close()
       
   182 	 */
       
   183 	@Override
       
   184 	public boolean close() {
       
   185 		boolean close = super.close();
       
   186 
       
   187 		// Stop the search and kill the search data reader
       
   188 		TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   189 				.getSearchProcessor().stopSearch(true);
       
   190 		TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   191 				.getSearchProcessor().shutdownSearchReader();
       
   192 
       
   193 		// Unpause
       
   194 		if (!wasPausedWhenEntered) {
       
   195 			TraceViewerGlobals.getTraceViewer().getView().getActionFactory()
       
   196 					.getPauseAction().run();
       
   197 		}
       
   198 
       
   199 		return close;
       
   200 	}
       
   201 
       
   202 	/*
       
   203 	 * (non-Javadoc)
       
   204 	 * 
       
   205 	 * @see com.nokia.traceviewer.dialog.BaseDialog#saveSettings()
       
   206 	 */
       
   207 	@Override
       
   208 	protected void saveSettings() {
       
   209 
       
   210 		// Save position
       
   211 		super.saveSettings();
       
   212 
       
   213 		// Save combo list items if dialog is not disposed
       
   214 		if (findCombo != null && !findCombo.isDisposed()) {
       
   215 			comboList = new String[findCombo.getItemCount()];
       
   216 			for (int i = 0; i < findCombo.getItemCount(); i++) {
       
   217 				comboList[i] = findCombo.getItem(i);
       
   218 			}
       
   219 			searchProperties
       
   220 					.setWholeWord(matchWholeWordCheckBox.getSelection());
       
   221 			searchProperties.setCaseSensitive(matchCaseCheckBox.getSelection());
       
   222 			searchProperties
       
   223 					.setRegExp(regularExpressionCheckBox.getSelection());
       
   224 			if (upDirectionRadioButton.getSelection()) {
       
   225 				searchProperties.setSearchingForward(false);
       
   226 			} else {
       
   227 				searchProperties.setSearchingForward(true);
       
   228 			}
       
   229 		}
       
   230 	}
       
   231 
       
   232 	/*
       
   233 	 * (non-Javadoc)
       
   234 	 * 
       
   235 	 * @see com.nokia.traceviewer.dialog.BaseDialog#restoreSettings()
       
   236 	 */
       
   237 	@Override
       
   238 	protected void restoreSettings() {
       
   239 		super.restoreSettings();
       
   240 
       
   241 		// Restore other settings
       
   242 		if (comboList != null) {
       
   243 			findCombo.setItems(comboList);
       
   244 		}
       
   245 		matchWholeWordCheckBox.setSelection(searchProperties.isWholeWord());
       
   246 		if (searchProperties.isWholeWord()) {
       
   247 			regularExpressionCheckBox.setEnabled(false);
       
   248 		}
       
   249 		matchCaseCheckBox.setSelection(searchProperties.isCaseSensitive());
       
   250 		regularExpressionCheckBox.setSelection(searchProperties.isRegExp());
       
   251 		if (searchProperties.isRegExp()) {
       
   252 			matchWholeWordCheckBox.setEnabled(false);
       
   253 		}
       
   254 		upDirectionRadioButton.setSelection(!searchProperties
       
   255 				.isSearchingForward());
       
   256 		downDirectionRadioButton.setSelection(searchProperties
       
   257 				.isSearchingForward());
       
   258 
       
   259 		// Set text to be what was last searched for
       
   260 		if (comboList != null && comboList.length > 0) {
       
   261 			findCombo.setText(comboList[0]);
       
   262 		}
       
   263 
       
   264 		// Set default button
       
   265 		getShell().setDefaultButton(searchButton);
       
   266 
       
   267 		// Set processor not to stop when next search is started
       
   268 		TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   269 				.getSearchProcessor().stopSearch(false);
       
   270 	}
       
   271 
       
   272 	/*
       
   273 	 * (non-Javadoc)
       
   274 	 * 
       
   275 	 * @see com.nokia.traceviewer.dialog.BaseDialog#createShell()
       
   276 	 */
       
   277 	@Override
       
   278 	protected void createDialogContents() {
       
   279 		// Pause the datareader if it's not paused already
       
   280 		wasPausedWhenEntered = TraceViewerGlobals.getTraceViewer()
       
   281 				.getDataReaderAccess().getMainDataReader().isPaused();
       
   282 		if (!wasPausedWhenEntered) {
       
   283 			TraceViewerGlobals.getTraceViewer().getView().getActionFactory()
       
   284 					.getPauseAction().run();
       
   285 		}
       
   286 
       
   287 		// Create needed items
       
   288 		TextViewer viewer = view.getViewer();
       
   289 		widget = viewer.getTextWidget();
       
   290 		document = viewer.getDocument();
       
   291 		finder = new FindReplaceDocumentAdapter(document);
       
   292 
       
   293 		// Shell and Composite
       
   294 		GridLayout shellGridLayout = new GridLayout();
       
   295 		shellGridLayout.numColumns = 3;
       
   296 		getShell().setText(Messages.getString("SearchDialog.DialogTitle")); //$NON-NLS-1$
       
   297 		composite.setLayout(shellGridLayout);
       
   298 		Label findLabel = new Label(composite, SWT.NONE);
       
   299 		findLabel.setText(Messages.getString("SearchDialog.FindText")); //$NON-NLS-1$
       
   300 
       
   301 		// Create key listener
       
   302 		createKeyListener();
       
   303 
       
   304 		// Create find combo
       
   305 		GridData findComboGridData = new GridData();
       
   306 		findComboGridData.widthHint = 280;
       
   307 		findCombo = new Combo(composite, SWT.NONE);
       
   308 		findCombo.setLayoutData(findComboGridData);
       
   309 		findCombo.setToolTipText(Messages
       
   310 				.getString("SearchDialog.FindComboToolTip")); //$NON-NLS-1$
       
   311 		findCombo.addKeyListener(searchDialogKeyListener);
       
   312 
       
   313 		// Search Button
       
   314 		GridData searchButtonGridData = new GridData();
       
   315 		searchButtonGridData.widthHint = 75;
       
   316 		searchButtonGridData.heightHint = 25;
       
   317 		searchButtonGridData.horizontalAlignment = GridData.END;
       
   318 		searchButton = new Button(composite, SWT.NONE);
       
   319 		searchButton.setText(Messages
       
   320 				.getString("SearchDialog.SearchButtonText")); //$NON-NLS-1$
       
   321 		searchButton.setToolTipText(Messages
       
   322 				.getString("SearchDialog.SearchButtonToolTip")); //$NON-NLS-1$
       
   323 		searchButton.setLayoutData(searchButtonGridData);
       
   324 
       
   325 		// Match whole word Checkbox
       
   326 		GridData matchWholeWordGridData = new GridData();
       
   327 		matchWholeWordGridData.horizontalSpan = 2;
       
   328 		matchWholeWordGridData.verticalAlignment = GridData.END;
       
   329 		matchWholeWordGridData.horizontalAlignment = GridData.BEGINNING;
       
   330 		matchWholeWordCheckBox = new Button(composite, SWT.CHECK);
       
   331 		matchWholeWordCheckBox.setText(Messages
       
   332 				.getString("SearchDialog.MatchWholeWordText")); //$NON-NLS-1$
       
   333 		matchWholeWordCheckBox.setToolTipText(Messages
       
   334 				.getString("SearchDialog.MatchWholeWordToolTip")); //$NON-NLS-1$
       
   335 		matchWholeWordCheckBox.setLayoutData(matchWholeWordGridData);
       
   336 
       
   337 		// Stop Search Button
       
   338 		GridData stopSeachButtonGridData = new GridData();
       
   339 		stopSeachButtonGridData.widthHint = 75;
       
   340 		stopSeachButtonGridData.heightHint = 25;
       
   341 		stopSeachButtonGridData.horizontalAlignment = GridData.END;
       
   342 		stopSearchButton = new Button(composite, SWT.NONE);
       
   343 		stopSearchButton.setText(Messages
       
   344 				.getString("SearchDialog.StopButtonText")); //$NON-NLS-1$
       
   345 		stopSearchButton.setToolTipText(Messages
       
   346 				.getString("SearchDialog.StopButtonToolTip")); //$NON-NLS-1$
       
   347 		stopSearchButton.setLayoutData(stopSeachButtonGridData);
       
   348 		stopSearchButton.setEnabled(false);
       
   349 
       
   350 		// Match Case Checkbox
       
   351 		GridData matchCaseCheckBoxGridData = new GridData();
       
   352 		matchCaseCheckBoxGridData.horizontalSpan = 2;
       
   353 		matchCaseCheckBox = new Button(composite, SWT.CHECK);
       
   354 		matchCaseCheckBox.setText(Messages
       
   355 				.getString("SearchDialog.MatchCaseText")); //$NON-NLS-1$
       
   356 		matchCaseCheckBox.setToolTipText(Messages
       
   357 				.getString("SearchDialog.MatchCaseToolTip")); //$NON-NLS-1$
       
   358 		matchCaseCheckBox.setLayoutData(matchCaseCheckBoxGridData);
       
   359 
       
   360 		// Regular Expression CheckBox
       
   361 		GridData regularExpressionCheckBoxGridData = new GridData();
       
   362 		regularExpressionCheckBoxGridData.horizontalSpan = 2;
       
   363 		regularExpressionCheckBoxGridData.verticalAlignment = GridData.BEGINNING;
       
   364 		regularExpressionCheckBoxGridData.horizontalAlignment = GridData.BEGINNING;
       
   365 		regularExpressionCheckBox = new Button(composite, SWT.CHECK);
       
   366 		regularExpressionCheckBox.setText(Messages
       
   367 				.getString("SearchDialog.RegExpText")); //$NON-NLS-1$
       
   368 		regularExpressionCheckBox.setToolTipText(Messages
       
   369 				.getString("SearchDialog.RegExpToolTip")); //$NON-NLS-1$
       
   370 		regularExpressionCheckBox
       
   371 				.setLayoutData(regularExpressionCheckBoxGridData);
       
   372 		createDirectionGroup();
       
   373 
       
   374 		// Spacer label
       
   375 		new Label(composite, SWT.NONE);
       
   376 
       
   377 		// Line Count Label
       
   378 		GridData lineCountLabelGridData = new GridData();
       
   379 		lineCountLabelGridData.horizontalSpan = 2;
       
   380 		lineCountLabelGridData.widthHint = 300;
       
   381 		lineCountLabel = new Label(composite, SWT.NONE);
       
   382 
       
   383 		// Get the trace count for the label and set it
       
   384 		int traceCount = 0;
       
   385 		if (TraceViewerGlobals.getTraceViewer().getDataReaderAccess()
       
   386 				.getCurrentDataReader() != null) {
       
   387 			traceCount = TraceViewerGlobals.getTraceViewer()
       
   388 					.getDataReaderAccess().getCurrentDataReader()
       
   389 					.getTraceCount();
       
   390 		}
       
   391 		lineCountLabel.setText(Messages.getString("SearchDialog.LineViewText") //$NON-NLS-1$
       
   392 				+ traceCount);
       
   393 		lineCountLabel.setLayoutData(lineCountLabelGridData);
       
   394 
       
   395 		// ProgressBar
       
   396 		GridData progressBarGridData = new GridData();
       
   397 		progressBarGridData.heightHint = 22;
       
   398 		progressBarGridData.grabExcessVerticalSpace = false;
       
   399 		progressBarGridData.grabExcessHorizontalSpace = true;
       
   400 		progressBarGridData.horizontalAlignment = SWT.FILL;
       
   401 		progressBarGridData.horizontalSpan = 3;
       
   402 		progressBar = new ProgressBar(composite, SWT.SMOOTH);
       
   403 		progressBar.setLayoutData(progressBarGridData);
       
   404 		updateSearchProgressBar(view.getShowingTracesFrom()
       
   405 				+ widget.getLineAtOffset(widget.getCaretOffset()));
       
   406 
       
   407 		// Set help
       
   408 		PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(),
       
   409 				TraceViewerHelpContextIDs.SEARCHING);
       
   410 	}
       
   411 
       
   412 	/**
       
   413 	 * This method initializes findCombo
       
   414 	 */
       
   415 	private void createKeyListener() {
       
   416 		searchDialogKeyListener = new KeyAdapter() {
       
   417 
       
   418 			@Override
       
   419 			public void keyPressed(KeyEvent e) {
       
   420 
       
   421 				// ALT + d changes search direction
       
   422 				if (e.stateMask == SWT.ALT
       
   423 						&& (e.character == 'd' || e.character == 'D')) {
       
   424 					upDirectionRadioButton.setSelection(!upDirectionRadioButton
       
   425 							.getSelection());
       
   426 					downDirectionRadioButton
       
   427 							.setSelection(!downDirectionRadioButton
       
   428 									.getSelection());
       
   429 
       
   430 					// ALT + c changes "match case" value
       
   431 				} else if (e.stateMask == SWT.ALT
       
   432 						&& (e.character == 'c' || e.character == 'C')) {
       
   433 					matchCaseCheckBox.setSelection(!matchCaseCheckBox
       
   434 							.getSelection());
       
   435 
       
   436 					// ALT + w changes "whole word" value
       
   437 				} else if (e.stateMask == SWT.ALT
       
   438 						&& (e.character == 'w' || e.character == 'W')) {
       
   439 					matchWholeWordCheckBox.setSelection(!matchWholeWordCheckBox
       
   440 							.getSelection());
       
   441 
       
   442 					// Search again
       
   443 				} else if (e.keyCode == SWT.F3) {
       
   444 					findCombo.setText(getPreviousSearchString());
       
   445 					searchString();
       
   446 				}
       
   447 			}
       
   448 		};
       
   449 	}
       
   450 
       
   451 	/**
       
   452 	 * This method initializes directionGroup
       
   453 	 */
       
   454 	private void createDirectionGroup() {
       
   455 
       
   456 		// Direction Group
       
   457 		GridData directionGroupGridData = new GridData();
       
   458 		directionGroupGridData.horizontalSpan = 2;
       
   459 		GridLayout gridLayout1 = new GridLayout();
       
   460 		gridLayout1.numColumns = 2;
       
   461 		Group directionGroup = new Group(composite, SWT.NONE);
       
   462 		directionGroup.setText(Messages
       
   463 				.getString("SearchDialog.DirectionGroupName")); //$NON-NLS-1$
       
   464 		directionGroup.setLayoutData(directionGroupGridData);
       
   465 		directionGroup.setLayout(gridLayout1);
       
   466 		directionGroup.setText(Messages
       
   467 				.getString("SearchDialog.DirectionGroupName")); //$NON-NLS-1$
       
   468 		directionGroup.setToolTipText(Messages
       
   469 				.getString("SearchDialog.DirectionToolTip")); //$NON-NLS-1$
       
   470 
       
   471 		// Up direction Button
       
   472 		upDirectionRadioButton = new Button(directionGroup, SWT.RADIO);
       
   473 		upDirectionRadioButton.setText(Messages
       
   474 				.getString("SearchDialog.UpDirectionText")); //$NON-NLS-1$
       
   475 		upDirectionRadioButton.setToolTipText(Messages
       
   476 				.getString("SearchDialog.UpDirectionToolTip")); //$NON-NLS-1$
       
   477 
       
   478 		// Down direction Button
       
   479 		downDirectionRadioButton = new Button(directionGroup, SWT.RADIO);
       
   480 		downDirectionRadioButton.setText(Messages
       
   481 				.getString("SearchDialog.DownDirectionText")); //$NON-NLS-1$
       
   482 		downDirectionRadioButton.setToolTipText(Messages
       
   483 				.getString("SearchDialog.DownDirectionToolTip")); //$NON-NLS-1$
       
   484 		downDirectionRadioButton.setSelection(true);
       
   485 
       
   486 		// Add key listeners
       
   487 		downDirectionRadioButton.addKeyListener(searchDialogKeyListener);
       
   488 		upDirectionRadioButton.addKeyListener(searchDialogKeyListener);
       
   489 	}
       
   490 
       
   491 	/**
       
   492 	 * Starts searching with given string
       
   493 	 * 
       
   494 	 * @param searchString
       
   495 	 *            search string
       
   496 	 */
       
   497 	public void startSearch(String searchString) {
       
   498 		if (TraceViewerGlobals.getTraceViewer().getStateHolder().getState() != StateHolder.State.SEARCHING) {
       
   499 			TraceViewerGlobals.getTraceViewer().getStateHolder().setState(
       
   500 					StateHolder.State.SEARCHING);
       
   501 
       
   502 			// Has to be before search button is disabled because will
       
   503 			// enable it in modify listener
       
   504 			insertTextToComboBox(searchString);
       
   505 
       
   506 			searchButton.setEnabled(false);
       
   507 			stopSearchButton.setEnabled(true);
       
   508 
       
   509 			searchString();
       
   510 		}
       
   511 
       
   512 		// Save settings
       
   513 		saveSettings();
       
   514 	}
       
   515 
       
   516 	/**
       
   517 	 * Inserts text to combo box if necessary
       
   518 	 * 
       
   519 	 * @param newString
       
   520 	 *            new string to add to combo box
       
   521 	 */
       
   522 	private void insertTextToComboBox(String newString) {
       
   523 		// Insert new items to combo
       
   524 
       
   525 		int nIndex = findCombo.indexOf(newString);
       
   526 		if (nIndex > -1) {
       
   527 			findCombo.remove(nIndex);
       
   528 		}
       
   529 		findCombo.setText(newString);
       
   530 		findCombo.add(newString, 0);
       
   531 	}
       
   532 
       
   533 	/*
       
   534 	 * (non-Javadoc)
       
   535 	 * 
       
   536 	 * @see com.nokia.traceviewer.dialog.BaseDialog#createActionListeners()
       
   537 	 */
       
   538 	@Override
       
   539 	protected void createActionListeners() {
       
   540 		// Add selection listener to search button
       
   541 		searchButton.addSelectionListener(new SelectionAdapter() {
       
   542 			@Override
       
   543 			public void widgetSelected(SelectionEvent event) {
       
   544 				TraceViewerGlobals.postUiEvent("SearchButton", "1"); //$NON-NLS-1$ //$NON-NLS-2$
       
   545 				if (widget.getLineCount() > 1) {
       
   546 					startSearch(findCombo.getText());
       
   547 				}
       
   548 				TraceViewerGlobals.postUiEvent("SearchButton", "0"); //$NON-NLS-1$ //$NON-NLS-2$
       
   549 			}
       
   550 		});
       
   551 
       
   552 		// Add selection listener to stop find button
       
   553 		stopSearchButton.addSelectionListener(new SelectionAdapter() {
       
   554 			@Override
       
   555 			public void widgetSelected(SelectionEvent event) {
       
   556 				TraceViewerGlobals.postUiEvent("StopSearchButton", "1"); //$NON-NLS-1$ //$NON-NLS-2$
       
   557 				TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   558 						.getSearchProcessor().stopSearch(true);
       
   559 				searchButton.setEnabled(true);
       
   560 				stopSearchButton.setEnabled(false);
       
   561 				getButton(IDialogConstants.OK_ID).setEnabled(true);
       
   562 				TraceViewerGlobals.postUiEvent("StopSearchButton", "0"); //$NON-NLS-1$ //$NON-NLS-2$
       
   563 			}
       
   564 		});
       
   565 
       
   566 		// Add selection listener to match whole word checkbox
       
   567 		matchWholeWordCheckBox.addSelectionListener(new SelectionAdapter() {
       
   568 			@Override
       
   569 			public void widgetSelected(SelectionEvent event) {
       
   570 				TraceViewerGlobals.postUiEvent("MatchWholeWordCheckBox" //$NON-NLS-1$
       
   571 						+ matchWholeWordCheckBox.getSelection(), "1"); //$NON-NLS-1$
       
   572 				if (matchWholeWordCheckBox.getSelection()) {
       
   573 					regularExpressionCheckBox.setEnabled(false);
       
   574 				} else {
       
   575 					regularExpressionCheckBox.setEnabled(true);
       
   576 				}
       
   577 				TraceViewerGlobals.postUiEvent("MatchWholeWordCheckBox" //$NON-NLS-1$
       
   578 						+ matchWholeWordCheckBox.getSelection(), "0"); //$NON-NLS-1$
       
   579 			}
       
   580 		});
       
   581 
       
   582 		// Add selection listener to regular expression checkbox
       
   583 		regularExpressionCheckBox.addSelectionListener(new SelectionAdapter() {
       
   584 			@Override
       
   585 			public void widgetSelected(SelectionEvent event) {
       
   586 				TraceViewerGlobals.postUiEvent("RegularExpressionCheckBox" //$NON-NLS-1$
       
   587 						+ regularExpressionCheckBox.getSelection(), "1"); //$NON-NLS-1$
       
   588 				if (regularExpressionCheckBox.getSelection()) {
       
   589 					matchWholeWordCheckBox.setEnabled(false);
       
   590 				} else {
       
   591 					matchWholeWordCheckBox.setEnabled(true);
       
   592 				}
       
   593 				TraceViewerGlobals.postUiEvent("RegularExpressionCheckBox" //$NON-NLS-1$
       
   594 						+ regularExpressionCheckBox.getSelection(), "0"); //$NON-NLS-1$
       
   595 			}
       
   596 		});
       
   597 
       
   598 		// Add selection listener to match case checkbox
       
   599 		matchCaseCheckBox.addSelectionListener(new SelectionAdapter() {
       
   600 			@Override
       
   601 			public void widgetSelected(SelectionEvent event) {
       
   602 				TraceViewerGlobals.postUiEvent("MatchCaseCheckBox" //$NON-NLS-1$
       
   603 						+ matchCaseCheckBox.getSelection(), "1"); //$NON-NLS-1$
       
   604 				TraceViewerGlobals.postUiEvent("MatchCaseCheckBox" //$NON-NLS-1$
       
   605 						+ matchCaseCheckBox.getSelection(), "0"); //$NON-NLS-1$
       
   606 			}
       
   607 		});
       
   608 
       
   609 		// Add modify listener to find combo box
       
   610 		findCombo.addModifyListener(new ModifyListener() {
       
   611 			public void modifyText(ModifyEvent e) {
       
   612 				if (findCombo.getText().length() > 0) {
       
   613 					searchButton.setEnabled(true);
       
   614 				} else {
       
   615 					searchButton.setEnabled(false);
       
   616 				}
       
   617 			}
       
   618 
       
   619 		});
       
   620 	}
       
   621 
       
   622 	/**
       
   623 	 * Gets progressBar
       
   624 	 * 
       
   625 	 * @return progressBar
       
   626 	 */
       
   627 	public ProgressBar getProgressBar() {
       
   628 		return progressBar;
       
   629 	}
       
   630 
       
   631 	/**
       
   632 	 * Sets search properties
       
   633 	 */
       
   634 	private void setVariablesToProperties() {
       
   635 
       
   636 		// Get variable statuses from the ui components
       
   637 		searchProperties.setSearchString(findCombo.getText());
       
   638 		searchProperties.setSearchingForward(!upDirectionRadioButton
       
   639 				.getSelection());
       
   640 		searchProperties.setCaseSensitive(matchCaseCheckBox.getSelection());
       
   641 		searchProperties.setWholeWord(matchWholeWordCheckBox.getSelection());
       
   642 		searchProperties.setRegExp(regularExpressionCheckBox.getSelection());
       
   643 		searchProperties.setOriginalSearchStartLine(TraceViewerGlobals
       
   644 				.getTraceViewer().getView().getShowingTracesFrom()
       
   645 				+ widget.getLineAtOffset(widget.getCaretOffset()));
       
   646 	}
       
   647 
       
   648 	/**
       
   649 	 * Searchs the occurrence of the String value and shows it in view
       
   650 	 */
       
   651 	private void searchString() {
       
   652 
       
   653 		// Set search variables
       
   654 		setVariablesToProperties();
       
   655 
       
   656 		// Check if this is a timestamp range search, jump straight to
       
   657 		// SearchProcessor
       
   658 		if (SearchUtils.containsTimestampQuery(searchProperties
       
   659 				.getSearchString())
       
   660 				&& SearchUtils.containsTimestampRangeQuery(searchProperties
       
   661 						.getSearchString())) {
       
   662 
       
   663 			// Do a timestamp range search
       
   664 			TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   665 					.getSearchProcessor().doTimestampRangeSearch(
       
   666 							searchProperties.getSearchString());
       
   667 
       
   668 			// Other searchs
       
   669 		} else {
       
   670 
       
   671 			try {
       
   672 
       
   673 				// Get the search start offset
       
   674 				int cursorOffset = getCursorOffset(searchProperties
       
   675 						.isSearchingForward());
       
   676 
       
   677 				// Find the trace and get the offset of it
       
   678 				int offset = findTrace(cursorOffset);
       
   679 
       
   680 				// String found
       
   681 				if (offset != SearchUtils.NOT_FOUND) {
       
   682 					processStringFound(offset);
       
   683 
       
   684 					// String was not found
       
   685 				} else {
       
   686 
       
   687 					// Start the search after or before this view
       
   688 					if (searchProperties.isSearchingForward()) {
       
   689 						processSearchingForward();
       
   690 					} else {
       
   691 						processSearchingBackward();
       
   692 					}
       
   693 
       
   694 				}
       
   695 
       
   696 			} catch (BadLocationException e) {
       
   697 				e.printStackTrace();
       
   698 				enableSearchButton();
       
   699 			} catch (PatternSyntaxException e) {
       
   700 				e.printStackTrace();
       
   701 				enableSearchButton();
       
   702 			}
       
   703 		}
       
   704 	}
       
   705 
       
   706 	/**
       
   707 	 * Finds the trace using search properties
       
   708 	 * 
       
   709 	 * @param searchStartOffset
       
   710 	 *            start offset where to start the search
       
   711 	 * @return offset of the trace found or -1 if not found
       
   712 	 * @throws BadLocationException
       
   713 	 */
       
   714 	private int findTrace(int searchStartOffset) throws BadLocationException {
       
   715 		int offset = SearchUtils.NOT_FOUND;
       
   716 
       
   717 		// Search using component, group and trace ID's
       
   718 		if (SearchUtils.containsIdQuery(searchProperties.getSearchString())) {
       
   719 			offset = findTraceIDSearch(searchStartOffset);
       
   720 
       
   721 			// Timestamp search
       
   722 		} else if (SearchUtils.containsTimestampQuery(searchProperties
       
   723 				.getSearchString())) {
       
   724 			offset = findTraceTimestampSearch(searchStartOffset);
       
   725 
       
   726 			// Create a normal text search
       
   727 		} else {
       
   728 			IRegion region = finder.find(searchStartOffset, searchProperties
       
   729 					.getSearchString(), searchProperties.isSearchingForward(),
       
   730 					searchProperties.isCaseSensitive(), searchProperties
       
   731 							.isWholeWord(), searchProperties.isRegExp());
       
   732 
       
   733 			if (region != null) {
       
   734 				offset = region.getOffset();
       
   735 			}
       
   736 		}
       
   737 
       
   738 		return offset;
       
   739 	}
       
   740 
       
   741 	/**
       
   742 	 * Finds the trace using ID search
       
   743 	 * 
       
   744 	 * @param searchStartOffset
       
   745 	 *            search start offset
       
   746 	 * @return found offset
       
   747 	 * @throws BadLocationException
       
   748 	 */
       
   749 	private int findTraceIDSearch(int searchStartOffset)
       
   750 			throws BadLocationException {
       
   751 		int offset;
       
   752 
       
   753 		// Parse ID's from the search string
       
   754 		TraceInformation inf = SearchUtils.parseIDsFromString(searchProperties
       
   755 				.getSearchString());
       
   756 
       
   757 		int startTrace = document.getLineOfOffset(searchStartOffset);
       
   758 
       
   759 		// Check which way we are searching and modify the start trace
       
   760 		// accordingly
       
   761 		boolean forward = searchProperties.isSearchingForward();
       
   762 		if (forward) {
       
   763 			startTrace++;
       
   764 		} else {
       
   765 			startTrace--;
       
   766 		}
       
   767 
       
   768 		List<TraceProperties> traces = null;
       
   769 		List<TraceInformation> informations = null;
       
   770 
       
   771 		// Get properties from the traces in the view. -2 comes from empty
       
   772 		// line in the end of widget and because traces start from offset 0,
       
   773 		// not 1
       
   774 		traces = TraceViewerGlobals.getTraceViewer().getTraces(
       
   775 				view.getShowingTracesFrom(),
       
   776 				view.getShowingTracesFrom() + widget.getLineCount() - 2);
       
   777 
       
   778 		// Get the informations array
       
   779 		if (traces != null) {
       
   780 			informations = new ArrayList<TraceInformation>(traces.size());
       
   781 			for (int i = 0; i < traces.size(); i++) {
       
   782 				informations.add(traces.get(i).information);
       
   783 			}
       
   784 		}
       
   785 
       
   786 		// Get the trace number that matches the ID's
       
   787 		int foundTrace = SearchUtils.findTraceOffsetFromInformations(
       
   788 				startTrace, inf, informations, forward);
       
   789 
       
   790 		if (foundTrace == SearchUtils.NOT_FOUND) {
       
   791 			offset = SearchUtils.NOT_FOUND;
       
   792 		} else {
       
   793 			offset = document.getLineOffset(foundTrace);
       
   794 		}
       
   795 		return offset;
       
   796 	}
       
   797 
       
   798 	/**
       
   799 	 * Finds the trace using timestamp search
       
   800 	 * 
       
   801 	 * @param searchStartOffset
       
   802 	 *            search start offset
       
   803 	 * @return found offset
       
   804 	 * @throws BadLocationException
       
   805 	 */
       
   806 	private int findTraceTimestampSearch(int searchStartOffset)
       
   807 			throws BadLocationException {
       
   808 		int offset;
       
   809 
       
   810 		// Parse timestamp from the search string
       
   811 		String timestamp = SearchUtils.parseTimestampFromString(
       
   812 				searchProperties.getSearchString(), true);
       
   813 
       
   814 		List<TraceProperties> traces = null;
       
   815 		List<String> timestamps = null;
       
   816 
       
   817 		// Get properties from the traces in the view. -2 comes from empty
       
   818 		// line in the end of widget and because traces start from offset 0,
       
   819 		// not 1
       
   820 		traces = TraceViewerGlobals.getTraceViewer().getTraces(
       
   821 				view.getShowingTracesFrom(),
       
   822 				view.getShowingTracesFrom() + widget.getLineCount() - 2);
       
   823 
       
   824 		int startTrace = document.getLineOfOffset(searchStartOffset);
       
   825 		String currentTraceTimestamp = null;
       
   826 
       
   827 		// Get the informations array
       
   828 		if (traces != null) {
       
   829 			TimestampParser parser = TraceViewerGlobals.getTraceViewer()
       
   830 					.getDataProcessorAccess().getTimestampParser();
       
   831 			timestamps = new ArrayList<String>(traces.size());
       
   832 			for (int i = 0; i < traces.size(); i++) {
       
   833 				TraceProperties trace = traces.get(i);
       
   834 				parser.processData(trace);
       
   835 				timestamps.add(trace.timestampString);
       
   836 			}
       
   837 
       
   838 			if (timestamps.size() >= startTrace) {
       
   839 				currentTraceTimestamp = timestamps.get(startTrace);
       
   840 			}
       
   841 		}
       
   842 
       
   843 		boolean forward = true;
       
   844 
       
   845 		// Check which way we are searching and modify the start trace
       
   846 		// accordingly
       
   847 		if (currentTraceTimestamp != null) {
       
   848 			if (currentTraceTimestamp.compareTo(timestamp) <= 0) {
       
   849 				startTrace++;
       
   850 			} else {
       
   851 				startTrace--;
       
   852 				forward = false;
       
   853 			}
       
   854 		} else {
       
   855 			startTrace++;
       
   856 		}
       
   857 		upDirectionRadioButton.setSelection(!forward);
       
   858 		downDirectionRadioButton.setSelection(forward);
       
   859 		searchProperties.setSearchingForward(forward);
       
   860 
       
   861 		// Get the trace number that matches the timestamp
       
   862 		int foundTrace = SearchUtils.findTraceOffsetFromTimestamps(startTrace,
       
   863 				timestamp, timestamps, forward);
       
   864 
       
   865 		if (foundTrace == SearchUtils.NOT_FOUND) {
       
   866 			offset = SearchUtils.NOT_FOUND;
       
   867 		} else {
       
   868 			offset = document.getLineOffset(foundTrace);
       
   869 		}
       
   870 		return offset;
       
   871 	}
       
   872 
       
   873 	/**
       
   874 	 * Processes searching forward
       
   875 	 */
       
   876 	private void processSearchingForward() {
       
   877 		// There is traces below this block
       
   878 		int traceCount = TraceViewerGlobals.getTraceViewer()
       
   879 				.getDataReaderAccess().getCurrentDataReader().getTraceCount();
       
   880 		if (view.getShowingTracesFrom() + widget.getLineCount() < traceCount) {
       
   881 
       
   882 			searchProperties.setCurrentSearchStartLine(view
       
   883 					.getShowingTracesFrom()
       
   884 					+ widget.getLineCount()
       
   885 					+ (TraceViewerGlobals.blockSize / 2));
       
   886 
       
   887 			TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   888 					.getSearchProcessor()
       
   889 					.processSearch(searchProperties, false);
       
   890 		} else { // End Of File
       
   891 			// Say EOF to searchProcessor
       
   892 			updateSearchProgressBar(traceCount);
       
   893 			searchHitEOF();
       
   894 		}
       
   895 	}
       
   896 
       
   897 	/**
       
   898 	 * Processes searching backwards
       
   899 	 */
       
   900 	private void processSearchingBackward() {
       
   901 		// There is traces above this block
       
   902 		if (view.getShowingTracesFrom() > 0) {
       
   903 			searchProperties.setCurrentSearchStartLine(view
       
   904 					.getShowingTracesFrom()
       
   905 					- (TraceViewerGlobals.blockSize / 2));
       
   906 			TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   907 					.getSearchProcessor()
       
   908 					.processSearch(searchProperties, false);
       
   909 		} else { // End (beginning) Of File
       
   910 			updateSearchProgressBar(0);
       
   911 			searchHitEOF();
       
   912 		}
       
   913 	}
       
   914 
       
   915 	/**
       
   916 	 * Processes situation where result is found
       
   917 	 * 
       
   918 	 * @param offset
       
   919 	 *            offset of result
       
   920 	 */
       
   921 	private void processStringFound(int offset) {
       
   922 		int line = widget.getLineAtOffset(offset);
       
   923 
       
   924 		// Update progressBar and linecount label
       
   925 		updateSearchProgressBar(view.getShowingTracesFrom() + line);
       
   926 
       
   927 		// Set search result line to the view
       
   928 		TraceViewerGlobals.getTraceViewer().getView().highlightLines(
       
   929 				view.getShowingTracesFrom() + line, 0, false);
       
   930 	}
       
   931 
       
   932 	/**
       
   933 	 * Gets cursor offset
       
   934 	 * 
       
   935 	 * @param searchingForward
       
   936 	 *            tells which way the search is going
       
   937 	 * @return cursor offset
       
   938 	 * @throws BadLocationException
       
   939 	 */
       
   940 	private int getCursorOffset(boolean searchingForward)
       
   941 			throws BadLocationException {
       
   942 		int cursorOffset;
       
   943 
       
   944 		if (searchingForward) {
       
   945 			cursorOffset = widget.getCaretOffset();
       
   946 		} else {
       
   947 			int lineNumber = widget.getLineAtOffset(widget.getCaretOffset());
       
   948 			int lineLength = document.getLineLength(lineNumber);
       
   949 			cursorOffset = widget.getCaretOffset() - lineLength + 1;
       
   950 		}
       
   951 		// To make sure cursor offset isn't anything stupid
       
   952 		if (cursorOffset < 0) {
       
   953 			cursorOffset = 0;
       
   954 		} else if (cursorOffset >= widget.getCharCount()) {
       
   955 			cursorOffset = widget.getCharCount() - 1;
       
   956 		}
       
   957 		return cursorOffset;
       
   958 	}
       
   959 
       
   960 	/**
       
   961 	 * Invokes search from EOF. Is called from view in EOF
       
   962 	 */
       
   963 	public void endOfFile() {
       
   964 		TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   965 				.getSearchProcessor().setHitEOFAlready(true);
       
   966 
       
   967 		setVariablesToProperties();
       
   968 
       
   969 		if (searchProperties.isSearchingForward()) { // Down
       
   970 			// Start new search from beginning of the file
       
   971 			searchProperties.setCurrentSearchStartLine(0);
       
   972 			TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   973 					.getSearchProcessor()
       
   974 					.processSearch(searchProperties, false);
       
   975 		} else { // Searching up
       
   976 			searchProperties.setCurrentSearchStartLine(TraceViewerGlobals
       
   977 					.getTraceViewer().getDataReaderAccess()
       
   978 					.getCurrentDataReader().getTraceCount());
       
   979 			TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   980 					.getSearchProcessor()
       
   981 					.processSearch(searchProperties, false);
       
   982 		}
       
   983 	}
       
   984 
       
   985 	/**
       
   986 	 * Enables search button
       
   987 	 */
       
   988 	public void enableSearchButton() {
       
   989 		display.asyncExec(new Runnable() {
       
   990 
       
   991 			public void run() {
       
   992 				if (getShell() != null && !getShell().isDisposed()) {
       
   993 
       
   994 					// Enable find button
       
   995 					if (!findCombo.getText().equals(SearchUtils.EMPTY)) {
       
   996 						searchButton.setEnabled(true);
       
   997 					}
       
   998 
       
   999 					// Disable stop button
       
  1000 					stopSearchButton.setEnabled(false);
       
  1001 
       
  1002 					// Set state back to normal
       
  1003 					TraceViewerGlobals.getTraceViewer().getStateHolder()
       
  1004 							.setState(StateHolder.State.NORMAL);
       
  1005 
       
  1006 					TraceViewerGlobals.getTraceViewer()
       
  1007 							.getDataProcessorAccess().getSearchProcessor()
       
  1008 							.setHitEOFAlready(false);
       
  1009 
       
  1010 					getShell().setFocus();
       
  1011 				}
       
  1012 			}
       
  1013 
       
  1014 		});
       
  1015 	}
       
  1016 
       
  1017 	/**
       
  1018 	 * Sets search text to dialog. Must be called from UI thread!
       
  1019 	 * 
       
  1020 	 * @param findStr
       
  1021 	 *            search text
       
  1022 	 */
       
  1023 	public void setSearchText(String findStr) {
       
  1024 		findCombo.setText(findStr);
       
  1025 	}
       
  1026 
       
  1027 	/**
       
  1028 	 * Updates search progressBar
       
  1029 	 * 
       
  1030 	 * @param selectionPoint
       
  1031 	 *            selection point where to update
       
  1032 	 */
       
  1033 	public void updateSearchProgressBar(int selectionPoint) {
       
  1034 		display.asyncExec(new SearchDialogProgressBarUpdater(selectionPoint,
       
  1035 				lineCountLabel));
       
  1036 	}
       
  1037 
       
  1038 	/**
       
  1039 	 * Search hit full round
       
  1040 	 */
       
  1041 	public void searchHitFullRound() {
       
  1042 		display.asyncExec(new SearchHitFullRoundUpdater());
       
  1043 	}
       
  1044 
       
  1045 	/**
       
  1046 	 * Search hit EOF
       
  1047 	 */
       
  1048 	public void searchHitEOF() {
       
  1049 		display.asyncExec(new SearchHitEOFUpdater());
       
  1050 	}
       
  1051 
       
  1052 	/**
       
  1053 	 * Tells is the search dialog open
       
  1054 	 * 
       
  1055 	 * @return true if dialog is open
       
  1056 	 */
       
  1057 	public boolean isOpen() {
       
  1058 		boolean isOpen = false;
       
  1059 		if (getShell() != null && !getShell().isDisposed()) {
       
  1060 			isOpen = true;
       
  1061 		}
       
  1062 		return isOpen;
       
  1063 	}
       
  1064 
       
  1065 	/**
       
  1066 	 * Tells is the search dialog visible
       
  1067 	 * 
       
  1068 	 * @return true if dialog is visible
       
  1069 	 */
       
  1070 	public boolean isVisible() {
       
  1071 		boolean isVisible = false;
       
  1072 		if (isOpen() && getShell().isVisible()) {
       
  1073 			isVisible = true;
       
  1074 		}
       
  1075 		return isVisible;
       
  1076 	}
       
  1077 
       
  1078 	/**
       
  1079 	 * Sets focus
       
  1080 	 */
       
  1081 	public void setFocus() {
       
  1082 		Shell shell = getShell();
       
  1083 		if (shell != null && !shell.isDisposed()) {
       
  1084 			shell.setFocus();
       
  1085 		}
       
  1086 	}
       
  1087 
       
  1088 	/**
       
  1089 	 * Check if dialog is open. If yes, close it
       
  1090 	 * 
       
  1091 	 * @return true if dialog was open and was now closed
       
  1092 	 */
       
  1093 	public boolean forceClose() {
       
  1094 		boolean closed = false;
       
  1095 		Shell shell = getShell();
       
  1096 		if (shell != null && !shell.isDisposed()) {
       
  1097 			shell.close();
       
  1098 			closed = true;
       
  1099 		}
       
  1100 		return closed;
       
  1101 	}
       
  1102 
       
  1103 	/**
       
  1104 	 * Gets previous search string
       
  1105 	 * 
       
  1106 	 * @return previous search string or empty String if doesn't exist
       
  1107 	 */
       
  1108 	public String getPreviousSearchString() {
       
  1109 		String previous = ""; //$NON-NLS-1$
       
  1110 
       
  1111 		if (comboList != null && comboList.length > 0) {
       
  1112 			previous = comboList[0];
       
  1113 		}
       
  1114 		return previous;
       
  1115 	}
       
  1116 }