01: package fr.aliacom.common.ui.table;
02:
03: import java.util.ArrayList;
04:
05: /**
06: * This class representents the column model for the {@link fr.aliacom.common.ui.ITable}.
07: *
08: * This class maps a tables columns to properties in the java bean
09: * displayed by the {@link fr.aliacom.common.ui.ITable} instance.
10: * Each column is a bean property.
11: * Several columns can display the same property.
12: *
13: * @author tom
14: *
15: * (C) 2001, 2002 Thomas Cataldo
16: */
17: public final class BeanPropertiesMapping {
18:
19: private ArrayList properties;
20: private ArrayList titles;
21:
22: /**
23: * Creates an empty column model.
24: */
25: public BeanPropertiesMapping() {
26: properties = new ArrayList();
27: titles = new ArrayList();
28: }
29:
30: /**
31: * Creates a column model suitable for displaying the properties listed
32: * in the ArrayList provided.
33: *
34: * @param properties the list of properties name
35: */
36: public BeanPropertiesMapping(ArrayList properties) {
37: this .properties = properties;
38: }
39:
40: /**
41: * Adds a property to the model. The property will be displayed by the table
42: * in a column named by the given title.
43: *
44: * @param property the java bean property name
45: * @param title the title of the column
46: */
47: public void addProperty(String property, String title) {
48: properties.add(property);
49: titles.add(title);
50: }
51:
52: /**
53: * Returns the name of the property displayed by the table at given column
54: * index.
55: *
56: * @param index the column number, starting at 0.
57: * @return the property at the given index
58: */
59: public String getProperty(int index) {
60: return properties.get(index).toString();
61: }
62:
63: /**
64: * Return the index of the column displaying a given property.
65: * Returns -1 if the property is not found.
66: *
67: * @param property
68: * @return the index of the property or -1 if not found
69: */
70: public int getIndex(String property) {
71: return properties.indexOf(property);
72: }
73:
74: /**
75: * Get the title of the column displayed at a given index.
76: *
77: * @param column the index of the column
78: * @return the human readable title.
79: */
80: public String getTitle(int column) {
81: return titles.get(column).toString();
82: }
83:
84: /**
85: * Method getPropertiesCount.
86: * @return the number of column/properties
87: */
88: public int getPropertiesCount() {
89: return properties.size();
90: }
91: }
|