mulwidgets/muldatamodel/inc/mulpushmode.h
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Implementation of model interface base
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MULPUSHMODE_H
       
    20 #define MULPUSHMODE_H
       
    21 
       
    22 //Includes
       
    23 #include <osn/ustring.h>
       
    24 
       
    25 #include <mul/muldatapath.h>
       
    26 
       
    27 #include "mul/imulwidget.h"
       
    28 
       
    29 
       
    30 namespace Alf
       
    31     {
       
    32 
       
    33 //Forward Declaration
       
    34 
       
    35 class MulVisualItem;
       
    36 class MulCacheManager;
       
    37 class MulPageDataWindow;
       
    38 class MulAlfModelImpl;
       
    39 	
       
    40 
       
    41 /**
       
    42  *  Base implementation class for pull/push model.
       
    43  *  @lib 
       
    44  */
       
    45 class MulPushMode
       
    46     {
       
    47     
       
    48 public: 
       
    49 
       
    50 	/**
       
    51 	 * C++ constructor.
       
    52 	 * 
       
    53 	 * @param aDataWindow DataWindow for model
       
    54 	 */
       
    55     MulPushMode( MulPageDataWindow& aDataWindow );
       
    56 	
       
    57 	/**
       
    58 	 * Destructor
       
    59 	 */
       
    60 	virtual ~MulPushMode();
       
    61    	
       
    62 	/**
       
    63 	 * Informs the data model that new items have been added to client's
       
    64 	 * internal model. Data model is expected to sync its indices as a 
       
    65 	 * result.
       
    66 	 * 
       
    67 	 * @param aIndex Position where items were inserted.
       
    68 	 * @param aCount Number of items inserted.
       
    69      * @return true if highlight is modified else false.	 
       
    70 	 */ 
       
    71 	bool Insert( int aIndex, int aCount, 
       
    72                          const MulDataPath& aPath = MulDataPath() );
       
    73 	
       
    74     /**
       
    75      * Informs the data model that items have been removed from the client's.
       
    76      * internal data model.Data model is expected to sync its indices as a 
       
    77      * result.
       
    78      * 
       
    79      * @param aIndex Position from where items have to be removed.
       
    80      * @param aCount Number of items to be removed.
       
    81      * @return true if highlight is modified else false.
       
    82      */ 
       
    83     bool Remove( int aIndex, int aCount, 
       
    84                          const MulDataPath& aPath = MulDataPath() );
       
    85 	
       
    86     /**
       
    87      * Informs the data model that an item has been updated in the client's
       
    88      * internal model. Data model will use to input to determine whether
       
    89      * a visualization change is required.
       
    90      * 
       
    91      * @param aIndex Position from where items have to be updated.
       
    92      * @param aCount Number of items to be updated.
       
    93      */ 
       
    94 	virtual void Update( int aIndex, int aCount, 
       
    95                          const MulDataPath& aPath = MulDataPath() );
       
    96 
       
    97  
       
    98     /**
       
    99       * A refresh data request. Informs that the data model has to be 
       
   100       * repopulated with mentioned number of items. So the data model
       
   101       * will remove all the existing data and issue request to the 
       
   102       * provider for new data.
       
   103       * 
       
   104       * @param aCount Number of items to be repopulated.
       
   105       * @param aPath  Path of parent item in the data hierarchy. 
       
   106       *               Default is Null path i.e. no parent.
       
   107       */ 						 
       
   108 	virtual void Refresh( int aCount, const MulDataPath& aPath = MulDataPath());						 
       
   109 	
       
   110 	/**
       
   111      * Provide data for the specified item. This is a unified API for 
       
   112      * adding & updating data. 
       
   113      *
       
   114      * @param aIndex Position of item to be updated.
       
   115      * @param aVisualItem Collection of attributes. Ownership is transfered.
       
   116      * @throw Invalid Argument, in case index is out of bound or visual 
       
   117      *                         item is NULL.
       
   118      * @throw Logic Error, in case item could not be updated.
       
   119      */ 
       
   120 	virtual void SetData( int aIndex, 
       
   121 						  std::auto_ptr<MulVisualItem> aVisualItem, 
       
   122                           const MulDataPath& aPath);
       
   123 	
       
   124 	 /**
       
   125 	  * Get the data for item at the specified index.
       
   126 	  *
       
   127 	  * @param aIndex Position of item in the data model.
       
   128 	  * @return A constant reference to the data at the given index.
       
   129 	  */ 
       
   130 	const MulVisualItem* Data( int aIndex, const MulDataPath& aPath ) const;
       
   131 
       
   132 	 /**
       
   133 	  * Get the count of items in the model.
       
   134 	  *
       
   135 	  * @return Count of items in the model.
       
   136 	  */ 
       
   137 	int Count(const MulDataPath& aPath ) const; 
       
   138 
       
   139 	/**
       
   140      * Set the default logical template id for widget elements. 
       
   141      * Logical templates map to visualization of the element(s).
       
   142      * 
       
   143      * @param aTemplateId Logical template id for the widget elements.
       
   144      */ 
       
   145 	virtual void SetTemplate( mulwidget::TLogicalTemplate aTemplateId ) ;
       
   146 	
       
   147     /**
       
   148      * Returns the default template. 
       
   149      * 
       
   150      * @return Logical template id for the widget elements.
       
   151      */ 
       
   152 	mulwidget::TLogicalTemplate Template( ) ;
       
   153 
       
   154 	/**
       
   155      * Set the logical template id for a specific widget element. 
       
   156      * Logical templates map to visualization of the element.
       
   157      * 
       
   158      * @param aItemIndex Unique id of item of which template needs to be applied.
       
   159      * @param aTemplateId Logical template id for the widget element.
       
   160      * @throw Invalid Argument, in case index is out of bound.
       
   161      */ 
       
   162 	void SetTemplate( int aItemIndex, mulwidget::TLogicalTemplate aTemplateId, 
       
   163 	                    	  const MulDataPath& aPath );
       
   164 	 
       
   165 	/**
       
   166      * Returns the total number of items in model.
       
   167      */ 
       
   168 	int CurrentItemCount() const;	                    	
       
   169 	    
       
   170 	/**
       
   171 	 * When ever data window update data window, it will use this method to notify
       
   172 	 * Data model to update data window and update alf model
       
   173 	 */
       
   174 	virtual void DataWindowUpdated(){ };
       
   175 		
       
   176 	/**
       
   177 	 * Return cachemanager 
       
   178 	 * 
       
   179 	 * @return cachae manager
       
   180 	 */
       
   181 	MulCacheManager& CacheManager() const;
       
   182 	
       
   183 	/**
       
   184 	 * Get Visualte item from absolute index
       
   185 	 * 
       
   186 	 * @param aAbsoluteIndex Absolute index
       
   187 	 * @return VisualItem at index
       
   188 	 */
       
   189 	virtual const MulVisualItem& Item( int aAbsoluteIndex );
       
   190 	
       
   191 	/**
       
   192 	 * Check that visual item has Templatte or not
       
   193 	 * If visualte item is not poper exception will be throws
       
   194 	 * 
       
   195 	 * @param aVisualItem Visual item to be tested
       
   196 	 */
       
   197 	void ValidateVisualItem( MulVisualItem& aVisualItem );
       
   198 	
       
   199 	/**
       
   200 	 * Modify the data alfmodel to handle remove, insert, or expand/colapse operation
       
   201 	 * 
       
   202 	 * @param, aOldCount Total number of items in Alf model before the current operation
       
   203 	 */	
       
   204 	virtual void ModelCountChanged(int aOldCount, int aNewCount);		
       
   205 		
       
   206 private:
       
   207 	
       
   208 	/**
       
   209 	 * If current highlight is greater than the number of items in model then update the highlight.
       
   210 	 *
       
   211 	 * @return Ture if highlight value is modified else false
       
   212 	 */		
       
   213 	bool ValidateCurrentHighlight();
       
   214 		
       
   215 protected: // data members	
       
   216 	
       
   217 	std::auto_ptr<MulCacheManager>	mCacheManager; //own
       
   218 	MulPageDataWindow& mDataWindow;	// Not own
       
   219 	//UString	 mDefaultTemplate; //default template for data	
       
   220 	mulwidget::TLogicalTemplate mDefaultTemplate;
       
   221 
       
   222     };
       
   223     
       
   224     } // namespace Alf
       
   225 
       
   226 #endif // MULPUSHMODE_H
       
   227     
       
   228 //End of file
       
   229