Search in sources :

Example 6 with ValueWithDisplayString

use of com.android.tools.idea.uibuilder.property.editors.support.ValueWithDisplayString in project android by JetBrains.

the class NlEnumEditor method setModel.

private void setModel(@NotNull NlProperty property) {
    // Do not inline this method. Other classes should not know about EnumSupportFactory.
    assert EnumSupportFactory.supportsProperty(property) : this.getClass().getName() + property;
    myEnumSupport = EnumSupportFactory.create(property);
    myProperty = property;
    myApiVersion = getApiVersion(property);
    List<ValueWithDisplayString> values = myEnumSupport.getAllValues();
    ValueWithDisplayString[] valueArray = values.toArray(new ValueWithDisplayString[0]);
    DefaultComboBoxModel<ValueWithDisplayString> newModel = new DefaultComboBoxModel<ValueWithDisplayString>(valueArray) {

        @Override
        public void setSelectedItem(Object object) {
            if (object instanceof String) {
                // This is a weird callback from Swing.
                // It seems to happen when we are losing focus.
                // We need to convert this string to a ValueWithDisplayString.
                // Also note that the toString() value will be set in the editor and we want the real value.
                object = createFromEditorValue((String) object);
            }
            if (object instanceof ValueWithDisplayString) {
                ValueWithDisplayString value = (ValueWithDisplayString) object;
                value.setUseValueForToString(myDisplayRealValue);
            }
            super.setSelectedItem(object);
        }
    };
    ValueWithDisplayString defaultValue = createFromEditorValue(null);
    newModel.insertElementAt(defaultValue, 0);
    //noinspection unchecked
    myCombo.setModel(newModel);
    // nothing added
    myAddedValueIndex = -1;
}
Also used : ValueWithDisplayString(com.android.tools.idea.uibuilder.property.editors.support.ValueWithDisplayString) ValueWithDisplayString(com.android.tools.idea.uibuilder.property.editors.support.ValueWithDisplayString)

Aggregations

ValueWithDisplayString (com.android.tools.idea.uibuilder.property.editors.support.ValueWithDisplayString)6 Quantity (com.android.tools.idea.uibuilder.property.editors.support.Quantity)1 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)1