01: package net.sourceforge.squirrel_sql.client.session.mainpanel;
02:
03: import java.text.SimpleDateFormat;
04: import java.util.ArrayList;
05: import java.util.Collections;
06:
07: import net.sourceforge.squirrel_sql.fw.util.StringManager;
08: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
09:
10: public class SQLHistoryItemWrapper {
11: /** Internationalized strings for this class. */
12: private static final StringManager s_stringMgr = StringManagerFactory
13: .getStringManager(SQLHistoryItemWrapper.class);
14:
15: private static final String[] COLUMNS = new String[] {
16: // i18n[SQLHistoryItemWrapper.index=Index]
17: s_stringMgr.getString("SQLHistoryItemWrapper.index"),
18:
19: // i18n[SQLHistoryItemWrapper.lastUsed=Last used]
20: s_stringMgr.getString("SQLHistoryItemWrapper.lastUsed"),
21:
22: // i18n[SQLHistoryItemWrapper.sql=SQL]
23: s_stringMgr.getString("SQLHistoryItemWrapper.sql"), };
24: private static final SimpleDateFormat LAST_USAGE_DATE_FORMAT = new SimpleDateFormat(
25: "yyyy-MM-dd HH:mm:ss:SSS");
26:
27: public static ArrayList<SQLHistoryItemWrapper> wrap(
28: ArrayList<SQLHistoryItem> items) {
29: ArrayList<SQLHistoryItemWrapper> ret = new ArrayList<SQLHistoryItemWrapper>(
30: items.size());
31:
32: int i = 0;
33: for (SQLHistoryItem item : items) {
34: ret.add(new SQLHistoryItemWrapper(item, ++i));
35: }
36:
37: Collections.reverse(ret);
38:
39: return ret;
40: }
41:
42: public static String[] getColumns() {
43: return COLUMNS;
44: }
45:
46: public static int getSQLColIx() {
47: return 2;
48: }
49:
50: private SQLHistoryItem _item;
51: private int _index;
52: private String _upperCaseSQL;
53: private String _lastUsageTimeString;
54:
55: public SQLHistoryItemWrapper(SQLHistoryItem item, int index) {
56: _item = item;
57: _index = index;
58: _upperCaseSQL = item.getSQL().toUpperCase();
59:
60: if (null != _item.getLastUsageTime()) {
61: _lastUsageTimeString = LAST_USAGE_DATE_FORMAT.format(_item
62: .getLastUsageTime());
63: }
64: }
65:
66: public Object getColum(int column) {
67: // corresponding to COLUMNS
68: switch (column) {
69: case 0:
70: return _index;
71: case 1:
72: return _lastUsageTimeString;
73: case 2:
74: return _item.getSQL();
75: default:
76: throw new IllegalArgumentException("Unknown colum index "
77: + column);
78:
79: }
80: }
81:
82: public String getUpperCaseSQL() {
83: return _upperCaseSQL;
84: }
85: }
|