ConfigItem: add all types except LOCALE (array still not working)
[nikiroo-utils.git] / src / be / nikiroo / utils / resources / MetaInfo.java
index 746fd4d939a71f346c3529b63fd65b13af5f9be9..d95e98c986a0e53266bbd203f95efa90066a7580 100644 (file)
@@ -1,6 +1,7 @@
 package be.nikiroo.utils.resources;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -17,11 +18,12 @@ import be.nikiroo.utils.resources.Meta.Format;
  * @param <E>
  *            the type of {@link Bundle} to edit
  */
-public class MetaInfo<E extends Enum<E>> {
+public class MetaInfo<E extends Enum<E>> implements Iterable<MetaInfo<E>> {
        private final Bundle<E> bundle;
        private final E id;
 
        private Meta meta;
+       private List<MetaInfo<E>> children = new ArrayList<MetaInfo<E>>();
 
        private String value;
        private List<Runnable> reloadedListeners = new ArrayList<Runnable>();
@@ -53,8 +55,14 @@ public class MetaInfo<E extends Enum<E>> {
 
                if (description == null) {
                        description = meta.description();
+                       if (description == null) {
+                               description = "";
+                       }
                        if (meta.info() != null && !meta.info().isEmpty()) {
-                               description += " (" + meta.info() + ")";
+                               if (!description.isEmpty()) {
+                                       description += "\n\n";
+                               }
+                               description += meta.info();
                        }
                }
 
@@ -94,6 +102,16 @@ public class MetaInfo<E extends Enum<E>> {
                return meta.format();
        }
 
+       // for ComboBox, this is mostly a suggestion
+       public String[] getAllowedValues() {
+               return meta.list();
+       }
+
+       // TODO: use it!
+       public boolean isArray() {
+               return meta.array();
+       }
+
        /**
         * The value stored by this item, as a {@link String}.
         * 
@@ -217,6 +235,15 @@ public class MetaInfo<E extends Enum<E>> {
                saveListeners.add(listener);
        }
 
+       @Override
+       public Iterator<MetaInfo<E>> iterator() {
+               return children.iterator();
+       }
+
+       public List<MetaInfo<E>> getChildren() {
+               return children;
+       }
+
        /**
         * Create a list of {@link MetaInfo}, one for each of the item in the given
         * {@link Bundle}.