1
2
3
4
5
6
7
8
9
10
11 package de.jaret.util.ui.table.filter;
12
13 import java.util.HashSet;
14 import java.util.Set;
15
16 import de.jaret.util.misc.PropertyObservableBase;
17 import de.jaret.util.ui.table.JaretTable;
18 import de.jaret.util.ui.table.model.IColumn;
19 import de.jaret.util.ui.table.model.IRow;
20
21 /***
22 * An abstract base that can be used when implementing autofilters.
23 *
24 * @author kliem
25 * @version $Id: AbstractAutoFilter.java 385 2007-04-29 20:31:49Z olk $
26 */
27 public abstract class AbstractAutoFilter extends PropertyObservableBase implements IAutoFilter {
28 /*** table of the autofilter. */
29 protected JaretTable _table;
30
31 /*** column of the autofilter. */
32 protected IColumn _column;
33
34 /***
35 * {@inheritDoc}
36 */
37 public void setColumn(IColumn column) {
38 _column = column;
39 }
40
41 /***
42 * {@inheritDoc}
43 */
44 public void setTable(JaretTable table) {
45 _table = table;
46 }
47
48 /***
49 * Get all possible filter strings for the autofilter comboboxes.
50 *
51 * @param col the column to look at
52 * @param maxLength the maxmium length of the individual strings. If a string is larger than that it wil be
53 * truncated, -1 for no truncation
54 * @return set of strings, shortened if necessary
55 */
56 protected Set<String> getColFilterStrings(IColumn col, int maxLength) {
57 Set<String> result = new HashSet<String>();
58 for (int i = 0; i < _table.getRowCount(); i++) {
59 IRow row = _table.getRow(i);
60 Object val = col.getValue(row);
61 if (val != null) {
62 String valStr = val.toString();
63 if (maxLength != -1 && valStr.length() > maxLength) {
64
65 valStr = valStr.substring(0, maxLength - 1);
66 }
67 result.add(valStr);
68 }
69 }
70
71 return result;
72 }
73
74 }