trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/dialog/LogAsciiOptionsSelectionDialog.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  * Ascii log options selection Dialog
       
    17  *
       
    18  */
       
    19 package com.nokia.traceviewer.dialog;
       
    20 
       
    21 import org.eclipse.swt.SWT;
       
    22 import org.eclipse.swt.events.SelectionAdapter;
       
    23 import org.eclipse.swt.events.SelectionEvent;
       
    24 import org.eclipse.swt.layout.GridLayout;
       
    25 import org.eclipse.swt.widgets.Button;
       
    26 import org.eclipse.swt.widgets.Shell;
       
    27 import org.eclipse.ui.PlatformUI;
       
    28 
       
    29 import com.nokia.traceviewer.TraceViewerHelpContextIDs;
       
    30 import com.nokia.traceviewer.TraceViewerPlugin;
       
    31 import com.nokia.traceviewer.engine.TraceViewerGlobals;
       
    32 import com.nokia.traceviewer.engine.preferences.PreferenceConstants;
       
    33 
       
    34 /**
       
    35  * Ascii log options selection Dialog
       
    36  */
       
    37 public final class LogAsciiOptionsSelectionDialog extends BaseDialog {
       
    38 
       
    39 	/**
       
    40 	 * Omit timestamps checkbox
       
    41 	 */
       
    42 	private Button omitTimestampCheckBox;
       
    43 
       
    44 	/**
       
    45 	 * Write machine readable log file checkbox
       
    46 	 */
       
    47 	private Button writeMachineReadableLogCheckBox;
       
    48 
       
    49 	/**
       
    50 	 * File path
       
    51 	 */
       
    52 	private final String filePath;
       
    53 
       
    54 	/**
       
    55 	 * Omit timestamp boolean value
       
    56 	 */
       
    57 	private static boolean omitTimestamp;
       
    58 
       
    59 	/**
       
    60 	 * Write machine readable log boolean value
       
    61 	 */
       
    62 	private static boolean writeMachineReadableLog;
       
    63 
       
    64 	/**
       
    65 	 * Constructor
       
    66 	 * 
       
    67 	 * @param parent
       
    68 	 *            parent shell
       
    69 	 * @param filePath
       
    70 	 *            file path of the ascii log
       
    71 	 */
       
    72 	public LogAsciiOptionsSelectionDialog(Shell parent, String filePath) {
       
    73 		super(parent, SWT.DIALOG_TRIM | SWT.MODELESS | SWT.RESIZE);
       
    74 		this.filePath = filePath;
       
    75 	}
       
    76 
       
    77 	/*
       
    78 	 * (non-Javadoc)
       
    79 	 * 
       
    80 	 * @see com.nokia.traceviewer.dialog.BaseDialog#createDialogContents()
       
    81 	 */
       
    82 	@Override
       
    83 	protected void createDialogContents() {
       
    84 		// Shell
       
    85 		GridLayout shellGridLayout = new GridLayout();
       
    86 		String shellTitle = Messages
       
    87 				.getString("LogAsciiOptionsSelectionDialog.ShellTitle"); //$NON-NLS-1$
       
    88 		getShell().setText(shellTitle);
       
    89 		composite.setLayout(shellGridLayout);
       
    90 
       
    91 		// Omit timestamp checkbox
       
    92 		omitTimestampCheckBox = new Button(composite, SWT.CHECK);
       
    93 		omitTimestampCheckBox.setText(Messages
       
    94 				.getString("LogAsciiOptionsSelectionDialog.OmitTimestampText")); //$NON-NLS-1$
       
    95 		omitTimestampCheckBox
       
    96 				.setToolTipText(Messages
       
    97 						.getString("LogAsciiOptionsSelectionDialog.OmitTimestampToolTip")); //$NON-NLS-1$
       
    98 		omitTimestampCheckBox.setSelection(omitTimestamp);
       
    99 		omitTimestampCheckBox.setEnabled(!writeMachineReadableLog);
       
   100 
       
   101 		// Write machine readable log checkbox
       
   102 		writeMachineReadableLogCheckBox = new Button(composite, SWT.CHECK);
       
   103 		String text = Messages
       
   104 				.getString("LogAsciiOptionsSelectionDialog.WriteMachineReadableLogText"); //$NON-NLS-1$
       
   105 		String tooltip = Messages
       
   106 				.getString("LogAsciiOptionsSelectionDialog.WriteMachineReadableLogToolTip"); //$NON-NLS-1$
       
   107 		writeMachineReadableLogCheckBox.setText(text);
       
   108 		writeMachineReadableLogCheckBox.setToolTipText(tooltip);
       
   109 		writeMachineReadableLogCheckBox.setSelection(writeMachineReadableLog);
       
   110 		writeMachineReadableLogCheckBox.setEnabled(!omitTimestamp);
       
   111 
       
   112 		// Set help
       
   113 		PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(),
       
   114 				TraceViewerHelpContextIDs.LOGGING);
       
   115 	}
       
   116 
       
   117 	/*
       
   118 	 * (non-Javadoc)
       
   119 	 * 
       
   120 	 * @see com.nokia.traceviewer.dialog.BaseDialog#createActionListeners()
       
   121 	 */
       
   122 	@Override
       
   123 	protected void createActionListeners() {
       
   124 		// Add selection listener to omit timestamp checkbox
       
   125 		omitTimestampCheckBox.addSelectionListener(new SelectionAdapter() {
       
   126 			@Override
       
   127 			public void widgetSelected(SelectionEvent event) {
       
   128 				boolean selected = omitTimestampCheckBox.getSelection();
       
   129 				TraceViewerGlobals.postUiEvent("OmitTimestampCheckBoxSelection" //$NON-NLS-1$
       
   130 						+ selected, "1"); //$NON-NLS-1$
       
   131 
       
   132 				writeMachineReadableLogCheckBox.setEnabled(!selected);
       
   133 				if (selected) {
       
   134 					writeMachineReadableLogCheckBox.setSelection(false);
       
   135 				}
       
   136 
       
   137 				TraceViewerGlobals.postUiEvent("OmitTimestampCheckBoxSelection" //$NON-NLS-1$
       
   138 						+ selected, "0"); //$NON-NLS-1$
       
   139 			}
       
   140 		});
       
   141 
       
   142 		// Add selection listener to write machine readable log checkbox
       
   143 		writeMachineReadableLogCheckBox
       
   144 				.addSelectionListener(new SelectionAdapter() {
       
   145 					@Override
       
   146 					public void widgetSelected(SelectionEvent event) {
       
   147 						boolean selected = writeMachineReadableLogCheckBox
       
   148 								.getSelection();
       
   149 						TraceViewerGlobals.postUiEvent(
       
   150 								"WriteMachineReadableLogCheckBoxSelection" //$NON-NLS-1$
       
   151 										+ selected, "1"); //$NON-NLS-1$
       
   152 
       
   153 						omitTimestampCheckBox.setEnabled(!selected);
       
   154 						if (selected) {
       
   155 							omitTimestampCheckBox.setSelection(false);
       
   156 						}
       
   157 
       
   158 						TraceViewerGlobals.postUiEvent(
       
   159 								"WriteMachineReadableLogCheckBoxSelection" //$NON-NLS-1$
       
   160 										+ selected, "0"); //$NON-NLS-1$
       
   161 					}
       
   162 				});
       
   163 	}
       
   164 
       
   165 	/*
       
   166 	 * (non-Javadoc)
       
   167 	 * 
       
   168 	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
       
   169 	 */
       
   170 	@Override
       
   171 	protected void okPressed() {
       
   172 		boolean machineReadableSettingChanged = (writeMachineReadableLog != writeMachineReadableLogCheckBox
       
   173 				.getSelection());
       
   174 		omitTimestamp = omitTimestampCheckBox.getSelection();
       
   175 		writeMachineReadableLog = writeMachineReadableLogCheckBox
       
   176 				.getSelection();
       
   177 
       
   178 		super.okPressed();
       
   179 
       
   180 		// If timestamp accuracy is milliseconds, ask if the user wants to
       
   181 		// change it to microseconds
       
   182 		if (writeMachineReadableLog
       
   183 				&& TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   184 						.getTimestampParser().isTimestampAccuracyMilliSecs()) {
       
   185 
       
   186 			// Get change timestamp accuracy confirmation from the user
       
   187 			String changeAccuracyConfirmation = Messages
       
   188 					.getString("LogAsciiOptionsSelectionDialog.ChangeTimestampAccuracyMsg"); //$NON-NLS-1$
       
   189 			boolean changeAccuracy = TraceViewerGlobals.getTraceViewer()
       
   190 					.getDialogs().showConfirmationDialog(
       
   191 							changeAccuracyConfirmation);
       
   192 
       
   193 			// Change the accuracy and save the new value to the preference
       
   194 			// store
       
   195 			if (changeAccuracy) {
       
   196 				TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   197 						.getTimestampParser().setTimestampAccuracyMilliSecs(
       
   198 								false);
       
   199 
       
   200 				TraceViewerPlugin.getDefault().getPreferenceStore().setValue(
       
   201 						PreferenceConstants.TIMESTAMP_ACCURACY,
       
   202 						PreferenceConstants.MICROSECOND_ACCURACY);
       
   203 
       
   204 			}
       
   205 		}
       
   206 
       
   207 		// Start logging
       
   208 		TraceViewerGlobals.getTraceViewer().getDataProcessorAccess()
       
   209 				.getLogger().startPlainTextLogging(filePath, omitTimestamp,
       
   210 						writeMachineReadableLog);
       
   211 
       
   212 		// Insert CloseAndRestartLogging Action button
       
   213 		if (writeMachineReadableLog) {
       
   214 			TraceViewerGlobals.getTraceViewer().getView().getActionFactory()
       
   215 					.addCloseAndRestartLoggingButton(filePath);
       
   216 		} else if (machineReadableSettingChanged) {
       
   217 			TraceViewerGlobals.getTraceViewer().getView().getActionFactory()
       
   218 					.removeCloseAndRestartLoggingButton();
       
   219 		}
       
   220 	}
       
   221 }