01: /*
02: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
03: * @version $Id: BeanContainer.java 6385 2007-10-25 14:02:26Z wehrens $
04: */
05:
06: package org.gridsphere.provider.portletui.beans;
07:
08: import java.util.*;
09:
10: /**
11: * The abstract <code>BeanContainer</code> is a container for other visual beans
12: */
13: public abstract class BeanContainer extends BaseComponentBean {
14:
15: public List<BaseComponentBean> container = new Vector<BaseComponentBean>();
16:
17: /**
18: * Constructs a default bean container
19: */
20: public BeanContainer() {
21: }
22:
23: /**
24: * Constructs a bean container with the supplied name
25: *
26: * @param name the bean container name
27: */
28: public BeanContainer(String name) {
29: super (name);
30: }
31:
32: /**
33: * Adds a visual bean to the bean container
34: *
35: * @param bean a base component bean
36: */
37: public void addBean(BaseComponentBean bean) {
38: container.add(bean);
39: }
40:
41: /**
42: * Adds a visual bean to the bean container
43: *
44: * @param index the position in the container to insert the bean
45: * @param bean a base component bean
46: */
47: public void setBean(int index, BaseComponentBean bean) {
48: container.set(index, bean);
49: }
50:
51: /**
52: * Removes a visual bean from the bean container
53: *
54: * @param bean the visual bean to remove
55: */
56: public void removeBean(BaseComponentBean bean) {
57: container.remove(bean);
58: }
59:
60: /**
61: * Clears the list of visual beans in this container
62: */
63: public void clear() {
64: container.clear();
65: }
66:
67: /**
68: * Returns the visual beans as a list of <code>BaseComponentBean</code>s
69: *
70: * @return the list of visual beans
71: */
72: public List<BaseComponentBean> getBeans() {
73: return Collections.unmodifiableList(container);
74: }
75:
76: /**
77: * Sorts the List by the value of the basecomponentbeans.
78: *
79: * @see BaseComponentBean
80: */
81: public void sortByValue() {
82: SortedSet<BaseComponentBean> sorted = new TreeSet<BaseComponentBean>();
83: for (int i = 0; i < container.size(); i++) {
84: sorted.add(container.get(i));
85: }
86: List<BaseComponentBean> result = new Vector<BaseComponentBean>();
87: for (BaseComponentBean aSorted : sorted) {
88: result.add(aSorted);
89: }
90: container = result;
91: }
92:
93: }
|