srcanaapps/apiquerytool/com.nokia.s60tools.apiquery/src/com/nokia/s60tools/apiquery/settings/UserSettings.java
changeset 0 a02c979e8dfd
equal deleted inserted replaced
-1:000000000000 0:a02c979e8dfd
       
     1 /*
       
     2 * Copyright (c) 2006 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 package com.nokia.s60tools.apiquery.settings;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 
       
    23 import com.nokia.s60tools.apiquery.shared.searchmethod.ISearchMethodExtension;
       
    24 import com.nokia.s60tools.apiquery.shared.searchmethod.ISearchMethodExtensionInfo;
       
    25 import com.nokia.s60tools.apiquery.shared.searchmethodregistry.SearchMethodExtensionRegistry;
       
    26 import com.nokia.s60tools.util.debug.DbgUtility;
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 /**
       
    32  * Singleton class that is created on plugin
       
    33  * startup, and is kept active as long as plugin is active.
       
    34  * 
       
    35  * The purpose of this class is store run-time instance
       
    36  * of active user settings.
       
    37  */
       
    38 public class UserSettings {
       
    39 
       
    40 	/**
       
    41 	 * Singleton instance.
       
    42 	 */
       
    43 	static private UserSettings instance = null;
       
    44 
       
    45 	/**
       
    46 	 * Currently selected search method.
       
    47 	 */
       
    48 	private ISearchMethodExtensionInfo currentlySelectedSearchMethodInfo = null;
       
    49 	
       
    50 	/**
       
    51 	 * Listeners that can be attached for listening the changes in the user settings.
       
    52 	 */
       
    53 	private ArrayList<IUserSettingsListener> settingsListeners = new ArrayList<IUserSettingsListener>();
       
    54 	
       
    55 	/**
       
    56 	 * Public Singleton instance accessor.
       
    57 	 * @return Returns instance of this singleton class-
       
    58 	 */
       
    59 	public static UserSettings getInstance(){
       
    60 		if( instance == null ){
       
    61 			instance = new UserSettings();
       
    62 		}
       
    63 		return instance;		
       
    64 	}	
       
    65 	
       
    66 	/**
       
    67 	 * Private default constructor.
       
    68 	 */
       
    69 	private UserSettings() {
       
    70 		DbgUtility.println(DbgUtility.PRIORITY_CLASS, "-- <<create>> --> " + getClass().getName()); //$NON-NLS-1$
       
    71 	}
       
    72 
       
    73 	/**
       
    74 	 * Gets the search method that is currently selected by user.
       
    75 	 * @return Returns the currentlySelectedSearchMethodInfo, or
       
    76 	 *         <code>null</code> if not set.
       
    77 	 */
       
    78 	public ISearchMethodExtensionInfo getCurrentlySelectedSearchMethodInfo() {
       
    79 		return currentlySelectedSearchMethodInfo;
       
    80 	}
       
    81 
       
    82 	/**
       
    83 	 * Gets the currently selected search method.
       
    84 	 * @return The currently selected search method.
       
    85 	 */
       
    86 	public ISearchMethodExtension getCurrentlySelectedSearchMethod() {
       
    87 		ISearchMethodExtensionInfo currSelExtInfo =  getInstance().getCurrentlySelectedSearchMethodInfo();
       
    88 		String id = currSelExtInfo.getId();
       
    89 		ISearchMethodExtension currSelExt = SearchMethodExtensionRegistry.getInstance().getById(id);
       
    90 		return currSelExt;
       
    91 	}	
       
    92 	
       
    93 	/**
       
    94 	 * Sets the search method that is currently selected by user.
       
    95 	 * @param currentlySelectedSearchMethodInfo The currentlySelectedSearchMethodInfo to set.
       
    96 	 */
       
    97 	public void setCurrentlySelectedSearchMethodInfo(
       
    98 			ISearchMethodExtensionInfo currentlySelectedSearchMethodInfo) {
       
    99 		this.currentlySelectedSearchMethodInfo = currentlySelectedSearchMethodInfo;
       
   100 		settingsChanged();
       
   101 	}
       
   102 	
       
   103 	/**
       
   104 	 * Adds a user settings listener.
       
   105 	 * @param listener Setting listener to add.
       
   106 	 */
       
   107 	public void addUserSettingListener(IUserSettingsListener listener){
       
   108 		settingsListeners.add(listener);
       
   109 	}
       
   110 	
       
   111 	/**
       
   112 	 * Removes a user settings listener.
       
   113 	 * @param listener Setting listener to remove.
       
   114 	 */
       
   115 	public void removeUserSettingListener(IUserSettingsListener listener){
       
   116 		settingsListeners.remove(listener);
       
   117 	}
       
   118 	
       
   119 	/**
       
   120 	 * Notifies listeners that the settings has been changed.
       
   121 	 */
       
   122 	public void settingsChanged(){
       
   123 		for (IUserSettingsListener listener : settingsListeners) {
       
   124 			listener.userSettingsChanged();
       
   125 		}
       
   126 	}
       
   127 }