protected void registerDefaultBinders() { registerBinderForPropertyType(String.class, new TextComponentBinder()); registerBinderForPropertyType(boolean.class, new CheckBoxBinder()); registerBinderForPropertyType(Boolean.class, new CheckBoxBinder()); registerBinderForPropertyType(LabeledEnum.class, new LabeledEnumComboBoxBinder()); registerBinderForControlType(JTextComponent.class, new TextComponentBinder()); registerBinderForControlType(JFormattedTextField.class, new FormattedTextFieldBinder(null)); registerBinderForControlType(JTextArea.class, new TextAreaBinder()); registerBinderForControlType(JToggleButton.class, new ToggleButtonBinder()); registerBinderForControlType(JCheckBox.class, new CheckBoxBinder()); registerBinderForControlType(JComboBox.class, new ComboBoxBinder()); registerBinderForControlType(JList.class, new ListBinder()); registerBinderForControlType(JLabel.class, new LabelBinder()); registerBinderForControlType(JScrollPane.class, new ScrollPaneBinder(this, JTextArea.class)); }
protected void doBindControl(ListModel bindingModel) { setRenderer(new LabeledEnumListRenderer(getMessageSource())); setEditor(new LabeledEnumComboBoxEditor(getMessageSource(), getEditor())); CompoundComparator comparator = new CompoundComparator(); comparator.addComparator(LabeledEnum.LABEL_ORDER); comparator.addComparator(new ComparableComparator()); setComparator(comparator); super.doBindControl(bindingModel); }
/** * @see javax.swing.ComboBoxEditor#setItem(java.lang.Object) */ public void setItem(Object anObject) { current = anObject; if (anObject != null) { if (messages != null && anObject instanceof MessageSourceResolvable) { inner.setItem(messages.getMessage((MessageSourceResolvable)anObject, Locale.getDefault())); } else { inner.setItem(((LabeledEnum)anObject).getLabel()); } } else { inner.setItem(null); } }
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value == null) { return this; } if (messages != null && value instanceof MessageSourceResolvable) { setText(messages.getMessage((MessageSourceResolvable)value, Locale.getDefault())); } else { setText(((LabeledEnum)value).getLabel()); } return this; }
public void configureForEnum(JComboBox comboBox, Class enumType) { Collection enumValues = getEnumResolver().getLabeledEnumSet(enumType); if (logger.isDebugEnabled()) { logger.debug("Populating combo box model with enums of type '" + enumType.getName() + "'; enums are [" + enumValues + "]"); } CompoundComparator comparator = new CompoundComparator(); comparator.addComparator(LabeledEnum.LABEL_ORDER); comparator.addComparator(new ComparableComparator()); comboBox.setModel(new ComboBoxListModel(new ArrayList(enumValues), comparator)); comboBox.setRenderer(new LabeledEnumListRenderer(messageSource)); comboBox.setEditor(new LabeledEnumComboBoxEditor(messageSource, comboBox.getEditor())); }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value != null) { if (messages != null && value instanceof MessageSourceResolvable) { value = messages.getMessage((MessageSourceResolvable) value, Locale.getDefault()); } else { value = ((LabeledEnum) value).getLabel(); } } return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); }
public void setLabeledEnum( String key, LabeledEnum value ) { Assert.notNull( key, "Key cannot be null" ); LabeledEnum old = getLabeledEnum( key ); internalSet( key, enumToString( value ) ); afterSet( key, old, value ); }
public LabeledEnum getLabeledEnum( String key ) { Assert.notNull( key, "Key cannot be null" ); String value = internalGet( key ); if( !StringUtils.hasText( value ) ) { return getDefaultLabeledEnum( key ); } return stringToEnum( value ); }
public final void testEnum() { String key = "enum-value"; LabeledEnum defaultValue = null; LabeledEnum newValue = TestEnum.ENUM2; // default value assertEquals( defaultValue, settings.getLabeledEnum( key ) ); assertEquals( defaultValue, settings.getDefaultLabeledEnum( key ) ); assertTrue( settings.isDefault( key ) ); assertFalse( settings.contains( key ) ); // change the value settings.setLabeledEnum( key, newValue ); assertEquals( newValue, settings.getLabeledEnum( key ) ); assertFalse( settings.isDefault( key ) ); assertTrue( settings.contains( key ) ); // check property change event assertPropertyChangeEventFired( key, defaultValue, newValue ); propertyChangeListener.reset(); // change the value to the same value, no property change event should // be fired settings.setLabeledEnum( key, newValue ); assertEquals( 0, propertyChangeListener.getCount() ); }
protected boolean isEnumeration(FormModel formModel, String formPropertyPath) { return LabeledEnum.class.isAssignableFrom(getPropertyType(formModel, formPropertyPath)); }
private LabeledEnum stringToEnum( String s ) { if( s == null || s.trim().equals( "" ) ) { return null; } return (LabeledEnum) ClassUtils.getFieldValue( s ); }
private String enumToString( LabeledEnum e ) { return e == null ? "" : ClassUtils.getClassFieldNameWithValue( e.getClass(), e ); }
public void setDefaultLabeledEnum( String key, LabeledEnum value ) { Assert.notNull( key, "Key cannot be null" ); defaults.put( key, enumToString( value ) ); }
public LabeledEnum getDefaultLabeledEnum( String key ) { Assert.notNull( key, "Key cannot be null" ); return stringToEnum( (String) defaults.get( key ) ); }
/** * Does the provided bean class represent a simple scalar property? A simple * scalar property is considered a value property; that is, it is not * another bean. Examples include primitives, primitive wrappers, Enums, and * Strings. */ public static boolean isSimpleScalar(Class clazz) { return clazz.isPrimitive() || simpleClasses.contains(clazz) || LabeledEnum.class.isAssignableFrom(clazz); }
void setLabeledEnum(String key, LabeledEnum value);
LabeledEnum getLabeledEnum(String key);
void setDefaultLabeledEnum(String key, LabeledEnum value);
LabeledEnum getDefaultLabeledEnum(String key);