trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/api/ViewHandler.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  * View handler handles operations that require TraceViewer view 
       
    17  *
       
    18  */
       
    19 package com.nokia.traceviewer.api;
       
    20 
       
    21 import org.eclipse.ui.PlatformUI;
       
    22 
       
    23 import com.nokia.traceviewer.api.TraceViewerAPI.TVAPIError;
       
    24 import com.nokia.traceviewer.engine.TraceViewerGlobals;
       
    25 
       
    26 /**
       
    27  * View handler handles operations that require TraceViewer view
       
    28  */
       
    29 final class ViewHandler {
       
    30 
       
    31 	/**
       
    32 	 * Private variable to be able to change it in inner class
       
    33 	 */
       
    34 	private TVAPIError syncToTimestampRet;
       
    35 
       
    36 	/**
       
    37 	 * Stops or restarts the TraceViewer view update
       
    38 	 * 
       
    39 	 * @param stop
       
    40 	 *            if true, stops the view update. If false, restarts the update.
       
    41 	 */
       
    42 	public void stopViewUpdate(boolean stop) {
       
    43 		if (TraceViewerGlobals.getTraceViewer().getView() != null) {
       
    44 			TraceViewerGlobals.getTraceViewer().getView().stopViewUpdate(stop);
       
    45 		}
       
    46 	}
       
    47 
       
    48 	/**
       
    49 	 * Syncs to timestamp in the TraceViewer view. If both start and end
       
    50 	 * timestamps are given, the range is selected. This function assumes that
       
    51 	 * the traces in the TraceViewer view are in chronological order. Also,
       
    52 	 * endTimestamp must always be "bigger" than startTimestamp
       
    53 	 * 
       
    54 	 * @param startTimestamp
       
    55 	 *            start timestamp in the format of hh:mm:ss.SSS
       
    56 	 * @param endTimestamp
       
    57 	 *            end timestamp in the format of hh:mm:ss.SSS or null if only
       
    58 	 *            start timestamp is searched for
       
    59 	 * @return error code from TraceViewerAPI
       
    60 	 */
       
    61 	public TVAPIError syncToTimestamp(final String startTimestamp,
       
    62 			final String endTimestamp) {
       
    63 		syncToTimestampRet = TVAPIError.NONE;
       
    64 
       
    65 		if (TraceViewerGlobals.getTraceViewer().getView() != null) {
       
    66 
       
    67 			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
       
    68 
       
    69 				/*
       
    70 				 * (non-Javadoc)
       
    71 				 * 
       
    72 				 * @see java.lang.Runnable#run()
       
    73 				 */
       
    74 				public void run() {
       
    75 
       
    76 					// Check that the view is not disposed
       
    77 					if (!TraceViewerGlobals.getTraceViewer().getView()
       
    78 							.isDisposed()) {
       
    79 
       
    80 						// Start searching for the timestamp(s)
       
    81 						TraceViewerGlobals.getTraceViewer()
       
    82 								.getDataProcessorAccess().getSearchProcessor()
       
    83 								.searchTraceWithTimestamp(startTimestamp,
       
    84 										endTimestamp);
       
    85 					} else {
       
    86 						syncToTimestampRet = TVAPIError.TRACE_VIEW_NOT_OPEN;
       
    87 					}
       
    88 
       
    89 				}
       
    90 			});
       
    91 
       
    92 		} else {
       
    93 			syncToTimestampRet = TVAPIError.TRACE_VIEW_NOT_OPEN;
       
    94 		}
       
    95 
       
    96 		return syncToTimestampRet;
       
    97 	}
       
    98 
       
    99 	/**
       
   100 	 * Syncs to trace in the TraceViewer view
       
   101 	 * 
       
   102 	 * @param startTrace
       
   103 	 *            start trace number
       
   104 	 * @param endTrace
       
   105 	 *            end trace number of 0 if only start trace is searched for
       
   106 	 * @return error code from TraceViewerAPI
       
   107 	 */
       
   108 	public TVAPIError syncToTrace(int startTrace, int endTrace) {
       
   109 		TVAPIError ret = TVAPIError.NONE;
       
   110 
       
   111 		if (TraceViewerGlobals.getTraceViewer().getView() != null) {
       
   112 			int start = startTrace;
       
   113 			int end = endTrace;
       
   114 
       
   115 			// Decrease lines by one because actually traces start from index 0
       
   116 			if (start > 0) {
       
   117 				start--;
       
   118 			}
       
   119 			if (end > 0) {
       
   120 				end--;
       
   121 			}
       
   122 
       
   123 			// Highlight lines
       
   124 			TraceViewerGlobals.getTraceViewer().getView().highlightLines(start,
       
   125 					end, true);
       
   126 
       
   127 		} else {
       
   128 			ret = TVAPIError.TRACE_VIEW_NOT_OPEN;
       
   129 		}
       
   130 
       
   131 		return ret;
       
   132 	}
       
   133 
       
   134 }