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;
}
Aggregations