1. #21
    Sencha User
    Join Date
    Mar 2011
    Posts
    2
    Vote Rating
    0
    bpossolo is on a distinguished road

      0  

    Default


    The solutions above all sound pretty overkill however they may be a bit outdated.

    You can simply leverage SimpleComboBox to list enums as follows:

    public enum Condition {
    New,
    Used,
    Damaged
    }

    SimpleComboBox<Condition> conditionCombo = new SimpleComboBox<Condition>();

    for( Condition condition : Condition.values() )
    conditionCombo.add(condition);

    You can control the text that renders by overriding the Condition.toString() method.

    if you need more power over what is displayed (for example, multilingual apps), then you can either override the SimpleComboBox methods (or provide a property editor) or with some clever tricks on the SimpleComboValue class (which the SimpleComboBox uses internally)

  2. #22
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,731
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    The code really hasn't changed too much, and while you could override those things, they would inevitably need a switch case, or a map lookup, or something to finally get the i18n'd value. If you have many enums throughout your app, it quickly becomes clear that the i18n has to be on the data side of things, not just in subclassing the view over and over.

  3. #23
    Ext GWT Premium Member
    Join Date
    Mar 2009
    Posts
    226
    Vote Rating
    3
    The_Jackal is on a distinguished road

      0  

    Default


    I had a case where I didn't want to use the enum's toString() method, rather I wanted to call a getLabel() method that does my GWT.create() call for i18n.

    I didn't want to use toString() for the i18n as I want toString() to still work on the server side.

    Here's the code to make to call a different method to get the text representation. It does the following:
    • Convert the value in the ComboBox with a property editor to call getLabel()
    • Convert the values in the list with a ModelProcessor to call getLabel() and Template

    The ComboBox that uses Condition enum (with a getLabel() method for i18n)
    Code:
    final SimpleComboBox<Condition> combo = new SimpleComboBox<Condition>();
    combo.setFieldLabel("Condition");
    combo.setName("condition");
    combo.add(Arrays.asList(Condition.values()));        
    combo.setEditable(false);
    combo.setAllowBlank(false);
    combo.setTriggerAction(TriggerAction.ALL);
    combo.setSimpleValue(Condition.NEW);
    Code:
    // Replace the text in the box with the enums label
    ListModelPropertyEditor<SimpleComboValue<Condition>> propEditor = 
        new ListModelPropertyEditor<SimpleComboValue<Condition>>()
        {
             public String getStringValue(SimpleComboValue<Condition> value) {
                 return value.getValue().getLabel();
             }
    };
    
    propEditor.setDisplayProperty("label");
    combo.setPropertyEditor(propEditor);
            
    // Replace the text in the list with the enums labels
    combo.getView().setModelProcessor(new ModelProcessor<SimpleComboValue<Condition>>() {
        public SimpleComboValue<Condition> prepareData(SimpleComboValue<Condition> model) {
            model.set("label", model.getValue().getLabel());
            return model;
        }
    });
            
    // Use getLabel in list (by default SimpleComboBox displayProperty "value" is used - calls enum toString)
    String html = "<tpl for=\".\"><div role=\"listitem\" class=\"" + combo.getListStyle() + "-item\">{" + "label" + "}</div></tpl>";
    combo.setTemplate(html);
    Verbose, but not too tricky. Hope this helps someone do the same.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi