1. #1
    Ext GWT Premium Member
    Join Date
    Jul 2009
    Posts
    104
    Vote Rating
    0
    VadimV1144 is on a distinguished road

      0  

    Default Answered: Using the Enum directly in Combobox

    Answered: Using the Enum directly in Combobox


    Hi,
    Is there a way to directly use Enums with the ListStore. That is without writing a wrapper or custom interface?

    For example, if I do something like this:
    Code:
    public interface EnumProperties extends PropertyAccess<Enum> {
    
    
        @Editor.Path("name")
        ModelKeyProvider<Enum> name();
    
    
        @Editor.Path("name")
        LabelProvider<Enum> label();
    }
    And then try to use this property access with the store,

    Code:
    final ListStore<Enum> store = new ListStore<Enum>(props.name());
    I get a very interesting exception :

    Code:
    java.lang.SecurityException: Prohibited package name: java.lang

  2. That is interesting. According to https://developers.google.com/web-to...efJreEmulation that should be legal - I'll see if I can learn anything about this further.

    It should be pretty straightforward to work around this, but building a class that implements both ModelKeyProvider<Enum<?>> and LabelProvider<Enum<?>> and returns the name() value for both. As reusable as this is - no need to GWT.create it though, just create a new instance whenever you need it.

    Also perhaps worth pointing out that if the ListStore is going to contain any enum (not just from the same type), name() may not be unique. Additionally, name() may not be great from an i18n perspective.

  3. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,640
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    That is interesting. According to https://developers.google.com/web-to...efJreEmulation that should be legal - I'll see if I can learn anything about this further.

    It should be pretty straightforward to work around this, but building a class that implements both ModelKeyProvider<Enum<?>> and LabelProvider<Enum<?>> and returns the name() value for both. As reusable as this is - no need to GWT.create it though, just create a new instance whenever you need it.

    Also perhaps worth pointing out that if the ListStore is going to contain any enum (not just from the same type), name() may not be unique. Additionally, name() may not be great from an i18n perspective.

  4. #3
    Sencha User PhiLho's Avatar
    Join Date
    Nov 2011
    Location
    Near Paris, France
    Posts
    139
    Answers
    2
    Vote Rating
    1
    PhiLho is on a distinguished road

      0  

    Default


    Indeed, I have an enum defined in a shared class (so I can pass the value in a DTO), and to display it in a combo box, I used something like:
    Code:
       private final LabelProvider<ImportParameters.AttributeKeyField> keyFieldLabelProvider = new LabelProvider<ImportParameters.AttributeKeyField>()
       {
          @Override
          public String getLabel(ImportParameters.AttributeKeyField akf)
          {
            switch (akf)
            {
               case LONG_NAME:
                  return messages.longName();
               case SHORT_NAME:
                  return messages.shortName();
               case NAME_IN_FILE:
                  return messages.nameInFile();
               default:
                  return messages.undefined();
            }
          }
       };
    where AttributeKeyField is the enum defined in the ImportParameters class.
    If you don't care about i18n, you can replace the body with a simple akf.getDisplayName() or similar method defined on the enum. It is less straightforward than what you describe, but more flexible without much more code.

  5. #4
    Ext GWT Premium Member
    Join Date
    Jul 2009
    Posts
    104
    Vote Rating
    0
    VadimV1144 is on a distinguished road

      0  

    Default


    Thank you for your replies, it was really helpful.

    I ended up with something like this:
    Code:
    public class EnumProperties implements ModelKeyProvider<Enum>, LabelProvider<Enum> {
    
    
        @Override
        public String getLabel(Enum item) {
    
    
            String s = EnumTranslatorMap.getLocalisedString(item);
            return (s == null)?item.name():s;
        }
    
    
        @Override
        public String getKey(Enum item) {
            return item.getClass().getName()+"_"+item.name();
        }
    
    
    }
    EnumTranslatorMap is my custom enum translator that gets me the correct i18n.
    And for the key, I use combination of the class name and the enum name.

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar