srcanaapps/depexplorer/com.nokia.s60tools.appdep/src/com/nokia/s60tools/appdep/ui/utils/UiUtils.java
changeset 0 a02c979e8dfd
equal deleted inserted replaced
-1:000000000000 0:a02c979e8dfd
       
     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 package com.nokia.s60tools.appdep.ui.utils;
       
    20 
       
    21 import org.eclipse.swt.widgets.Shell;
       
    22 
       
    23 import com.nokia.s60tools.appdep.core.AppDepSettings;
       
    24 import com.nokia.s60tools.appdep.core.ITargetPlatform;
       
    25 import com.nokia.s60tools.appdep.ui.dialogs.SearchConfirmNewRootSelectionDialog;
       
    26 import com.nokia.s60tools.appdep.ui.preferences.DEPreferences;
       
    27 import com.nokia.s60tools.appdep.ui.views.main.MainView;
       
    28 
       
    29 /**
       
    30  * Contains static service methods that are needed by multiple
       
    31  * UI related classes in order to prevent duplication of similar 
       
    32  * functionality in multiple places.
       
    33  */
       
    34 public class UiUtils {
       
    35 
       
    36 	/**
       
    37 	 * Opens ask dialog if needed and asks confirmation about if new root is to be set or not.
       
    38 	 * If in preferences there is selection, "dont ask again" dialog want be opened but <code>true</code> is returned.
       
    39 	 * @param newRootComponentName
       
    40 	 * @return <code>true</code> if new root is to be set, <code>false</code> otherwise.
       
    41 	 */
       
    42 	private static boolean handleSetAsNewRootComponentConfirmation(Shell sh, String newRootComponentName) {
       
    43 		
       
    44 		//checking if preferences has already value dontAskAgain
       
    45 		if(DEPreferences.getDontAskSetAsNewRootFromSearch()){
       
    46 			return true;
       
    47 		}
       
    48 		else {							
       
    49 			SearchConfirmNewRootSelectionDialog dialog = new SearchConfirmNewRootSelectionDialog(sh, newRootComponentName);
       
    50 			int doOpen = dialog.open();
       
    51 			boolean setAsNewRoot = (doOpen == SearchConfirmNewRootSelectionDialog.OK) ? true : false;
       
    52 			
       
    53 			//if canceled, preferences wont be changed.
       
    54 			if(setAsNewRoot){
       
    55 				boolean dontAskAgain = dialog.isDontAskAgainChecked();
       
    56 				//setting to preferences
       
    57 				DEPreferences.setDontAskAtainAsNewRootFromSearch(dontAskAgain);
       
    58 			}
       
    59 	
       
    60 			return setAsNewRoot;
       
    61 		}
       
    62 	}
       
    63 
       
    64 	/**
       
    65 	 * Sets given component as new root component (and optionally triggers
       
    66 	 * confirmation query). 
       
    67 	 * @param view Reference to main view.
       
    68 	 * @param selectedComponentName Component to be set as new root component.
       
    69 	 * @param targetPlatform Target platform for the component, or <code>null</code> if not known.
       
    70 	 */
       
    71 	public static void setComponentAsNewRootInMainView(MainView view, String selectedComponentName, ITargetPlatform targetPlatform) {
       
    72 		Shell sh = view.getViewSite().getShell();
       
    73 		if( handleSetAsNewRootComponentConfirmation(sh, selectedComponentName)){		
       
    74 			AppDepSettings st = AppDepSettings.getActiveSettings();
       
    75 			st.setCurrentlyAnalyzedComponentName(selectedComponentName);
       
    76 			st.setCurrentlyAnalyzedComponentTargetPlatform(targetPlatform);
       
    77 			view.inputUpdated();   		
       
    78 		}
       
    79 	}
       
    80 
       
    81 	
       
    82 	
       
    83 }