Package muntjac :: Package ui :: Module base_field_factory
[hide private]
[frames] | no frames]

Source Code for Module muntjac.ui.base_field_factory

 1  # Copyright (C) 2012 Vaadin Ltd.  
 2  # Copyright (C) 2012 Richard Lincoln 
 3  #  
 4  # Licensed under the Apache License, Version 2.0 (the "License");  
 5  # you may not use this file except in compliance with the License.  
 6  # You may obtain a copy of the License at  
 7  #  
 8  #     http://www.apache.org/licenses/LICENSE-2.0  
 9  #  
10  # Unless required by applicable law or agreed to in writing, software  
11  # distributed under the License is distributed on an "AS IS" BASIS,  
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13  # See the License for the specific language governing permissions and  
14  # limitations under the License. 
15   
16  from warnings import warn 
17   
18  from muntjac.ui.default_field_factory import DefaultFieldFactory 
19  from muntjac.ui.field_factory import IFieldFactory 
20  from muntjac.data.property import IProperty 
21  from muntjac.ui.abstract_component import AbstractComponent 
22   
23   
24 -class BaseFieldFactory(IFieldFactory):
25 """Default implementation of the the following Field types are used 26 by default: 27 28 - B{Boolean}: Button(switchMode:true). 29 - B{Date}: DateField(resolution: day). 30 - B{Item}: Form. 31 - B{default field type}: TextField. 32 33 @author: Vaadin Ltd. 34 @author: Richard Lincoln 35 @version: 1.1.2 36 @deprecated: use L{DefaultFieldFactory} or own implementations 37 on L{FormFieldFactory} or L{TableFieldFactory} 38 instead. 39 """ 40
41 - def __init__(self):
42 warn('use DefaultFieldFactory', DeprecationWarning)
43 44
45 - def createField(self, *args):
46 """Creates the field based on type of data. 47 48 @param args: tuple of the form 49 - (type, uiContext) 50 1. the type of data presented in field. 51 2. the context where the Field is presented. 52 @see: L{IFieldFactory.createField} 53 """ 54 nargs = len(args) 55 if nargs == 2: 56 if isinstance(args[0], IProperty): 57 prop, uiContext = args 58 if property is not None: 59 return self.createField(prop.getType(), uiContext) 60 else: 61 return None 62 else: 63 typ, uiContext = args 64 return DefaultFieldFactory.createFieldByPropertyType(typ) 65 elif nargs == 3: 66 item, propertyId, uiContext = args 67 if item is not None and propertyId is not None: 68 f = self.createField(item.getItemProperty(propertyId), 69 uiContext) 70 if isinstance(f, AbstractComponent): 71 name = DefaultFieldFactory.createCaptionByPropertyId( 72 propertyId) 73 f.setCaption(name) 74 return f 75 else: 76 return None 77 elif nargs == 4: 78 container, itemId, propertyId, uiContext = args 79 prop = container.getContainerProperty(itemId, propertyId) 80 return self.createField(prop, uiContext) 81 else: 82 raise ValueError, 'invalid number of arguments'
83