trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/dialog/ProgressBarCloseHandler.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  * Handles surviving from manual closing of progressbar
       
    17  *
       
    18  */
       
    19 package com.nokia.traceviewer.dialog;
       
    20 
       
    21 import org.eclipse.swt.widgets.Shell;
       
    22 
       
    23 import com.nokia.traceviewer.action.LogSaveAsciiAction;
       
    24 import com.nokia.traceviewer.action.LogSaveBinaryAction;
       
    25 import com.nokia.traceviewer.action.PauseAction;
       
    26 import com.nokia.traceviewer.engine.TraceViewerGlobals;
       
    27 import com.nokia.traceviewer.engine.dataprocessor.FilterProcessor;
       
    28 
       
    29 /**
       
    30  * Handles surviving from manual closing of progressbar
       
    31  * 
       
    32  */
       
    33 public final class ProgressBarCloseHandler {
       
    34 
       
    35 	/**
       
    36 	 * Waiting time for dataprocessors to stop
       
    37 	 */
       
    38 	private static final int WAITING_TIME = 1500;
       
    39 
       
    40 	/**
       
    41 	 * Progressbar closed, handle it
       
    42 	 * 
       
    43 	 * @param maxLines
       
    44 	 *            max lines in progressbar
       
    45 	 * @return true if progressbar should be closed, false otherwise
       
    46 	 */
       
    47 	public boolean progressBarClosed(int maxLines) {
       
    48 		boolean closeDialog = true;
       
    49 
       
    50 		// Closing from Filtering
       
    51 		if (TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
    52 				.getFilterProcessor().isProcessingFilter()) {
       
    53 			closeDialog = closeFiltering(closeDialog, maxLines);
       
    54 
       
    55 			// Closing from Counting or Variable Tracing
       
    56 		} else if (TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
    57 				.getLineCountProcessor().isProcessingCounting()
       
    58 				|| TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
    59 						.getVariableTracingProcessor().isProcessingTracing()) {
       
    60 			closeDialog = closeCountingOrVariableTracing(closeDialog);
       
    61 
       
    62 			// Closing when saving current traces to a log file
       
    63 		} else if (((LogSaveBinaryAction) TraceViewerGlobals.getTraceViewer()
       
    64 				.getView().getActionFactory().getLogSaveBinaryAction())
       
    65 				.isSavingFile()) {
       
    66 			closeDialog = closeSavingLog();
       
    67 
       
    68 		} else if (((LogSaveAsciiAction) TraceViewerGlobals.getTraceViewer()
       
    69 				.getView().getActionFactory().getLogSaveAsciiAction())
       
    70 				.isSavingFile()) {
       
    71 			closeDialog = closeSavingLog();
       
    72 		}
       
    73 		return closeDialog;
       
    74 	}
       
    75 
       
    76 	/**
       
    77 	 * Closes filtering
       
    78 	 * 
       
    79 	 * @param closeDialog
       
    80 	 *            boolean indicating are we closing the progressbar
       
    81 	 * @param maxLines
       
    82 	 *            maximum lines in progressbar
       
    83 	 * @return true if we are closing the progressbar
       
    84 	 */
       
    85 	private boolean closeFiltering(boolean closeDialog, int maxLines) {
       
    86 		FilterProcessor proc = TraceViewerGlobals.getTraceViewer()
       
    87 				.getDataProcessorAccess().getFilterProcessor();
       
    88 		if (proc.hasRules() || proc.isUsingExternalFilter()) {
       
    89 
       
    90 			// Get close confirmation from the user
       
    91 			String closeConfirmation = Messages
       
    92 					.getString("ProgressBarCloseHandler.CloseFilterConfirmation"); //$NON-NLS-1$
       
    93 			boolean close = TraceViewerGlobals.getTraceViewer().getDialogs()
       
    94 					.showConfirmationDialog(closeConfirmation);
       
    95 
       
    96 			Shell progressShell = TraceViewerGlobals.getTraceViewer()
       
    97 					.getDataProcessorAccess().getFilterProcessor()
       
    98 					.getFilterDialog().getProgressBar().getShell();
       
    99 
       
   100 			// Remove filtering if clicked OK and progressBar shell is still
       
   101 			// open
       
   102 			if (close && progressShell != null && !progressShell.isDisposed()) {
       
   103 				TraceViewerGlobals.getTraceViewer().getDataReaderAccess()
       
   104 						.getMainDataReader().pause(true);
       
   105 				TraceViewerGlobals.getTraceViewer().getDataReaderAccess()
       
   106 						.getCurrentDataReader().shutdown();
       
   107 				// Clear filters
       
   108 				proc.getFilterRules().getFilterRules().clear();
       
   109 
       
   110 				// Wait so dataProcessors have time to stop
       
   111 				try {
       
   112 					Thread.sleep(WAITING_TIME);
       
   113 				} catch (InterruptedException e) {
       
   114 					e.printStackTrace();
       
   115 				}
       
   116 
       
   117 				// Shut down possible external data processor
       
   118 				if (proc.isUsingExternalFilter()) {
       
   119 					proc.getExternalFilterProcessor().stopExternalApplication();
       
   120 					// Remove normal filters
       
   121 				} else {
       
   122 					proc.getFilterDialog().removeFilters(maxLines);
       
   123 				}
       
   124 
       
   125 				PauseAction action = (PauseAction) TraceViewerGlobals
       
   126 						.getTraceViewer().getView().getActionFactory()
       
   127 						.getPauseAction();
       
   128 				action.setPaused(false);
       
   129 			} else {
       
   130 				closeDialog = false;
       
   131 			}
       
   132 		}
       
   133 
       
   134 		return closeDialog;
       
   135 	}
       
   136 
       
   137 	/**
       
   138 	 * Closes line counting or variable tracing
       
   139 	 * 
       
   140 	 * @param closeDialog
       
   141 	 *            boolean indicating are we closing the progressbar
       
   142 	 * @return true if we are closing the progressbar
       
   143 	 */
       
   144 	private boolean closeCountingOrVariableTracing(boolean closeDialog) {
       
   145 		return closeDialog;
       
   146 	}
       
   147 
       
   148 	/**
       
   149 	 * Closes when saving log
       
   150 	 * 
       
   151 	 * @return true if we are closing the progressbar
       
   152 	 */
       
   153 	private boolean closeSavingLog() {
       
   154 
       
   155 		// Get close confirmation from the user
       
   156 		String closeConfirmation = Messages
       
   157 				.getString("ProgressBarCloseHandler.CloseSavingConfirmation"); //$NON-NLS-1$
       
   158 		boolean close = TraceViewerGlobals.getTraceViewer().getDialogs()
       
   159 				.showConfirmationDialog(closeConfirmation);
       
   160 
       
   161 		return close;
       
   162 	}
       
   163 }