00001 ############################################################################## 00002 # 00003 # Copyright (c) 2008 Albert Cervera i Areny <albert@nan-tic.com> 00004 # 00005 # WARNING: This program as such is intended to be used by professional 00006 # programmers who take the whole responsability of assessing all potential 00007 # consequences resulting from its eventual inadequacies and bugs 00008 # End users who are looking for a ready-to-use solution with commercial 00009 # garantees and support are strongly adviced to contract a Free Software 00010 # Service Company 00011 # 00012 # This program is Free Software; you can redistribute it and/or 00013 # modify it under the terms of the GNU General Public License 00014 # as published by the Free Software Foundation; either version 2 00015 # of the License, or (at your option) any later version. 00016 # 00017 # This program is distributed in the hope that it will be useful, 00018 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 # GNU General Public License for more details. 00021 # 00022 # You should have received a copy of the GNU General Public License 00023 # along with this program; if not, write to the Free Software 00024 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00025 # 00026 ############################################################################## 00027 00028 from AbstractFieldDelegate import * 00029 from Koo.Common import Plugins 00030 import os 00031 00032 ## @brief The FieldDelegateFactory class specializes in creating the appropiate 00033 # delegates for a given type. 00034 00035 class FieldDelegateFactory: 00036 delegates = {} 00037 00038 ## @brief Scans for all available delegates. 00039 @staticmethod 00040 def scan(): 00041 # Scan only once 00042 if FieldDelegateFactory.delegates: 00043 return 00044 # Search for all available views 00045 Plugins.scan( 'Koo.Fields', os.path.abspath(os.path.dirname(__file__)) ) 00046 00047 ## @brief Creates a new delegate given type, parent and attributes. 00048 @staticmethod 00049 def create(delegateType, parent, attributes): 00050 FieldDelegateFactory.scan() 00051 if not delegateType in FieldDelegateFactory.delegates: 00052 return AbstractFieldDelegate( parent, attributes ) 00053 00054 delegateClass = FieldDelegateFactory.delegates[delegateType] 00055 return delegateClass(parent, attributes) 00056 00057 ## @brief Registers a new delegate, given it's name (or type) and reference 00058 # to the class. 00059 @staticmethod 00060 def register( name, delegate ): 00061 FieldDelegateFactory.delegates[ name ] = delegate 00062