sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/preferences/AnalyzeToolPreferencePage.java
changeset 15 0367d2db2c06
parent 6 f65f740e69f9
equal deleted inserted replaced
14:bb339882c6e9 15:0367d2db2c06
    14  * Description:  Definitions for the class AnalyzeToolPreferencePage
    14  * Description:  Definitions for the class AnalyzeToolPreferencePage
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 package com.nokia.s60tools.analyzetool.preferences;
    18 package com.nokia.s60tools.analyzetool.preferences;
       
    19 
       
    20 import java.io.File;
       
    21 import java.text.MessageFormat;
    19 
    22 
    20 import org.eclipse.core.runtime.IPath;
    23 import org.eclipse.core.runtime.IPath;
    21 import org.eclipse.core.runtime.Path;
    24 import org.eclipse.core.runtime.Path;
    22 import org.eclipse.jface.preference.FieldEditorPreferencePage;
    25 import org.eclipse.jface.preference.FieldEditorPreferencePage;
    23 import org.eclipse.jface.preference.IPreferenceStore;
    26 import org.eclipse.jface.preference.IPreferenceStore;
    36 import org.eclipse.swt.widgets.Text;
    39 import org.eclipse.swt.widgets.Text;
    37 import org.eclipse.ui.IWorkbench;
    40 import org.eclipse.ui.IWorkbench;
    38 import org.eclipse.ui.IWorkbenchPreferencePage;
    41 import org.eclipse.ui.IWorkbenchPreferencePage;
    39 import org.eclipse.ui.PlatformUI;
    42 import org.eclipse.ui.PlatformUI;
    40 
    43 
       
    44 import com.nokia.carbide.cpp.epoc.engine.image.ISVGSource;
    41 import com.nokia.s60tools.analyzetool.Activator;
    45 import com.nokia.s60tools.analyzetool.Activator;
    42 import com.nokia.s60tools.analyzetool.AnalyzeToolHelpContextIDs;
    46 import com.nokia.s60tools.analyzetool.AnalyzeToolHelpContextIDs;
    43 import com.nokia.s60tools.analyzetool.global.Constants;
    47 import com.nokia.s60tools.analyzetool.global.Constants;
    44 import com.nokia.s60tools.analyzetool.global.Util;
    48 import com.nokia.s60tools.analyzetool.global.Util;
    45 import com.nokia.s60tools.analyzetool.ui.IActionListener;
    49 import com.nokia.s60tools.analyzetool.ui.IActionListener;
    46 
    50 
    47 /**
    51 /**
    48  * This class represents a preference page that is contributed to the
    52  * This class represents a preference page that is contributed to the
    49  * Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>,
    53  * Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>, we
    50  * we can use the field support built into JFace that allows us to create a page
    54  * can use the field support built into JFace that allows us to create a page
    51  * that is small and knows how to save, restore and apply itself.
    55  * that is small and knows how to save, restore and apply itself.
    52  * <p>
    56  * <p>
    53  * This page is used to modify preferences only. They are stored in the
    57  * This page is used to modify preferences only. They are stored in the
    54  * preference store that belongs to the main plug-in class. That way,
    58  * preference store that belongs to the main plug-in class. That way,
    55  * preferences can be accessed directly via the preference store.
    59  * preferences can be accessed directly via the preference store.
    56  */
    60  */
    57 
    61 
    58 public class AnalyzeToolPreferencePage extends FieldEditorPreferencePage
    62 public class AnalyzeToolPreferencePage extends FieldEditorPreferencePage
    59 		implements IWorkbenchPreferencePage, Listener{
    63 		implements IWorkbenchPreferencePage, Listener {
    60 
    64 
    61 	/** Button to ask always. */
    65 	/** Button to ask always. */
    62 	Button askButton = null;
    66 	Button askButton = null;
    63 
    67 
    64 	/** Atool.exe path field. */
    68 	/** Atool.exe path field. */
    71 	Label atoolVerLabel;
    75 	Label atoolVerLabel;
    72 
    76 
    73 	/** Browse button to active file selection dialog. */
    77 	/** Browse button to active file selection dialog. */
    74 	Button browseButton = null;
    78 	Button browseButton = null;
    75 
    79 
    76 	/** Button to activate/deactivate statistic generation */
       
    77 	//Button generateStatistic = null;
       
    78 
       
    79 	/** Group for callstack size buttons. */
    80 	/** Group for callstack size buttons. */
    80 	Group csSizeGroup;
    81 	Group csSizeGroup;
    81 
    82 
    82 	/** Custom items button */
    83 	/** Custom items button */
    83 	Button customButton;
    84 	Button customButton;
    86 	Button fortyButton;
    87 	Button fortyButton;
    87 
    88 
    88 	/** Hundred items button */
    89 	/** Hundred items button */
    89 	Button hundredButton;
    90 	Button hundredButton;
    90 
    91 
    91 	/** Button to use process data. */
       
    92 	Button processButton = null;
       
    93 
       
    94 	/** Button to refresh atool.exe version. */
       
    95 	Button refreshAtoolVersion = null;
       
    96 
       
    97 	/** Radio group for report level. */
    92 	/** Radio group for report level. */
    98 	RadioGroupFieldEditor reportLevels = null;
    93 	RadioGroupFieldEditor reportLevels = null;
    99 
    94 
   100 	/** Button to use S60 file mode. */
    95 	/** Button to use S60 file mode. */
   101 	Button s60Button = null;
    96 	Button s60Button = null;
   110 	 * Button to use default atool.exe location this means that atool.exe is
   105 	 * Button to use default atool.exe location this means that atool.exe is
   111 	 * executed inside AnalyzeTool jar.
   106 	 * executed inside AnalyzeTool jar.
   112 	 */
   107 	 */
   113 	Button useDefaultLocation = null;
   108 	Button useDefaultLocation = null;
   114 
   109 
   115 	/** Button to use user specified data file name. */
       
   116 	Button userButton = null;
       
   117 
       
   118 	/** Use user specified location. */
   110 	/** Use user specified location. */
   119 	Button useUserSpecified = null;
   111 	Button useUserSpecified = null;
   120 
   112 
   121 	/** Button to verbose atool.exe output. */
   113 	/** Button to verbose atool.exe output. */
   122 	Button verboseButton = null;
   114 	Button verboseButton = null;
   123 
   115 
   124 	/** Button to select TraceViewer connection. */
       
   125 	Button externalButton = null;
       
   126 
       
   127 	/** Button to select fast external data gathering mode */
   116 	/** Button to select fast external data gathering mode */
   128 	Button externalFastButton = null;
   117 	Button externalFastButton = null;
   129 
   118 
   130 	/** No items button. */
   119 	/** No items button. */
   131 	Button zeroButton;
   120 	Button zeroButton;
   132 
   121 
       
   122 	Label logPath;
       
   123 	Text logPathText;
       
   124 	Label fileName;
       
   125 	Text fileNameText;
   133 
   126 
   134 	/**
   127 	/**
   135 	 * Constructor.
   128 	 * Constructor.
   136 	 */
   129 	 */
   137 	public AnalyzeToolPreferencePage() {
   130 	public AnalyzeToolPreferencePage() {
   144 	 * Checks preferences initial values if logging mode is not set to S60
   137 	 * Checks preferences initial values if logging mode is not set to S60
   145 	 * disables S60 data file name selections.
   138 	 * disables S60 data file name selections.
   146 	 */
   139 	 */
   147 	public final void checkInitValues() {
   140 	public final void checkInitValues() {
   148 		IPreferenceStore store = Activator.getPreferences();
   141 		IPreferenceStore store = Activator.getPreferences();
   149 		
   142 
   150 		// get stored atool folder
   143 		// get stored atool folder
   151 		String atoolFolder = store.getString(Constants.ATOOL_FOLDER);
   144 		String atoolFolder = store.getString(Constants.ATOOL_FOLDER);
   152 		atoolVerLabel.setText(Constants.PREFS_ATOOL_VER_NOT_FOUND);
   145 		atoolVerLabel.setText(Constants.PREFS_ATOOL_VER_NOT_FOUND);
   153 
   146 
   154 		// if atool folder is set to point default atool location
   147 		// if atool folder is set to point default atool location
   155 		if (atoolFolder.equals(Constants.DEFAULT_ATOOL_FOLDER)) {
   148 		if (atoolFolder.equals(Constants.DEFAULT_ATOOL_FOLDER)) {
   156 
   149 
   157 			// check that stored atool location exists
   150 			// check that stored atool location exists
   158 			java.io.File file = new java.io.File(atoolFolder);
   151 			File file = new File(atoolFolder);
   159 			if (file.exists()) { // if exists use this location and update
   152 			if (file.exists()) { // if exists use this location and update
   160 				// preference page buttons
   153 				// preference page buttons
   161 				useDefaultLocation.setSelection(false);
   154 				useDefaultLocation.setSelection(false);
   162 				store.setValue(Constants.USE_INTERNAL, false);
   155 				store.setValue(Constants.USE_INTERNAL, false);
   163 
   156 
   164 			} else { // location could not found => use internal atool
   157 			} else { // location could not found => use internal atool
   165 				useDefaultLocation.setSelection(true);
   158 				useDefaultLocation.setSelection(true);
   166 				store.setValue(Constants.USE_INTERNAL, true);
   159 				store.setValue(Constants.USE_INTERNAL, true);
   167 
       
   168 			}
   160 			}
   169 		} else {
   161 		} else {
   170 			boolean useDef = store.getBoolean(Constants.USE_INTERNAL);
   162 			boolean useDef = store.getBoolean(Constants.USE_INTERNAL);
   171 			useDefaultLocation.setSelection(useDef);
   163 			useDefaultLocation.setSelection(useDef);
   172 
       
   173 		}
   164 		}
   174 
   165 
   175 		// get atool.exe path and set it atool.exe path field
   166 		// get atool.exe path and set it atool.exe path field
   176 		String atoolPath = store.getString(Constants.USER_SELECTED_FOLDER);
   167 		String atoolPath = store.getString(Constants.USER_SELECTED_FOLDER);
   177 		atoolDirText.setText(atoolPath);
   168 		atoolDirText.setText(atoolPath);
   178 
   169 
   179 		// update preference page buttons
   170 		// update preference page buttons
   180 		handleDefaultLocationChange();
   171 		handleDefaultLocationChange();
   181 
   172 
   182 		// update atool.exe version number
       
   183 		if (useDefaultLocation.getSelection()) {
       
   184 			updateAtoolVersion(null);
       
   185 		} else {
       
   186 			updateAtoolVersion(atoolDirText.getText());
       
   187 		}
       
   188 
       
   189 		// get logging mode and update buttons
   173 		// get logging mode and update buttons
   190 		String fileMode = store.getString(Constants.LOGGING_MODE);
   174 		String fileMode = store.getString(Constants.LOGGING_MODE);
   191 		setGroupButtons(fileMode);
   175 		setGroupButtons(fileMode);
   192 
   176 
   193 		String loggingMode = store.getString(Constants.S60_LOG_FILE_MODE);
   177 		logPathText.setText(store.getString(Constants.DEVICE_LOG_FILE_PATH));
   194 		if (loggingMode.equals(Constants.LOGGING_S60_USER_SPECIFIED)) {
   178 		fileNameText.setText(store.getString(Constants.DEVICE_LOG_FILE_NAME));
   195 			processButton.setSelection(false);
   179 
   196 			userButton.setSelection(true);
   180 		logPathText.setText(store.getString(Constants.DEVICE_LOG_FILE_PATH));
   197 		} else {
   181 		fileNameText.setText(store.getString(Constants.DEVICE_LOG_FILE_NAME));
   198 			processButton.setSelection(true);
       
   199 			userButton.setSelection(false);
       
   200 		}
       
   201 
   182 
   202 		verboseButton.setSelection(store.getBoolean(Constants.ATOOL_VERBOSE));
   183 		verboseButton.setSelection(store.getBoolean(Constants.ATOOL_VERBOSE));
   203 		//generateStatistic.setSelection(store.getBoolean(Constants.CREATE_STATISTIC));
       
   204 
   184 
   205 		// get stored callstack size
   185 		// get stored callstack size
   206 		int callstackSize = store.getInt(Constants.CALLSTACK_SIZE);
   186 		int callstackSize = store.getInt(Constants.CALLSTACK_SIZE);
   207 		if (callstackSize == 0) {
   187 		if (callstackSize == 0) {
   208 			zeroButton.setSelection(true);
   188 			zeroButton.setSelection(true);
   218 			// enable spinner and set stored callstack size
   198 			// enable spinner and set stored callstack size
   219 			customButton.setSelection(true);
   199 			customButton.setSelection(true);
   220 			spinner.setEnabled(true);
   200 			spinner.setEnabled(true);
   221 			spinner.setSelection(callstackSize);
   201 			spinner.setSelection(callstackSize);
   222 		}
   202 		}
   223 		
       
   224 	}
   203 	}
   225 
   204 
   226 	/**
   205 	/**
   227 	 * Check if user entered folder location is available.
   206 	 * Check if user entered folder location is available.
   228 	 *
   207 	 * 
   229 	 * @param folderLocation
   208 	 * @param folderLocation
   230 	 *            User entered folder location
   209 	 *            User entered folder location
   231 	 * @return True if folder exists otherwise False
   210 	 * @return True if folder exists otherwise False
   232 	 */
   211 	 */
   233 	public final boolean checkIfFolderExists(final String folderLocation) {
   212 	public final boolean checkIfFolderExists(final String folderLocation) {
   299 	}
   278 	}
   300 
   279 
   301 	/**
   280 	/**
   302 	 * Creates data gathering group items
   281 	 * Creates data gathering group items
   303 	 */
   282 	 */
   304 	private void createGatheringGroup()
   283 	private void createGatheringGroup() {
   305 	{
       
   306 		// create new button group for logging mode
   284 		// create new button group for logging mode
   307 		Group groupGatheringMode = new Group(getFieldEditorParent(), SWT.NULL);
   285 		Group groupGatheringMode = new Group(getFieldEditorParent(), SWT.NULL);
   308 		groupGatheringMode.setText(Constants.PREFS_LOGGING_MODE_TITLE);
   286 		groupGatheringMode.setText(Constants.PREFS_LOGGING_MODE_TITLE);
   309 
   287 
   310 		// set group layout
   288 		// set group layout
   313 		groupGatheringMode.setLayout(layoutLogMode);
   291 		groupGatheringMode.setLayout(layoutLogMode);
   314 
   292 
   315 		GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
   293 		GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
   316 		gridData.horizontalSpan = 1;
   294 		gridData.horizontalSpan = 1;
   317 		groupGatheringMode.setLayoutData(gridData);
   295 		groupGatheringMode.setLayoutData(gridData);
   318 
       
   319 		// External mode button
       
   320 		externalButton = new Button(groupGatheringMode, SWT.RADIO);
       
   321 		externalButton.setToolTipText(Constants.PREFS_EXT_TOOLTIP);
       
   322 		externalButton.setText(Constants.PREFS_EXT);
       
   323 		externalButton.addListener(SWT.Selection, this);
       
   324 
   296 
   325 		// External fast mode button
   297 		// External fast mode button
   326 		externalFastButton = new Button(groupGatheringMode, SWT.RADIO);
   298 		externalFastButton = new Button(groupGatheringMode, SWT.RADIO);
   327 		externalFastButton.setToolTipText(Constants.PREFS_EXT_FAST_TOOLTIP);
   299 		externalFastButton.setToolTipText(Constants.PREFS_EXT_FAST_TOOLTIP);
   328 		externalFastButton.setText(Constants.PREFS_EXT_FAST);
   300 		externalFastButton.setText(Constants.PREFS_EXT_FAST);
   332 		s60Button = new Button(groupGatheringMode, SWT.RADIO);
   304 		s60Button = new Button(groupGatheringMode, SWT.RADIO);
   333 		s60Button.setToolTipText(Constants.PREFS_S60_TOOLTIP);
   305 		s60Button.setToolTipText(Constants.PREFS_S60_TOOLTIP);
   334 		s60Button.setText(Constants.PREFS_S60);
   306 		s60Button.setText(Constants.PREFS_S60);
   335 		s60Button.addListener(SWT.Selection, this);
   307 		s60Button.addListener(SWT.Selection, this);
   336 
   308 
   337 		Composite compStoreMode = new Composite(groupGatheringMode, SWT.NULL);
   309 		Composite compS60 = new Composite(groupGatheringMode, SWT.NULL);
   338 
   310 
   339 		final GridLayout layoutStoreMode = new GridLayout();
   311 		final GridLayout layoutS60 = new GridLayout();
   340 		layoutStoreMode.marginLeft = 15;
   312 		layoutS60.marginLeft = 15;
   341 		layoutStoreMode.numColumns = 1;
   313 		layoutS60.numColumns = 2;
   342 		compStoreMode.setLayout(layoutStoreMode);
   314 		compS60.setLayout(layoutS60);
   343 
   315 
   344 		// use process name button
   316 		// path label
   345 		processButton = new Button(compStoreMode, SWT.RADIO);
   317 		logPath = new Label(compS60, SWT.NONE);
   346 		processButton.setToolTipText(Constants.PREFS_USE_PROCESS_NAME_TOOLTIP);
   318 		logPath.setToolTipText("Log file path in the device.");
   347 		processButton.setText(Constants.PREFS_USE_PROCESS_NAME);
   319 		logPath.setText("Log file path:");
   348 		processButton.addListener(SWT.Selection, this);
   320 
   349 
   321 		// path field
   350 		// user specified button
   322 		logPathText = new Text(compS60, SWT.BORDER);
   351 		userButton = new Button(compStoreMode, SWT.RADIO);
   323 		logPathText.setLayoutData(new GridData(280, SWT.DEFAULT));
   352 		userButton.setToolTipText(Constants.PREFS_USER_SPEC_TOOLTIP);
   324 		logPathText.setText("C:\\logs\\atool\\");
   353 		userButton.setText(Constants.PREFS_USER_SPEC);
   325 
   354 		userButton.addListener(SWT.Selection, this);
   326 		// filename label
       
   327 		fileName = new Label(compS60, SWT.NONE);
       
   328 		fileName.setToolTipText("Log file name.");
       
   329 		fileName.setText("Filename:");
       
   330 
       
   331 		// filename field
       
   332 		fileNameText = new Text(compS60, SWT.BORDER);
       
   333 		fileNameText.setLayoutData(new GridData(280, SWT.DEFAULT));
       
   334 		fileNameText.setText("%processname%.dat");
   355 
   335 
   356 		// ask always button
   336 		// ask always button
   357 		askButton = new Button(groupGatheringMode, SWT.RADIO);
   337 		askButton = new Button(groupGatheringMode, SWT.RADIO);
   358 		askButton.setToolTipText(Constants.PREFS_ASK_ALWAYS_TOOLTIP);
   338 		askButton.setToolTipText(Constants.PREFS_ASK_ALWAYS_TOOLTIP);
   359 		askButton.setText(Constants.PREFS_ASK_ALWAYS);
   339 		askButton.setText(Constants.PREFS_ASK_ALWAYS);
   360 		askButton.addListener(SWT.Selection, this);
   340 		askButton.addListener(SWT.Selection, this);
   361 
   341 	}
   362 	}
   342 
   363 	/**
   343 	/**
   364 	 * Creates the field editors. Field editors are abstractions of the common
   344 	 * Creates the field editors. Field editors are abstractions of the common
   365 	 * GUI blocks needed to manipulate various types of preferences. Each field
   345 	 * GUI blocks needed to manipulate various types of preferences. Each field
   366 	 * editor knows how to save and restore itself.
   346 	 * editor knows how to save and restore itself.
   367 	 */
   347 	 */
   368 	@Override
   348 	@Override
   369 	public final void createFieldEditors() {
   349 	public final void createFieldEditors() {
   370 		
   350 
   371 		Composite composite = new Composite(getFieldEditorParent(), SWT.NULL);
   351 		Composite composite = new Composite(getFieldEditorParent(), SWT.NULL);
   372 		final GridLayout gridLayout = new GridLayout();
   352 		final GridLayout gridLayout = new GridLayout();
   373 		gridLayout.numColumns = 3;
   353 		gridLayout.numColumns = 3;
   374 
   354 
   375 		// set layoyt of this view
   355 		// set layoyt of this view
   413 		atoolDir.setToolTipText(Constants.PREFS_SELECT_FOLDER);
   393 		atoolDir.setToolTipText(Constants.PREFS_SELECT_FOLDER);
   414 		atoolDir.setText(Constants.PREFS_ATOOL_PATH);
   394 		atoolDir.setText(Constants.PREFS_ATOOL_PATH);
   415 
   395 
   416 		// directory field
   396 		// directory field
   417 		atoolDirText = new Text(compAtool, SWT.BORDER);
   397 		atoolDirText = new Text(compAtool, SWT.BORDER);
       
   398 		atoolDirText.setEditable(false);
   418 		atoolDirText.setLayoutData(new GridData(200, SWT.DEFAULT));
   399 		atoolDirText.setLayoutData(new GridData(200, SWT.DEFAULT));
   419 
   400 
   420 		// button which opens the folder selection dialog
   401 		// button which opens the folder selection dialog
   421 		browseButton = new Button(compAtool, SWT.NONE);
   402 		browseButton = new Button(compAtool, SWT.NONE);
   422 		browseButton.setToolTipText(Constants.PREFS_SELECT_FOLDER);
   403 		browseButton.setToolTipText(Constants.PREFS_SELECT_FOLDER);
   423 		browseButton.setText(Constants.PREFS_BROWSE);
   404 		browseButton.setText(Constants.PREFS_BROWSE);
   424 		browseButton.addListener(SWT.Selection, this);
   405 		browseButton.addListener(SWT.Selection, this);
   425 
   406 
   426 		// generate statistics for the test run
       
   427 		/*
       
   428 		generateStatistic = new Button(groupAtool, SWT.CHECK);
       
   429 		generateStatistic.setText("Generate statistics");
       
   430 		generateStatistic.setToolTipText("Generate statistics");
       
   431 		*/
       
   432 		// verbose atool.exe output
   407 		// verbose atool.exe output
   433 		verboseButton = new Button(groupAtool, SWT.CHECK);
   408 		verboseButton = new Button(groupAtool, SWT.CHECK);
   434 		verboseButton.setText(Constants.PREFS_VERBOSE);
   409 		verboseButton.setText(Constants.PREFS_VERBOSE);
   435 		verboseButton.setToolTipText(Constants.PREFS_VERBOSE_TOOLTIP);
   410 		verboseButton.setToolTipText(Constants.PREFS_VERBOSE_TOOLTIP);
   436 
   411 
   453 		// create atool.exe version field and set layout
   428 		// create atool.exe version field and set layout
   454 		atoolVerLabel = new Label(groupVersion, SWT.NONE);
   429 		atoolVerLabel = new Label(groupVersion, SWT.NONE);
   455 		GridData vergd13 = new GridData(GridData.FILL_HORIZONTAL);
   430 		GridData vergd13 = new GridData(GridData.FILL_HORIZONTAL);
   456 		vergd13.horizontalSpan = 2;
   431 		vergd13.horizontalSpan = 2;
   457 		atoolVerLabel.setLayoutData(vergd13);
   432 		atoolVerLabel.setLayoutData(vergd13);
   458 
       
   459 		// create button to refresh atool.exe version
       
   460 		refreshAtoolVersion = new Button(groupVersion, SWT.NONE);
       
   461 		refreshAtoolVersion.setText(Constants.PREFS_REFRESH_VERSION);
       
   462 		refreshAtoolVersion.addListener(SWT.Selection, this);
       
   463 
   433 
   464 		// create data gathering group
   434 		// create data gathering group
   465 		createGatheringGroup();
   435 		createGatheringGroup();
   466 
   436 
   467 		// create callstack size group
   437 		// create callstack size group
   475 						{ Constants.PREFS_SHOW_TOPMOST,
   445 						{ Constants.PREFS_SHOW_TOPMOST,
   476 								Constants.REPORT_TOPMOST } },
   446 								Constants.REPORT_TOPMOST } },
   477 				getFieldEditorParent(), true);
   447 				getFieldEditorParent(), true);
   478 
   448 
   479 		addField(reportLevels);
   449 		addField(reportLevels);
   480 		
   450 
   481 		checkInitValues();
   451 		checkInitValues();
   482 		PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(),
   452 		PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(),
   483 				AnalyzeToolHelpContextIDs.ANALYZE_TOOL_VIEW_MEM_LEAKS);
   453 				AnalyzeToolHelpContextIDs.ANALYZE_TOOL_VIEW_MEM_LEAKS);
   484 
   454 	}
   485 	}
   455 
   486 
   456 	@Override
   487 	/**
   457 	protected void checkState() {
   488 	 * Handles atool.exe location selection changes Update corresponding buttons
   458 		super.checkState();
   489 	 * states.
   459 
       
   460 		String path;
       
   461 
       
   462 		if (useDefaultLocation.getSelection()) {
       
   463 			path = null;
       
   464 		} else {
       
   465 			path = atoolDirText.getText();
       
   466 		}
       
   467 
       
   468 		if (Util.getAtoolVersionNumber(path).equals(
       
   469 				Constants.PREFS_ATOOL_VER_NOT_FOUND)) {
       
   470 			setErrorMessage(Constants.PREFS_CLE_NOT_AVAILABLE);
       
   471 			setValid(false);
       
   472 		} else if (Util.compareVersionNumber(Util.getAtoolVersionNumber(path),
       
   473 				Constants.MIN_CLE_SUPPORTED) == Constants.VERSION_NUMBERS_SECOND) {
       
   474 			setErrorMessage(MessageFormat.format(
       
   475 					Constants.PREFS_CLE_OLDER_THAN_MIN,
       
   476 					Constants.MIN_CLE_SUPPORTED));
       
   477 			setValid(false);
       
   478 		} else {
       
   479 			setErrorMessage(null);
       
   480 			setValid(true);
       
   481 		}
       
   482 	}
       
   483 
       
   484 	/**
       
   485 	 * Handles atool.exe location selection changes. Update corresponding
       
   486 	 * buttons states.
   490 	 */
   487 	 */
   491 	public final void handleDefaultLocationChange() {
   488 	public final void handleDefaultLocationChange() {
   492 		if (useDefaultLocation.getSelection()) {
   489 		if (useDefaultLocation.getSelection()) {
   493 			atoolDirText.setEnabled(false);
   490 			atoolDirText.setEnabled(false);
   494 			browseButton.setEnabled(false);
   491 			browseButton.setEnabled(false);
   495 			atoolDir.setEnabled(false);
   492 			atoolDir.setEnabled(false);
   496 			useUserSpecified.setSelection(false);
   493 			useUserSpecified.setSelection(false);
       
   494 			updateAtoolVersion(null);
   497 		} else {
   495 		} else {
   498 			atoolDirText.setEnabled(true);
   496 			atoolDirText.setEnabled(true);
   499 			browseButton.setEnabled(true);
   497 			browseButton.setEnabled(true);
   500 			atoolDir.setEnabled(true);
   498 			atoolDir.setEnabled(true);
   501 			useUserSpecified.setSelection(true);
   499 			useUserSpecified.setSelection(true);
   502 		}
   500 			updateAtoolVersion(atoolDirText.getText());
   503 	}
   501 		}
   504 	
   502 	}
       
   503 
   505 	/*
   504 	/*
   506 	 * (non-Javadoc)
   505 	 * (non-Javadoc)
   507 	 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
   506 	 * 
       
   507 	 * @see
       
   508 	 * org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
       
   509 	 * Event)
   508 	 */
   510 	 */
   509 	public final void handleEvent(final Event event) {
   511 	public final void handleEvent(final Event event) {
   510 		if (event.widget == browseButton) {
   512 		if (event.widget == browseButton) {
   511 			openFolderDialog();
   513 			openFolderDialog();
   512 		} else if (event.widget == externalButton || event.widget == externalFastButton || event.widget == askButton ) {
   514 		} else if (event.widget == externalFastButton
   513 			userButton.setEnabled(false);
   515 				|| event.widget == askButton) {
   514 			processButton.setEnabled(false);
   516 			setFileModeEnabled(false);
   515 		} else if (event.widget == s60Button) {
   517 		} else if (event.widget == s60Button) {
   516 			userButton.setEnabled(true);
   518 			setFileModeEnabled(true);
   517 			processButton.setEnabled(true);
       
   518 		} else if (event.widget == useDefaultLocation
   519 		} else if (event.widget == useDefaultLocation
   519 				|| event.widget == atoolDir) {
   520 				|| event.widget == atoolDir) {
   520 			handleDefaultLocationChange();
   521 			handleDefaultLocationChange();
   521 		} else if (event.widget == refreshAtoolVersion) {
       
   522 			if (useDefaultLocation.getSelection()) {
       
   523 				updateAtoolVersion(null);
       
   524 			} else {
       
   525 				updateAtoolVersion(atoolDirText.getText());
       
   526 			}
       
   527 		} else if (event.widget == zeroButton || event.widget == fortyButton
   522 		} else if (event.widget == zeroButton || event.widget == fortyButton
   528 				|| event.widget == hundredButton) {
   523 				|| event.widget == hundredButton) {
   529 			spinner.setEnabled(false);
   524 			spinner.setEnabled(false);
   530 		} else if (event.widget == customButton) {
   525 		} else if (event.widget == customButton) {
   531 			spinner.setEnabled(true);
   526 			spinner.setEnabled(true);
   532 		}
   527 		}
   533 	}
   528 	}
   534 
   529 
   535 	/*
   530 	/*
   536 	 * (non-Javadoc)
   531 	 * (non-Javadoc)
   537 	 *
   532 	 * 
   538 	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
   533 	 * @see
       
   534 	 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
   539 	 */
   535 	 */
   540 	public void init(final IWorkbench workbench) {
   536 	public void init(final IWorkbench workbench) {
   541 		// MethodDeclaration/Block[count(BlockStatement) = 0 and
   537 		// MethodDeclaration/Block[count(BlockStatement) = 0 and
   542 		// @containsComment = 'false']
   538 		// @containsComment = 'false']
   543 	}
   539 	}
   551 		folderDialog.setText(Constants.PREFS_SELECT_DIR);
   547 		folderDialog.setText(Constants.PREFS_SELECT_DIR);
   552 		folderDialog.setFilterPath(atoolDirText.getText());
   548 		folderDialog.setFilterPath(atoolDirText.getText());
   553 		String folderPath = folderDialog.open();
   549 		String folderPath = folderDialog.open();
   554 		if (folderPath != null) {
   550 		if (folderPath != null) {
   555 			atoolDirText.setText(folderPath);
   551 			atoolDirText.setText(folderPath);
       
   552 			updateAtoolVersion(atoolDirText.getText());
   556 		}
   553 		}
   557 	}
   554 	}
   558 
   555 
   559 	/**
   556 	/**
   560 	 * Perform defaults for AnalyzeTool preferences.
   557 	 * Perform defaults for AnalyzeTool preferences.
   561 	 */
   558 	 */
   562 	@Override
   559 	@Override
   563 	public final void performDefaults() {
   560 	public final void performDefaults() {
   564 		//check that AT prefs page is displayed
   561 		setGroupButtons(Constants.LOGGING_EXT_FAST);
   565 		//if( getControl() != null && getControl().isVisible() ) {
   562 		atoolDirText.setText(Constants.DEFAULT_ATOOL_FOLDER);
   566 
   563 		useDefaultLocation.setSelection(true);
   567 			processButton.setSelection(true);
   564 		handleDefaultLocationChange();
   568 			userButton.setSelection(false);
   565 		verboseButton.setSelection(false);
   569 			setGroupButtons(Constants.LOGGING_EXT);
   566 		zeroButton.setSelection(false);
   570 
   567 		fortyButton.setSelection(true);
   571 			atoolDirText.setText(Constants.DEFAULT_ATOOL_FOLDER);
   568 		hundredButton.setSelection(false);
   572 			useDefaultLocation.setSelection(true);
   569 		customButton.setSelection(false);
   573 			handleDefaultLocationChange();
   570 		spinner.setEnabled(false);
   574 			verboseButton.setSelection(false);
   571 
   575 			zeroButton.setSelection(false);
   572 		logPathText.setText("C:\\logs\\atool\\");
   576 			fortyButton.setSelection(true);
   573 		fileNameText.setText("%processname%.dat");
   577 			hundredButton.setSelection(false);
       
   578 			customButton.setSelection(false);
       
   579 			spinner.setEnabled(false);
       
   580 			
       
   581 			//generateStatistic.setSelection(false);
       
   582 			super.performDefaults();	
       
   583 		//}
       
   584 	}
   574 	}
   585 
   575 
   586 	/**
   576 	/**
   587 	 * Stores selected values When user press "Ok" or "apply" button this method
   577 	 * Stores selected values When user press "Ok" or "apply" button this method
   588 	 * is called
   578 	 * is called
   589 	 */
   579 	 */
   590 	@Override
   580 	@Override
   591 	public final boolean performOk() {
   581 	public final boolean performOk() {
   592 		
   582 
   593 		//check that AT prefs page is displayed
   583 		IPreferenceStore store = Activator.getPreferences();
   594 		//if( getControl() != null && getControl().isVisible() ) {
   584 
   595 			IPreferenceStore store = Activator.getPreferences();
   585 		// use default location is selected
   596 			String atoolFolder = atoolDirText.getText();
   586 		if (useDefaultLocation.getSelection()) {
   597 
   587 			store.setValue(Constants.ATOOL_FOLDER, Util
   598 			// use default location is selected
   588 					.getDefaultAtoolLocation());
   599 			if (useDefaultLocation.getSelection()) {
   589 			store.setValue(Constants.USE_INTERNAL, true);
   600 				store.setValue(Constants.ATOOL_FOLDER, Util
   590 		}
   601 						.getDefaultAtoolLocation());
   591 		// using user specified atool.exe location and the folder contains
   602 				store.setValue(Constants.USE_INTERNAL, true);
   592 		// atool.exe
   603 			}
   593 		else {
   604 			// using user specified atool.exe location and the folder contains
   594 			store.setValue(Constants.ATOOL_FOLDER, atoolDirText.getText());
   605 			// atool.exe
   595 			store.setValue(Constants.USER_SELECTED_FOLDER, atoolDirText
   606 			else if (checkIfFolderExists(atoolFolder)) {
   596 					.getText());
   607 				store.setValue(Constants.ATOOL_FOLDER, atoolFolder);
   597 			store.setValue(Constants.USE_INTERNAL, false);
   608 				store.setValue(Constants.USER_SELECTED_FOLDER, atoolFolder);
   598 		}
   609 				store.setValue(Constants.USE_INTERNAL, false);
   599 
   610 			}
   600 		// store logging mode
   611 			// user selected folder does not contain atool.exe
   601 		if (askButton.getSelection()) {
   612 			// ask confirmation to use this folder anyway
   602 			store.setValue(Constants.LOGGING_MODE,
   613 			else {
   603 					Constants.LOGGING_ASK_ALLWAYS);
   614 				boolean ret = Util
   604 		} else if (s60Button.getSelection()) {
   615 						.openConfirmationDialog(Constants.CONFIRM_DIR_DOES_NOT_CONTAIN_ATOOL);
   605 			store.setValue(Constants.LOGGING_MODE, Constants.LOGGING_S60);
   616 				if (ret) {
   606 		} else if (externalFastButton.getSelection()) {
   617 
   607 			store.setValue(Constants.LOGGING_MODE, Constants.LOGGING_EXT_FAST);
   618 					store.setValue(Constants.ATOOL_FOLDER, atoolFolder);
   608 		}
   619 					store.setValue(Constants.USER_SELECTED_FOLDER, atoolFolder);
   609 		store.setValue(Constants.DEVICE_LOG_FILE_PATH, logPathText.getText());
   620 					store.setValue(Constants.USE_INTERNAL, false);
   610 		store.setValue(Constants.DEVICE_LOG_FILE_NAME, fileNameText.getText());
   621 				} else {
   611 
   622 					return false;
   612 		// store value of verbose atool.exe output
   623 				}
   613 		store.setValue(Constants.ATOOL_VERBOSE, verboseButton.getSelection());
   624 			}
   614 
   625 
   615 		// update preference value
   626 			// store logging mode
   616 		// this values is used later when UI creates/update toolbar options and
   627 			if (askButton.getSelection()) {
   617 		// when building project with "ask always" option
   628 				store.setValue(Constants.LOGGING_MODE,
   618 		if (externalFastButton.isEnabled()) {
   629 						Constants.LOGGING_ASK_ALLWAYS);
   619 			store.setValue(Constants.LOGGING_FAST_ENABLED, true);
   630 			} else if (s60Button.getSelection()) {
   620 		} else {
   631 				store.setValue(Constants.LOGGING_MODE, Constants.LOGGING_S60);
   621 			store.setValue(Constants.LOGGING_FAST_ENABLED, false);
   632 			} else if( externalFastButton.getSelection() ) {
   622 		}
   633 				store.setValue(Constants.LOGGING_MODE, Constants.LOGGING_EXT_FAST);
   623 
   634 			} else {
   624 		// get callstack size
   635 				store.setValue(Constants.LOGGING_MODE, Constants.LOGGING_EXT);
   625 		int size = 0;
   636 			}
   626 		boolean userDefinedCSSize = false;
   637 
   627 		if (zeroButton.getSelection() && zeroButton.isEnabled()) {
   638 			// store log file option
   628 			userDefinedCSSize = true;
   639 			if (userButton.getSelection()) {
   629 		} else if (fortyButton.getSelection() && fortyButton.isEnabled()) {
   640 				store.setValue(Constants.S60_LOG_FILE_MODE,
   630 			size = 40;
   641 						Constants.LOGGING_S60_USER_SPECIFIED);
   631 			userDefinedCSSize = true;
   642 			} else {
   632 		} else if (hundredButton.getSelection() && hundredButton.isEnabled()) {
   643 				store.setValue(Constants.S60_LOG_FILE_MODE,
   633 			size = 100;
   644 						Constants.LOGGING_S60_PROCESS_NAME);
   634 			userDefinedCSSize = true;
   645 			}
   635 		} else if (customButton.getSelection() && customButton.isEnabled()) {
   646 
   636 			size = spinner.getSelection();
   647 			// store value of verbose atool.exe output
   637 			userDefinedCSSize = true;
   648 			store.setValue(Constants.ATOOL_VERBOSE, verboseButton.getSelection());
   638 		}
   649 
   639 
   650 			// update preference value
   640 		// store callstack size
   651 			// this values is used later when UI creates/update toolbar options and when building project with "ask always" option
   641 		store.setValue(Constants.USE_CALLSTACK_SIZE, userDefinedCSSize);
   652 			if( externalFastButton.isEnabled() ) {
   642 		store.setValue(Constants.CALLSTACK_SIZE, size);
   653 				store.setValue(Constants.LOGGING_FAST_ENABLED, true);
   643 
   654 			}
   644 		// update view with new settings
   655 			else {
   645 		IActionListener listener = Activator.getActionListener();
   656 				store.setValue(Constants.LOGGING_FAST_ENABLED, false);
   646 		if (listener != null) {
   657 			}
   647 			listener.preferenceChanged();
   658 			// store.setValue(Constants.CREATE_STATISTIC,
   648 		}
   659 			// generateStatistic.getSelection());
   649 
   660 
       
   661 			// get callstack size
       
   662 			int size = 0;
       
   663 			boolean userDefinedCSSize = false;
       
   664 			if (zeroButton.getSelection() && zeroButton.isEnabled()) {
       
   665 				userDefinedCSSize = true;
       
   666 			} else if (fortyButton.getSelection() && fortyButton.isEnabled()) {
       
   667 				size = 40;
       
   668 				userDefinedCSSize = true;
       
   669 			} else if (hundredButton.getSelection() && hundredButton.isEnabled()) {
       
   670 				size = 100;
       
   671 				userDefinedCSSize = true;
       
   672 			} else if (customButton.getSelection() && customButton.isEnabled()) {
       
   673 				size = spinner.getSelection();
       
   674 				userDefinedCSSize = true;
       
   675 			}
       
   676 
       
   677 			// store callstack size
       
   678 			store.setValue(Constants.USE_CALLSTACK_SIZE, userDefinedCSSize);
       
   679 			store.setValue(Constants.CALLSTACK_SIZE, size);
       
   680 			
       
   681 			// update view with new settings
       
   682 			IActionListener listener = Activator.getActionListener();
       
   683 			if (listener != null) {
       
   684 				listener.preferenceChanged();
       
   685 			}
       
   686 		//}
       
   687 		
       
   688 		// store report detail level prefs
   650 		// store report detail level prefs
   689 		return super.performOk();
   651 		return super.performOk();
   690 	}
   652 	}
   691 
   653 
   692 	/**
   654 	/**
   693 	 * Sets S60 file options visible.
   655 	 * Sets S60 file options visible.
   694 	 *
   656 	 * 
   695 	 * @param enabled
   657 	 * @param enabled
   696 	 *            Is buttons enabled.
   658 	 *            Is buttons enabled.
   697 	 */
   659 	 */
   698 	private void setFileModeEnabled(final boolean enabled) {
   660 	private void setFileModeEnabled(final boolean enabled) {
   699 		processButton.setEnabled(enabled);
   661 		logPath.setEnabled(enabled);
   700 		userButton.setEnabled(enabled);
   662 		logPathText.setEnabled(enabled);
       
   663 		fileName.setEnabled(enabled);
       
   664 		fileNameText.setEnabled(enabled);
   701 	}
   665 	}
   702 
   666 
   703 	/**
   667 	/**
   704 	 * Changes logging mode buttons.
   668 	 * Changes logging mode buttons.
   705 	 *
   669 	 * 
   706 	 * @param mode
   670 	 * @param mode
   707 	 *            Which mode is used
   671 	 *            Which mode is used
   708 	 */
   672 	 */
   709 	private void setGroupButtons(final String mode) {
   673 	private void setGroupButtons(final String mode) {
   710 		if (mode.equals(Constants.LOGGING_S60)) {
   674 		if (mode.equals(Constants.LOGGING_S60)) {
   711 			externalButton.setSelection(false);
       
   712 			externalFastButton.setSelection(false);
   675 			externalFastButton.setSelection(false);
   713 			s60Button.setSelection(true);
   676 			s60Button.setSelection(true);
   714 			askButton.setSelection(false);
   677 			askButton.setSelection(false);
   715 			setFileModeEnabled(true);
   678 			setFileModeEnabled(true);
   716 		} else if (mode.equals(Constants.LOGGING_ASK_ALLWAYS)) {
   679 		} else if (mode.equals(Constants.LOGGING_ASK_ALLWAYS)) {
   717 			externalButton.setSelection(false);
       
   718 			externalFastButton.setSelection(false);
   680 			externalFastButton.setSelection(false);
   719 			s60Button.setSelection(false);
   681 			s60Button.setSelection(false);
   720 			askButton.setSelection(true);
   682 			askButton.setSelection(true);
   721 			setFileModeEnabled(false);
   683 			setFileModeEnabled(false);
   722 		} else if( mode.equals(Constants.LOGGING_EXT_FAST)) {
   684 		} else if (mode.equals(Constants.LOGGING_EXT_FAST)) {
   723 			externalButton.setSelection(false);
       
   724 			externalFastButton.setSelection(true);
   685 			externalFastButton.setSelection(true);
   725 			s60Button.setSelection(false);
   686 			s60Button.setSelection(false);
   726 			askButton.setSelection(false);
   687 			askButton.setSelection(false);
   727 			setFileModeEnabled(false);
   688 			setFileModeEnabled(false);
   728 		} else {
   689 		}
   729 			externalButton.setSelection(true);
   690 		// else {
   730 			externalFastButton.setSelection(false);
   691 		// externalButton.setSelection(true);
   731 			s60Button.setSelection(false);
   692 		// externalFastButton.setSelection(false);
   732 			askButton.setSelection(false);
   693 		// s60Button.setSelection(false);
   733 			setFileModeEnabled(false);
   694 		// askButton.setSelection(false);
   734 		}
   695 		// setFileModeEnabled(false);
       
   696 		// }
   735 	}
   697 	}
   736 
   698 
   737 	/**
   699 	/**
   738 	 * Update atool.exe version number.
   700 	 * Update atool.exe version number.
   739 	 *
   701 	 * 
   740 	 * @param path
   702 	 * @param path
   741 	 *            Atool.exe location
   703 	 *            Atool.exe location
   742 	 */
   704 	 */
   743 	private void updateAtoolVersion(final String path) {
   705 	private void updateAtoolVersion(final String path) {
   744 		atoolVerLabel.setText(Util.getAtoolVersionNumber(path));
   706 		atoolVerLabel.setText(Util.getAtoolVersionNumber(path));
   745 		atoolVerLabel.update();
   707 		atoolVerLabel.update();
   746 		updateCSGroup(path);
   708 		checkState();
   747 	}
       
   748 
       
   749 	/**
       
   750 	 * Checks what version of command line is used, if the version is 1.7.4 or
       
   751 	 * higher enables callstack size selection otherwise disables callstack size
       
   752 	 * selection.
       
   753 	 *
       
   754 	 * @param path
       
   755 	 *            Command line engine path
       
   756 	 */
       
   757 	private void updateCSGroup(final String path) {
       
   758 		int compared = Constants.VERSION_NUMBERS_INVALID;
       
   759 
       
   760 		// compare version numbers
       
   761 		compared = Util.compareVersionNumber(Constants.CS_SUPPORT_MIN_VERSION,
       
   762 				Util.getAtoolVersionNumber(path));
       
   763 
       
   764 		// if used command line version is 1.7.4 or higher enable callstack size
       
   765 		// selection
       
   766 		if (compared == Constants.VERSION_NUMBERS_SECOND
       
   767 				|| compared == Constants.VERSION_NUMBERS_EQUALS) {
       
   768 			zeroButton.setEnabled(true);
       
   769 			fortyButton.setEnabled(true);
       
   770 			hundredButton.setEnabled(true);
       
   771 			customButton.setEnabled(true);
       
   772 			spinner.setEnabled(true);
       
   773 			csSizeGroup.setToolTipText("");
       
   774 			externalFastButton.setEnabled(true);
       
   775 			externalFastButton.setToolTipText("");
       
   776 		} else {
       
   777 			zeroButton.setEnabled(false);
       
   778 			fortyButton.setEnabled(false);
       
   779 			hundredButton.setEnabled(false);
       
   780 			customButton.setEnabled(false);
       
   781 			spinner.setEnabled(false);
       
   782 			csSizeGroup
       
   783 					.setToolTipText(Constants.PREFS_CS_SIZE_DISABLED_TOOLTIP);
       
   784 
       
   785 			if( externalFastButton.getSelection() ) {
       
   786 				externalButton.setSelection(true);
       
   787 			}
       
   788 			externalFastButton.setSelection(false);
       
   789 			externalFastButton.setEnabled(false);
       
   790 			externalFastButton.setToolTipText(Constants.PREFS_CS_SIZE_DISABLED_TOOLTIP);
       
   791 
       
   792 
       
   793 		}
       
   794 
       
   795 	}
   709 	}
   796 }
   710 }