teichmann@5835: package org.dive4elements.river.client.shared.model; ingo@51: ingo@51: import java.io.Serializable; ingo@51: import java.util.ArrayList; ingo@51: import java.util.List; ingo@51: ingo@51: /** ingo@51: * @author Ingo Weinzierl ingo@51: */ ingo@872: public class DataList implements Serializable, Cloneable { ingo@51: felix@1296: /** The list of Data objects managed by this list. */ ingo@51: protected List data; ingo@51: felix@1296: /** The name of the state that this list belongs to. */ ingo@51: protected String state; ingo@51: felix@1296: /** The name of a UIProvider that is recommended to render this DataList. */ ingo@51: protected String uiprovider; ingo@51: felix@1296: /** The label that should be used to label data objects. */ ingo@51: protected String label; ingo@51: ingo@2500: /** The help text (URL) that should be displayed for this data object. */ ingo@2500: protected String helpText; ingo@2500: ingo@51: ingo@51: /** ingo@51: * The default constructor that creates a new DataList without Data objects ingo@51: * and no UIProvider. ingo@51: */ ingo@51: public DataList() { ingo@51: data = new ArrayList(); ingo@51: } ingo@51: ingo@51: ingo@52: /** ingo@52: * Constructor. ingo@52: * ingo@52: * @param state The name of the state that this list belongs to. ingo@52: * @param size The initial size of the list. ingo@52: */ ingo@51: public DataList(String state, int size) { ingo@51: this.state = state; ingo@51: this.data = new ArrayList(size); ingo@51: } ingo@51: ingo@51: ingo@51: /** ingo@51: * A constructor that creates a new DataList without Data objects and no ingo@51: * UIProvider. Size defines the initial size of the list. ingo@51: * ingo@52: * @param state The name of the state that this list belongs to. ingo@51: * @param size The initial size of the list. ingo@52: * @param uiprovider The UIProvider that should be used to render this list. ingo@51: */ ingo@51: public DataList(String state, int size, String uiprovider) { ingo@51: this(state, size); ingo@51: this.uiprovider = uiprovider; ingo@51: } ingo@51: ingo@51: ingo@51: /** ingo@52: * A constructor that creates a new DataList without Data objects and no ingo@52: * UIProvider. Size defines the initial size of the list. ingo@52: * ingo@52: * @param state The name of the state that this list belongs to. ingo@52: * @param size The initial size of the list. ingo@52: * @param uiprovider The UIProvider that should be used to render this list. ingo@52: * @param label The label. ingo@52: */ ingo@52: public DataList(String state, int size, String uiprovider, String label) { ingo@52: this(state, size, uiprovider); ingo@52: this.label = label; ingo@52: } ingo@52: ingo@52: ingo@52: /** ingo@2500: * A constructor that creates a new DataList without Data objects and no ingo@2500: * UIProvider. Size defines the initial size of the list. ingo@2500: * ingo@2500: * @param state The name of the state that this list belongs to. ingo@2500: * @param size The initial size of the list. ingo@2500: * @param uiprovider The UIProvider that should be used to render this list. ingo@2500: * @param label The label. ingo@2500: * @param helpText The help text (should be an URL). ingo@2500: */ ingo@2500: public DataList( ingo@2500: String state, ingo@2500: int size, ingo@2500: String uiprovider, ingo@2500: String label, ingo@2500: String helpText ingo@2500: ) { ingo@2500: this(state, size, uiprovider, label); ingo@2500: this.helpText = helpText; ingo@2500: } ingo@2500: ingo@2500: ingo@2500: /** ingo@51: * Adds a new Data object to the list. ingo@51: * ingo@51: * @param obj The Data object. ingo@51: */ ingo@51: public void add(Data obj) { ingo@51: if (obj != null) { ingo@51: data.add(obj); ingo@51: } ingo@51: } ingo@51: ingo@51: ingo@51: /** ingo@51: * Adds a new Data objects to the list. ingo@51: * ingo@51: * @param obj The Data object. ingo@51: */ ingo@51: public void add(Data[] obj) { ingo@51: if (obj != null) { ingo@51: for (Data o: obj) { ingo@51: data.add(o); ingo@51: } ingo@51: } ingo@51: } ingo@51: ingo@51: ingo@51: /** ingo@51: * Returns the Data element at position idx. ingo@51: * ingo@51: * @param idx The position of an element that should be returned. ingo@51: * ingo@51: * @return the Data element at position idx. ingo@51: */ ingo@51: public Data get(int idx) { ingo@51: if (idx < size()) { ingo@51: return data.get(idx); ingo@51: } ingo@51: ingo@51: return null; ingo@51: } ingo@51: ingo@51: ingo@51: /** ingo@52: * Returns the whole list of Data objects. ingo@52: * ingo@52: * @return the whole list of Data objects. ingo@52: */ ingo@52: public List getAll() { ingo@52: return data; ingo@52: } ingo@52: ingo@52: /** ingo@51: * Returns the number of Data objects in the list. ingo@51: * ingo@51: * @param the number of Data objects in the list. ingo@51: */ ingo@51: public int size() { ingo@51: return data.size(); ingo@51: } ingo@51: ingo@51: ingo@51: /** ingo@51: * Returns the name of the state that this list belongs to. ingo@51: * ingo@51: * @return the name of the state that this list belongs to. ingo@51: */ ingo@51: public String getState() { ingo@51: return state; ingo@51: } ingo@51: ingo@51: ingo@51: /** ingo@51: * Returns the label for this list. ingo@51: * ingo@51: * @return the label of this list. ingo@51: */ ingo@51: public String getLabel() { ingo@51: return label; ingo@51: } ingo@51: ingo@51: ingo@51: /** ingo@51: * Retrieves the name of a UIProvider or null if no one is recommended. ingo@51: * ingo@51: * @return the name of a UIProvider or null if no one is recommended. ingo@51: */ ingo@51: public String getUIProvider() { ingo@51: return uiprovider; ingo@51: } ingo@872: ingo@872: ingo@2500: /** ingo@2500: * Returns the help text which should be an URL. ingo@2500: * ingo@2500: * @return the help text. ingo@2500: */ ingo@2500: public String getHelpText() { ingo@2500: return helpText; ingo@2500: } ingo@2500: ingo@2500: ingo@872: public Object clone() { ingo@872: DataList clone = new DataList( ingo@872: this.state, ingo@872: this.data.size(), ingo@872: this.uiprovider, ingo@2500: this.label, ingo@2500: this.helpText); ingo@872: clone.data = (List) ((ArrayList)data).clone(); ingo@872: ingo@872: return clone; ingo@872: } ingo@51: } ingo@51: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :