trace/traceanalyser/com.nokia.s60tools.traceanalyser/src/com/nokia/s60tools/traceanalyser/model/UserEnteredData.java
changeset 9 14dc2103a631
equal deleted inserted replaced
8:15296fd0af4a 9:14dc2103a631
       
     1 /*
       
     2 * Copyright (c) 2009 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 */
       
    17 
       
    18 
       
    19 
       
    20 package com.nokia.s60tools.traceanalyser.model;
       
    21 
       
    22 import org.eclipse.jface.dialogs.IDialogSettings;
       
    23 
       
    24 import com.nokia.s60tools.traceanalyser.plugin.TraceAnalyserPlugin;
       
    25 
       
    26 /**
       
    27  * This class is used to save and restore data which is entered by user in 
       
    28  * wizard pages.
       
    29  *
       
    30  */
       
    31 public class UserEnteredData {
       
    32 
       
    33 	// section names 
       
    34 	public static final String SECTION_SELECT_TRACE = "TraceSelectionDialog";
       
    35 	public static final String PREVIOUS_DICTIONARY = "PreviousDictionary";
       
    36 	public static final String PREVIOUS_GROUP = "PreviousGroup";
       
    37 	
       
    38 	public static enum ValueTypes {	PREVIOUS_GROUP,
       
    39 									PREVIOUS_DICTIONARY } 
       
    40 
       
    41 	
       
    42 	
       
    43 	/**
       
    44 	 * getString
       
    45 	 * gets string value from correct section
       
    46 	 * @param valueType type of string
       
    47 	 * @return String value
       
    48 	 */
       
    49 	
       
    50 	public String getString( ValueTypes valueType) {
       
    51 		try {
       
    52 			String retval = "";
       
    53 			
       
    54 			// get value from correct section
       
    55 			switch(valueType){
       
    56 				case PREVIOUS_DICTIONARY:{
       
    57 					IDialogSettings section = getSection(SECTION_SELECT_TRACE);
       
    58 					if (section != null) {
       
    59 						retval = section.get(PREVIOUS_DICTIONARY);
       
    60 						
       
    61 					}
       
    62 					break;
       
    63 			
       
    64 				}
       
    65 				case PREVIOUS_GROUP:{
       
    66 					IDialogSettings section = getSection(SECTION_SELECT_TRACE);
       
    67 					if (section != null) {
       
    68 						retval = section.get(PREVIOUS_GROUP);
       
    69 					}	
       
    70 					break;
       
    71 				}
       
    72 				
       
    73 				
       
    74 				default:{
       
    75 					break;
       
    76 				}
       
    77 			}	
       
    78 			return retval;
       
    79 		} catch (Exception e) {
       
    80 			return "";
       
    81 		}
       
    82 	}
       
    83 	
       
    84 	/**
       
    85 	 * saveString
       
    86 	 * saves string value into correct section. 
       
    87 	 * @param valueType type of string
       
    88 	 * @param value value that is saved
       
    89 	 */
       
    90 	
       
    91 	public void saveString(ValueTypes valueType, String value) {
       
    92 		try {
       
    93 
       
    94 			// save value into correct section
       
    95 
       
    96 			switch(valueType){
       
    97 				case PREVIOUS_DICTIONARY:{
       
    98 					IDialogSettings section = getSection(SECTION_SELECT_TRACE);
       
    99 					if (section != null) {
       
   100 						section.put(PREVIOUS_DICTIONARY, value);
       
   101 					}
       
   102 					break;
       
   103 				}
       
   104 				case PREVIOUS_GROUP:{
       
   105 					IDialogSettings section = getSection(SECTION_SELECT_TRACE);
       
   106 					if (section != null) {
       
   107 						section.put(PREVIOUS_GROUP, value);
       
   108 					}
       
   109 					break;
       
   110 				}
       
   111 
       
   112 				default:{
       
   113 					break;
       
   114 				}
       
   115 			}	
       
   116 			
       
   117 			
       
   118 		} catch (Exception E) {
       
   119 			// No actions needed
       
   120 		}
       
   121 	}
       
   122 	
       
   123 	
       
   124 	/**
       
   125 	 * Returns wanted section
       
   126 	 * @param section name of the wanted section
       
   127 	 * @return wanted section
       
   128 	 */
       
   129 	protected IDialogSettings getSection(String section) {
       
   130 		IDialogSettings retVal = null;
       
   131 		if (TraceAnalyserPlugin.getDefault().getDialogSettings() != null) {
       
   132 			retVal = TraceAnalyserPlugin.getDefault().getDialogSettings().getSection(section);
       
   133 			if (retVal == null) {
       
   134 				retVal = TraceAnalyserPlugin.getDefault().getDialogSettings().addNewSection(section);
       
   135 			}
       
   136 		}
       
   137 		return retVal;
       
   138 	}	
       
   139 }