trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/dialog/SearchDialogProgressBarUpdater.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  * SearchDialogProgressBar updater class
       
    17  *
       
    18  */
       
    19 package com.nokia.traceviewer.dialog;
       
    20 
       
    21 import org.eclipse.swt.widgets.Label;
       
    22 import org.eclipse.swt.widgets.ProgressBar;
       
    23 
       
    24 import com.nokia.traceviewer.engine.TraceViewerGlobals;
       
    25 
       
    26 /**
       
    27  * Updates search dialogs progressBar
       
    28  * 
       
    29  */
       
    30 final class SearchDialogProgressBarUpdater implements Runnable {
       
    31 
       
    32 	/**
       
    33 	 * Value of the progressbar
       
    34 	 */
       
    35 	private int value;
       
    36 
       
    37 	/**
       
    38 	 * Line count label to update
       
    39 	 */
       
    40 	private final Label lineCountLabel;
       
    41 
       
    42 	/**
       
    43 	 * Constructor
       
    44 	 * 
       
    45 	 * @param value
       
    46 	 *            value of the selection
       
    47 	 * @param lineCountLabel
       
    48 	 *            line count label to update
       
    49 	 */
       
    50 	SearchDialogProgressBarUpdater(int value, Label lineCountLabel) {
       
    51 		this.value = value;
       
    52 		this.lineCountLabel = lineCountLabel;
       
    53 	}
       
    54 
       
    55 	/*
       
    56 	 * (non-Javadoc)
       
    57 	 * 
       
    58 	 * @see java.lang.Runnable#run()
       
    59 	 */
       
    60 	public void run() {
       
    61 		ProgressBar bar = TraceViewerGlobals.getTraceViewer()
       
    62 				.getDataProcessorAccess().getSearchProcessor()
       
    63 				.getSearchDialog().getProgressBar();
       
    64 
       
    65 		if (bar != null && !bar.isDisposed()) {
       
    66 			int max = 0;
       
    67 
       
    68 			// Get max value from data reader
       
    69 			if (TraceViewerGlobals.getTraceViewer().getDataReaderAccess()
       
    70 					.getCurrentDataReader() != null) {
       
    71 				max = TraceViewerGlobals.getTraceViewer().getDataReaderAccess()
       
    72 						.getCurrentDataReader().getTraceCount();
       
    73 			}
       
    74 			// Set maximum value to bar
       
    75 			bar.setMaximum(max);
       
    76 
       
    77 			// Set selection value
       
    78 			StringBuffer text = new StringBuffer();
       
    79 			text.append(Messages
       
    80 					.getString("SearchDialogProgressBarUpdater.LineText")); //$NON-NLS-1$
       
    81 			text.append(':');
       
    82 			text.append(' ');
       
    83 
       
    84 			if (value <= 0 && max > 0) {
       
    85 				value = 1;
       
    86 				text.append(value);
       
    87 			} else if (value >= max) {
       
    88 				value = max;
       
    89 				text.append(value);
       
    90 			} else if (max == 0) {
       
    91 				text.append(0);
       
    92 			} else {
       
    93 				text.append(value + 1);
       
    94 			}
       
    95 			bar.setSelection(value);
       
    96 
       
    97 			text.append(" / "); //$NON-NLS-1$
       
    98 			text.append(max);
       
    99 
       
   100 			// Change line text
       
   101 			if (!lineCountLabel.isDisposed()) {
       
   102 				lineCountLabel.setText(text.toString());
       
   103 			}
       
   104 		}
       
   105 	}
       
   106 }