/* * PDFedit - free program for PDF document manipulation. * Copyright (C) 2006, 2007 PDFedit team: Michal Hocko, * Miroslav Jahoda, * Jozef Misutka, * Martin Petricek * * Project is hosted on http://sourceforge.net/projects/pdfedit */ #ifndef __TREEITEMGENERICOBSERVER_H__ #define __TREEITEMGENERICOBSERVER_H__ #include "treeitemabstract.h" #include "util.h" #include #include #include #include namespace gui { //template class /* template struct ObserverItemTrait { // public: typedef observer::ObserverHandler::Observer ObserverType; public: typedef boost::shared_ptr NewValueType; public: typedef boost::shared_ptr::ObserverContext> ObserverContextType; }; */ /** This template class provides observer monitoring some item.
That item must have ObserverContext and Observer types defined within it The observer will reload associated tree item when the observed item changes. \brief Generic observer that will reload tree item on change */ template class TreeItemGenericObserver : public observer::IObserver { public: /** Constructor @param _parent Object to be reloaded on any change to monitored item */ TreeItemGenericObserver(TreeItemAbstract* _parent){ parent=_parent; }; /** Deactivate observer */ void deactivate() { parent=NULL; } /** Notification function called by changing property @param newValue New value of property @param context Context of change */ virtual void notify (__attribute__((unused)) boost::shared_ptr newValue, __attribute__((unused)) boost::shared_ptr > context) const throw() { if (!parent) { //Should never happen guiPrintDbg(debug::DBG_ERR,"BUG: Kernel is holding observer for item already destroyed"); assert(parent); return; } //Reload contents of parent parent->reload(); } /** Return priority of this observer @return priority value */ virtual observer::IObserver::priority_t getPriority() const throw(){ return 0;//TODO: what priority? } /** Destructor */ virtual ~TreeItemGenericObserver() throw() { //Empty for now } protected: /** Parent object holding observed property*/ TreeItemAbstract *parent; }; } // namespace gui #endif