/*
 * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.

 * Author: Dmitry Abramov
 * Created: 06.03.2009 13:41:01
 * $Id$
 */
package com.haulmont.cuba.web.gui.data;

import com.itmill.toolkit.data.Item;
import com.itmill.toolkit.data.Property;

import java.util.List;
import java.util.Collection;
import java.util.Collections;

public class EnumerationContainer implements com.itmill.toolkit.data.Container {
    private List<Enum> values;

    public EnumerationContainer(List<Enum> values) {
        this.values = values;
    }

    public Item getItem(Object itemId) {
        return new EnumerationItem(itemId);
    }

    public Collection getContainerPropertyIds() {
        return Collections.emptyList();
    }

    public Collection getItemIds() {
        return values;
    }

    public Property getContainerProperty(Object itemId, Object propertyId) {
        throw new UnsupportedOperationException();
    }

    public Class getType(Object propertyId) {
        throw new UnsupportedOperationException();
    }

    public int size() {
        return values.size();
    }

    public boolean containsId(Object itemId) {
        return values.contains(itemId);
    }

    public Item addItem(Object itemId) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public Object addItem() throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public boolean removeItem(Object itemId) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public boolean addContainerProperty(Object propertyId, Class type, Object defaultValue) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public boolean removeAllItems() throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    private static class EnumerationItem implements Item {
        private Object item;

        public EnumerationItem(Object itemId) {
            this.item = itemId;
        }

        public Property getItemProperty(Object id) {
            throw new UnsupportedOperationException();
        }

        public Collection getItemPropertyIds() {
            return Collections.emptyList();
        }

        public boolean addItemProperty(Object id, Property property) throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        public boolean removeItemProperty(Object id) throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        @Override
        public String toString() {
            return item.toString();
        }
    }
}

@@ -355,16 +355,71 @@
 operty;%0D
+%0Aimport com.haulmont.cuba.core.global.MessageProvider;%0D
 %0A%0D%0Aimpor
@@ -500,16 +500,63 @@
 ons;%0D%0A%0D%0A
+import org.apache.commons.lang.StringUtils;%0D%0A%0D%0A
 public c
@@ -2432,16 +2432,46 @@
 t item;%0D
+%0A        private String name;%0D
 %0A%0D%0A     
@@ -2547,16 +2547,247 @@
 temId;%0D%0A
+            String nameKey = item.getClass().getSimpleName() + %22.%22 + item.toString();%0D%0A%0D%0A            name = MessageProvider.getMessage(item.getClass(), nameKey);%0D%0A            if (StringUtils.isEmpty(name)) name = item.toString();%0D%0A
         
@@ -3436,31 +3436,20 @@
  return 
-item.toString()
+name
 ;%0D%0A     

integrate MessageProvider and enums