def __init__(self): super(ComboBoxStartsWithExample, self).__init__() self.setSpacing(True) # Creates a new combobox using an existing container l = ComboBox('Please select your country', ExampleUtil.getISO3166Container()) # Sets the combobox to show a certain property as the item caption l.setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME) l.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY) # Sets the icon to use with the items l.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG) # Set a reasonable width l.setWidth(350, self.UNITS_PIXELS) # Set the appropriate filtering mode for this example l.setFilteringMode(IFiltering.FILTERINGMODE_STARTSWITH) l.setImmediate(True) l.addListener(self, IValueChangeListener) # Disallow null selections l.setNullSelectionAllowed(False) self.addComponent(l)
class PersonFieldFactory(DefaultFieldFactory): def __init__(self, c): self._c = c super(PersonFieldFactory, self).__init__() self.countries = ComboBox("Country") self.countries.setWidth("100%") self.countries.setContainerDataSource(ExampleUtil.getISO3166Container()) self.countries.setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME) self.countries.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG) self.countries.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH) def createField(self, item, propertyId, uiContext): if "countryCode" == propertyId: # filtering ComboBox w/ country names return self.countries elif "password" == propertyId: # Create a password field so the password is not shown f = self.createPasswordField(propertyId) else: # Use the super class to create a suitable field base # on the property type. f = super(PersonFieldFactory, self).createField(item, propertyId, uiContext) if "firstName" == propertyId: tf = f tf.setRequired(True) tf.setRequiredError("Please enter a First Name") tf.setWidth(self._c._COMMON_FIELD_WIDTH) tf.addValidator(StringLengthValidator("First Name must be 3-25 characters", 3, 25, False)) elif "lastName" == propertyId: tf = f tf.setRequired(True) tf.setRequiredError("Please enter a Last Name") tf.setWidth(self._c._COMMON_FIELD_WIDTH) tf.addValidator(StringLengthValidator("Last Name must be 3-50 characters", 3, 50, False)) elif "password" == propertyId: pf = f pf.setRequired(True) pf.setRequiredError("Please enter a password") pf.setWidth("10em") pf.addValidator(StringLengthValidator("Password must be 6-20 characters", 6, 20, False)) elif "shoesize" == propertyId: tf = f tf.setNullRepresentation("") tf.setNullSettingAllowed(True) tf.addValidator(IntegerValidator("Shoe size must be an Integer")) tf.setWidth("4em") return f def createPasswordField(self, propertyId): pf = PasswordField() pf.setCaption(DefaultFieldFactory.createCaptionByPropertyId(propertyId)) return pf
class DateResolutionExample(VerticalLayout, IValueChangeListener): resolution_PROPERTY_NAME = 'name' # Resolution fields from DateField _resolutions = [ InlineDateField.RESOLUTION_YEAR, InlineDateField.RESOLUTION_MONTH, InlineDateField.RESOLUTION_DAY, InlineDateField.RESOLUTION_HOUR, InlineDateField.RESOLUTION_MIN, InlineDateField.RESOLUTION_SEC, InlineDateField.RESOLUTION_MSEC ] _resolutionNames = [ 'Year', 'Month', 'Day', 'Hour', 'Minute', 'Second', 'Millisecond' ] def __init__(self): super(DateResolutionExample, self).__init__() self.setSpacing(True) self._datetime = InlineDateField('Please select the starting time:') # Set the value of the PopupDateField to current date self._datetime.setValue(datetime.today()) # Set the correct resolution self._datetime.setResolution(InlineDateField.RESOLUTION_DAY) self._datetime.setImmediate(True) # Create selection self._localeSelection = ComboBox('Select resolution:') self._localeSelection.setNullSelectionAllowed(False) self._localeSelection.addListener(self, IValueChangeListener) self._localeSelection.setImmediate(True) # Fill the selection with choices, set captions correctly self._localeSelection.setContainerDataSource( self.getResolutionContainer()) self._localeSelection.setItemCaptionPropertyId( self.resolution_PROPERTY_NAME) self._localeSelection.setItemCaptionMode( ComboBox.ITEM_CAPTION_MODE_PROPERTY) self.addComponent(self._datetime) self.addComponent(self._localeSelection) def valueChange(self, event): self._datetime.setResolution(event.getProperty().getValue()) self._datetime.requestRepaint() def getResolutionContainer(self): resolutionContainer = IndexedContainer() resolutionContainer.addContainerProperty(self.resolution_PROPERTY_NAME, str, None) for i, res in enumerate(self._resolutions): added = resolutionContainer.addItem(res) added.getItemProperty(self.resolution_PROPERTY_NAME).setValue( self._resolutionNames[i]) return resolutionContainer
class DateResolutionExample(VerticalLayout, IValueChangeListener): resolution_PROPERTY_NAME = 'name' # Resolution fields from DateField _resolutions = [ InlineDateField.RESOLUTION_YEAR, InlineDateField.RESOLUTION_MONTH, InlineDateField.RESOLUTION_DAY, InlineDateField.RESOLUTION_HOUR, InlineDateField.RESOLUTION_MIN, InlineDateField.RESOLUTION_SEC, InlineDateField.RESOLUTION_MSEC ] _resolutionNames = [ 'Year', 'Month', 'Day', 'Hour', 'Minute', 'Second', 'Millisecond' ] def __init__(self): super(DateResolutionExample, self).__init__() self.setSpacing(True) self._datetime = InlineDateField('Please select the starting time:') # Set the value of the PopupDateField to current date self._datetime.setValue(datetime.today()) # Set the correct resolution self._datetime.setResolution(InlineDateField.RESOLUTION_DAY) self._datetime.setImmediate(True) # Create selection self._localeSelection = ComboBox('Select resolution:') self._localeSelection.setNullSelectionAllowed(False) self._localeSelection.addListener(self, IValueChangeListener) self._localeSelection.setImmediate(True) # Fill the selection with choices, set captions correctly self._localeSelection.setContainerDataSource( self.getResolutionContainer()) self._localeSelection.setItemCaptionPropertyId( self.resolution_PROPERTY_NAME) self._localeSelection.setItemCaptionMode( ComboBox.ITEM_CAPTION_MODE_PROPERTY) self.addComponent(self._datetime) self.addComponent(self._localeSelection) def valueChange(self, event): self._datetime.setResolution(event.getProperty().getValue()) self._datetime.requestRepaint() def getResolutionContainer(self): resolutionContainer = IndexedContainer() resolutionContainer.addContainerProperty( self.resolution_PROPERTY_NAME, str, None) for i, res in enumerate(self._resolutions): added = resolutionContainer.addItem(res) added.getItemProperty( self.resolution_PROPERTY_NAME).setValue( self._resolutionNames[i]) return resolutionContainer
class PersonFieldFactory(DefaultFieldFactory): def __init__(self, c): self._c = c super(PersonFieldFactory, self).__init__() self.countries = ComboBox('Country') self.countries.setWidth(self._c._COMMON_FIELD_WIDTH) self.countries.setContainerDataSource( ExampleUtil.getISO3166Container()) self.countries.setItemCaptionPropertyId( ExampleUtil.iso3166_PROPERTY_NAME) self.countries.setItemIconPropertyId( ExampleUtil.iso3166_PROPERTY_FLAG) self.countries.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH) def createField(self, item, propertyId, uiContext): if 'countryCode' == propertyId: # filtering ComboBox w/ country names return self.countries elif 'password' == propertyId: # Create a password field so the password is not shown f = self.createPasswordField(propertyId) else: # Use the super class to create a suitable field base on the # property type. f = super(PersonFieldFactory, self).createField(item, propertyId, uiContext) if 'firstName' == propertyId: tf = f tf.setRequired(True) tf.setRequiredError('Please enter a First Name') tf.setWidth(self._c._COMMON_FIELD_WIDTH) tf.addValidator(StringLengthValidator( 'First Name must be 3-25 characters', 3, 25, False)) elif 'lastName' == propertyId: tf = f tf.setRequired(True) tf.setRequiredError('Please enter a Last Name') tf.setWidth(self._c._COMMON_FIELD_WIDTH) tf.addValidator(StringLengthValidator( 'Last Name must be 3-50 characters', 3, 50, False)) elif 'password' == propertyId: pf = f pf.setRequired(True) pf.setRequiredError('Please enter a password') pf.setWidth('10em') pf.addValidator(StringLengthValidator( 'Password must be 6-20 characters', 6, 20, False)) elif 'shoesize' == propertyId: tf = f tf.setNullRepresentation('') tf.setNullSettingAllowed(True) tf.addValidator(IntegerValidator('Shoe size must be an Integer')) tf.setWidth('2em') elif 'uuid' == propertyId: tf = f tf.setWidth('20em') return f def createPasswordField(self, propertyId): pf = PasswordField() pf.setCaption(DefaultFieldFactory.createCaptionByPropertyId(propertyId)) return pf