Java 类org.springframework.core.enums.LabeledEnum 实例源码

项目:spring-rich-client    文件:SwingBinderSelectionStrategy.java   
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));
}
项目:spring-richclient    文件:SwingBinderSelectionStrategy.java   
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));
}
项目:spring-rich-client    文件:LabeledEnumComboBoxBinding.java   
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);
}
项目:spring-rich-client    文件:LabeledEnumComboBoxEditor.java   
/**
 * @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);
    }
}
项目:spring-rich-client    文件:LabeledEnumListRenderer.java   
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;
}
项目:spring-rich-client    文件:DefaultComponentFactory.java   
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()));
}
项目:spring-rich-client    文件:LabeledEnumTableCellRenderer.java   
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);
}
项目:spring-rich-client    文件:AbstractSettings.java   
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 );
}
项目:spring-rich-client    文件:AbstractSettings.java   
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 );
}
项目:spring-rich-client    文件:SettingsAbstractTests.java   
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() );
}
项目:spring-richclient    文件:LabeledEnumComboBoxBinding.java   
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);
}
项目:spring-richclient    文件:LabeledEnumComboBoxEditor.java   
/**
 * @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);
    }
}
项目:spring-richclient    文件:LabeledEnumListRenderer.java   
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;
}
项目:spring-richclient    文件:DefaultComponentFactory.java   
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()));
}
项目:spring-richclient    文件:LabeledEnumTableCellRenderer.java   
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);
}
项目:spring-richclient    文件:AbstractSettings.java   
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 );
}
项目:spring-richclient    文件:AbstractSettings.java   
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 );
}
项目:spring-richclient    文件:SettingsAbstractTests.java   
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() );
}
项目:spring-rich-client    文件:AbstractBinderSelectionStrategy.java   
protected boolean isEnumeration(FormModel formModel, String formPropertyPath) {
    return LabeledEnum.class.isAssignableFrom(getPropertyType(formModel, formPropertyPath));
}
项目:spring-rich-client    文件:AbstractSettings.java   
private LabeledEnum stringToEnum( String s ) {
    if( s == null || s.trim().equals( "" ) ) {
        return null;
    }
    return (LabeledEnum) ClassUtils.getFieldValue( s );
}
项目:spring-rich-client    文件:AbstractSettings.java   
private String enumToString( LabeledEnum e ) {
    return e == null ? "" : ClassUtils.getClassFieldNameWithValue( e.getClass(), e );
}
项目:spring-rich-client    文件:AbstractSettings.java   
public void setDefaultLabeledEnum( String key, LabeledEnum value ) {
    Assert.notNull( key, "Key cannot be null" );

    defaults.put( key, enumToString( value ) );
}
项目:spring-rich-client    文件:AbstractSettings.java   
public LabeledEnum getDefaultLabeledEnum( String key ) {
    Assert.notNull( key, "Key cannot be null" );
    return stringToEnum( (String) defaults.get( key ) );
}
项目:spring-richclient    文件:AbstractBinderSelectionStrategy.java   
protected boolean isEnumeration(FormModel formModel, String formPropertyPath) {
    return LabeledEnum.class.isAssignableFrom(getPropertyType(formModel, formPropertyPath));
}
项目:spring-richclient    文件:AbstractSettings.java   
private LabeledEnum stringToEnum( String s ) {
    if( s == null || s.trim().equals( "" ) ) {
        return null;
    }
    return (LabeledEnum) ClassUtils.getFieldValue( s );
}
项目:spring-richclient    文件:AbstractSettings.java   
private String enumToString( LabeledEnum e ) {
    return e == null ? "" : ClassUtils.getClassFieldNameWithValue( e.getClass(), e );
}
项目:spring-richclient    文件:AbstractSettings.java   
public void setDefaultLabeledEnum( String key, LabeledEnum value ) {
    Assert.notNull( key, "Key cannot be null" );

    defaults.put( key, enumToString( value ) );
}
项目:spring-richclient    文件:AbstractSettings.java   
public LabeledEnum getDefaultLabeledEnum( String key ) {
    Assert.notNull( key, "Key cannot be null" );
    return stringToEnum( (String) defaults.get( key ) );
}
项目:spring-rich-client    文件:ClassUtils.java   
/**
 * 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);
}
项目:spring-richclient    文件:ClassUtils.java   
/**
 * 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);
}
项目:spring-rich-client    文件:Settings.java   
void setLabeledEnum(String key, LabeledEnum value);
项目:spring-rich-client    文件:Settings.java   
LabeledEnum getLabeledEnum(String key);
项目:spring-rich-client    文件:Settings.java   
void setDefaultLabeledEnum(String key, LabeledEnum value);
项目:spring-rich-client    文件:Settings.java   
LabeledEnum getDefaultLabeledEnum(String key);
项目:spring-richclient    文件:Settings.java   
void setLabeledEnum(String key, LabeledEnum value);
项目:spring-richclient    文件:Settings.java   
LabeledEnum getLabeledEnum(String key);
项目:spring-richclient    文件:Settings.java   
void setDefaultLabeledEnum(String key, LabeledEnum value);
项目:spring-richclient    文件:Settings.java   
LabeledEnum getDefaultLabeledEnum(String key);