srcanaapps/depexplorer/com.nokia.s60tools.appdep/src/com/nokia/s60tools/appdep/ui/views/main/MainViewPopulateProgressListener.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.appdep.ui.views.main;
       
    20 
       
    21 import org.eclipse.swt.widgets.Display;
       
    22 
       
    23 import com.nokia.s60tools.appdep.core.data.ComponentNode;
       
    24 import com.nokia.s60tools.appdep.core.data.IComponentSearchProgressListener;
       
    25 import com.nokia.s60tools.appdep.resources.Messages;
       
    26 
       
    27 /**
       
    28  * Main view population progress listener
       
    29  */
       
    30 public class MainViewPopulateProgressListener implements IComponentSearchProgressListener {
       
    31 
       
    32 	/**
       
    33 	 * Determines the UI refresh cycle. The refresh is done after
       
    34 	 * UI_REFRESH_CYCLE amount of components has been added.
       
    35 	 */
       
    36 	private static final int UI_REFRESH_CYCLE = 20;
       
    37 	
       
    38 	/**
       
    39 	 * Determines how often component count information
       
    40 	 * on toolbar is updated.
       
    41 	 */
       
    42 	private static final int COMPONENT_COUNT_REFRESH_CYCLE = 5;
       
    43 	
       
    44 	/**
       
    45 	 * View into which report progress into.
       
    46 	 */
       
    47 	MainView view = null;
       
    48 	
       
    49 	/**
       
    50 	 * Default constructor
       
    51 	 * @param view View into which report progress into.
       
    52 	 */
       
    53 	public MainViewPopulateProgressListener(MainView view){
       
    54 		this.view = view;
       
    55 	}
       
    56 	
       
    57 	/* (non-Javadoc)
       
    58 	 * @see com.nokia.s60tools.appdep.core.data.IComponentSearchProgressListener#searchStarted()
       
    59 	 */
       
    60 	public void searchStarted() {
       
    61 		view.searchStarted();
       
    62 		String descriptionText = Messages.getString("MainViewPopulateProgressListener.Searching_Msg"); //$NON-NLS-1$
       
    63 		view.updateDescription(descriptionText);
       
    64 	}
       
    65 
       
    66 	/* (non-Javadoc)
       
    67 	 * @see com.nokia.s60tools.appdep.core.data.IComponentSearchProgressListener#componentAdded(com.nokia.s60tools.appdep.core.data.ComponentNode, int)
       
    68 	 */
       
    69 	public void componentAdded(ComponentNode node, int componentTotalCount) {
       
    70 		final String descriptionText = Messages.getString("MainViewPopulateProgressListener.Searching_Msg_Start")  //$NON-NLS-1$
       
    71 			                     + componentTotalCount + Messages.getString("MainViewPopulateProgressListener.Searching_Msg_End"); //$NON-NLS-1$
       
    72 		
       
    73 		final int total = componentTotalCount;
       
    74 		
       
    75 		Runnable updateRunnable = new Runnable(){
       
    76 			public void run(){
       
    77 				if((total % COMPONENT_COUNT_REFRESH_CYCLE) == 0){
       
    78 					view.updateDescription(descriptionText);	
       
    79 				}
       
    80 				if((total % UI_REFRESH_CYCLE) == 0){
       
    81 					view.refresh();
       
    82 				}
       
    83 			}
       
    84 		};
       
    85 		
       
    86 		// Update request done in its own thread
       
    87 		// in order not to cause invalid thread access
       
    88 		Display.getDefault().asyncExec(updateRunnable);		
       
    89 	}
       
    90 
       
    91 	/* (non-Javadoc)
       
    92 	 * @see com.nokia.s60tools.appdep.core.data.IComponentSearchProgressListener#searchFinished(int)
       
    93 	 */
       
    94 	public void searchFinished(int componentTotalCount) {
       
    95 		final String descriptionText = Messages.getString("MainViewPopulateProgressListener.Search_Complete_Msg_Start")  //$NON-NLS-1$
       
    96 			                     + componentTotalCount + Messages.getString("MainViewPopulateProgressListener.Search_Complete_Msg_End"); //$NON-NLS-1$
       
    97 				
       
    98 		Runnable updateRunnable = new Runnable(){
       
    99 			public void run(){
       
   100 				view.updateDescription(descriptionText);	
       
   101 				view.searchCompleted();
       
   102 				view.refresh();
       
   103 			}
       
   104 		};
       
   105 		
       
   106 		// Update request done in its own thread
       
   107 		// in order not to cause invalid thread access
       
   108 		Display.getDefault().asyncExec(updateRunnable);		
       
   109 
       
   110 	}
       
   111 
       
   112 	/* (non-Javadoc)
       
   113 	 * @see com.nokia.s60tools.appdep.core.data.IComponentSearchProgressListener#searchAborted(int)
       
   114 	 */
       
   115 	public void searchAborted(int componentTotalCount) {
       
   116 		final String descriptionText = Messages.getString("MainViewPopulateProgressListener.Search_Aborted_Msg_Start")  //$NON-NLS-1$
       
   117 			                     + componentTotalCount + Messages.getString("MainViewPopulateProgressListener.Search_Aborted_Msg_End"); //$NON-NLS-1$
       
   118 				
       
   119 		Runnable updateRunnable = new Runnable(){
       
   120 			public void run(){
       
   121 				view.updateDescription(descriptionText);	
       
   122 				view.searchCompleted();
       
   123 				view.refresh();
       
   124 			}
       
   125 		};
       
   126 		
       
   127 		// Update request done in its own thread
       
   128 		// in order not to cause invalid thread access
       
   129 		Display.getDefault().asyncExec(updateRunnable);		
       
   130 		
       
   131 	}
       
   132 
       
   133 }