themeinstaller/source/src/com/nokia/tools/themeinstaller/installationmanager/InstallationList.java
branchRCL_3
changeset 17 fe49e33862e2
parent 16 b685c59de105
child 18 04b7640f6fb5
equal deleted inserted replaced
16:b685c59de105 17:fe49e33862e2
     1 /*
       
     2 * Copyright (c) 2007 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:  Installation list for monitoring language variants under install.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.tools.themeinstaller.installationmanager;
       
    20 
       
    21 import java.util.Vector;
       
    22 
       
    23 /**
       
    24  * Installation list for monitoring language variants under install.
       
    25  */
       
    26 public class InstallationList
       
    27     {
       
    28 
       
    29     // CONSTANTS
       
    30     private static final int NOT_FOUND = -1;
       
    31     private static final String EXT_PREFIX = ".o";
       
    32 
       
    33     // Languages under install
       
    34     private Vector iLanguages;
       
    35 
       
    36     /**
       
    37      * Constructor.
       
    38      */
       
    39     public InstallationList()
       
    40         {
       
    41         iLanguages = new Vector();
       
    42         }
       
    43 
       
    44     /**
       
    45      * Add a language under install.
       
    46      * @param aLanguage language id
       
    47      */
       
    48     public void addInstall( Integer aLanguage )
       
    49         {
       
    50         iLanguages.add( aLanguage );
       
    51         }
       
    52 
       
    53     /**
       
    54      * Remove a language from list when the installation has completed.
       
    55      * @param aODTFileName path and file name of the installed ODT.
       
    56      * @return true if a language was removed from the list
       
    57      */
       
    58     public boolean removeInstall( String aODTFileName )
       
    59         {
       
    60         // No localized as default
       
    61         int languageId = NOT_FOUND;
       
    62         int extIndex = NOT_FOUND;
       
    63         if( aODTFileName != null )
       
    64             {
       
    65             extIndex = aODTFileName.lastIndexOf( EXT_PREFIX );
       
    66             }
       
    67         if( extIndex >= 0 )
       
    68             {
       
    69             String language = aODTFileName.substring( extIndex + EXT_PREFIX.length() );
       
    70             if( language != null &&
       
    71                !language.equals( "" ) )
       
    72                 {
       
    73                 languageId = Integer.valueOf( language ).intValue();
       
    74                 }
       
    75             }
       
    76 
       
    77         return removeInstall( languageId );
       
    78         }
       
    79 
       
    80     /**
       
    81      * Remove a language from list when the installation has completed.
       
    82      * @param aLanguage language id
       
    83      * @return true if a language was removed from the list
       
    84      */
       
    85     public boolean removeInstall( int aLanguage )
       
    86         {
       
    87         boolean result = false;
       
    88         int index = findLanguage( aLanguage );
       
    89         if( index >= 0 )
       
    90             {
       
    91             iLanguages.remove( index );
       
    92             result = true;
       
    93             }
       
    94 
       
    95         return result;
       
    96         }
       
    97 
       
    98     /**
       
    99      * Check if there are ongoing installations in the list.
       
   100      * @return true if there are installtions in the list
       
   101      */
       
   102     public boolean installsExist()
       
   103         {
       
   104         if( iLanguages.size() > 0 )
       
   105             {
       
   106             return true;
       
   107             }
       
   108         return false;
       
   109         }
       
   110 
       
   111     /**
       
   112      * Find a language from the list.
       
   113      * @param aLanguage language id
       
   114      * @return index of the language in the list
       
   115      */
       
   116     private int findLanguage( int aLanguage )
       
   117         {
       
   118         int count = iLanguages.size();
       
   119         for( int i = 0; i < count; i++ )
       
   120             {
       
   121             Integer integer = ( Integer ) iLanguages.elementAt( i );
       
   122             if( integer.intValue() == aLanguage )
       
   123                 {
       
   124                 return i;
       
   125                 }
       
   126             }
       
   127 
       
   128         return NOT_FOUND;
       
   129         }
       
   130 
       
   131     }