1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
42 warn('use DefaultFieldFactory', DeprecationWarning)
43
44
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