001: package org.osbl.client.wings.control;
002:
003: import org.wings.session.SessionManager;
004: import org.wings.SURLIcon;
005: import org.concern.*;
006: import org.wingx.table.RefreshableModel;
007:
008: import javax.swing.table.AbstractTableModel;
009: import java.text.*;
010: import java.util.*;
011:
012: /**
013: * @author hengels
014: * @version $Revision$
015: */
016: class LogTableModel extends AbstractTableModel implements
017: RefreshableModel {
018: DateFormat dateFormat = DateFormat.getDateTimeInstance(
019: DateFormat.SHORT, DateFormat.MEDIUM, SessionManager
020: .getSession().getLocale());
021: private List logs = new ArrayList();
022: private String[] columnNames = new String[] { "", "Timestamp",
023: "Activity", "Message", "Details", "Annotations", };
024:
025: private Controller controller;
026: private Subject subject;
027: private boolean archive;
028:
029: public LogTableModel() {
030: }
031:
032: public void clean() {
033: logs.clear();
034: }
035:
036: public void setController(Controller controller) {
037: this .controller = controller;
038: }
039:
040: public void setSubject(Subject subject) {
041: this .subject = subject;
042: }
043:
044: public void setArchive(boolean archive) {
045: this .archive = archive;
046: }
047:
048: public void refresh() {
049: if (controller == null || subject == null)
050: return;
051: try {
052: logs = archive ? controller.getArchive(subject
053: .getSubjectId()) : controller.getLog(subject
054: .getSubjectId());
055: } catch (UnknownSubjectException e) {
056: e.printStackTrace();
057: clean();
058: }
059: fireTableDataChanged();
060: }
061:
062: public int getColumnCount() {
063: return columnNames.length - 1;
064: }
065:
066: public String getColumnName(int column) {
067: return columnNames[column];
068: }
069:
070: public int getRowCount() {
071: return logs.size();
072: }
073:
074: Log getRow(int row) {
075: return (Log) logs.get(row);
076: }
077:
078: public Object getValueAt(int rowIndex, int columnIndex) {
079: Log log = (Log) logs.get(rowIndex);
080:
081: switch (columnIndex) {
082: case 0:
083: return new SURLIcon(
084: log.isSuccess() ? "../icon/16x16/success.png"
085: : "../icon/16x16/failure.png", 16, 16);
086: case 1:
087: return dateFormat.format(log.getTimestamp());
088: case 2:
089: return log.getActivity();
090: case 3:
091: return log.getMessage();
092: case 4:
093: return log.getDetails();
094: case 5:
095: try {
096: return log.getAnnotations();
097: } catch (Exception e) {
098: // TODO: eager load on refresh
099: }
100: }
101: return "?";
102: }
103: }
|