| 1 | |
package org.jtheque.core.managers.view.impl.components.model; |
| 2 | |
|
| 3 | |
import org.jtheque.core.managers.Managers; |
| 4 | |
import org.jtheque.core.managers.beans.IBeansManager; |
| 5 | |
import org.jtheque.core.managers.event.EventLog; |
| 6 | |
import org.jtheque.core.managers.event.IEventManager; |
| 7 | |
import org.jtheque.core.managers.language.ILanguageManager; |
| 8 | |
|
| 9 | |
import javax.swing.table.AbstractTableModel; |
| 10 | |
import java.text.DateFormat; |
| 11 | |
import java.text.SimpleDateFormat; |
| 12 | |
import java.util.ArrayList; |
| 13 | |
import java.util.List; |
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public final class EventsTableModel extends AbstractTableModel { |
| 37 | 0 | private final DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Managers.getManager(ILanguageManager.class).getCurrentLocale()); |
| 38 | 0 | private final DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss,SSS", Managers.getManager(ILanguageManager.class).getCurrentLocale()); |
| 39 | |
|
| 40 | |
private String log; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
private interface Columns { |
| 48 | |
int LEVEL = 0; |
| 49 | |
int DATE = 1; |
| 50 | |
int TIME = 2; |
| 51 | |
int SOURCE = 3; |
| 52 | |
int TITLE = 4; |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
private String[] headers; |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
private List<EventLog> events; |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public EventsTableModel() { |
| 69 | 0 | super(); |
| 70 | |
|
| 71 | 0 | Managers.getManager(IBeansManager.class).inject(this); |
| 72 | |
|
| 73 | 0 | setLog(Managers.getManager(IEventManager.class).getLogs().iterator().next()); |
| 74 | 0 | } |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public EventLog getValueAt(int row) { |
| 83 | 0 | return events.get(row); |
| 84 | |
} |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
public void setHeaders(String[] headers) { |
| 92 | 0 | this.headers = headers.clone(); |
| 93 | |
|
| 94 | 0 | fireTableStructureChanged(); |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
@Override |
| 98 | |
public int getColumnCount() { |
| 99 | 0 | return headers.length; |
| 100 | |
} |
| 101 | |
|
| 102 | |
@Override |
| 103 | |
public int getRowCount() { |
| 104 | 0 | return events.size(); |
| 105 | |
} |
| 106 | |
|
| 107 | |
@Override |
| 108 | |
public Object getValueAt(int rowIndex, int columnIndex) { |
| 109 | 0 | EventLog eventLog = events.get(rowIndex); |
| 110 | |
|
| 111 | 0 | if (eventLog != null) { |
| 112 | 0 | switch (columnIndex) { |
| 113 | |
case Columns.LEVEL: |
| 114 | 0 | return Managers.getManager(ILanguageManager.class).getMessage(eventLog.getLevel().getKey()); |
| 115 | |
case Columns.DATE: |
| 116 | 0 | return dateFormat.format(eventLog.getDate()); |
| 117 | |
case Columns.TIME: |
| 118 | 0 | return timeFormat.format(eventLog.getDate()); |
| 119 | |
case Columns.SOURCE: |
| 120 | 0 | return eventLog.getSource(); |
| 121 | |
case Columns.TITLE: |
| 122 | 0 | return Managers.getManager(ILanguageManager.class).getMessage(eventLog.getTitleKey()); |
| 123 | |
default: |
| 124 | 0 | return ""; |
| 125 | |
} |
| 126 | |
} |
| 127 | |
|
| 128 | 0 | return ""; |
| 129 | |
} |
| 130 | |
|
| 131 | |
@Override |
| 132 | |
public String getColumnName(int column) { |
| 133 | 0 | return headers[column]; |
| 134 | |
} |
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public boolean isCellEditable(int row, int column) { |
| 138 | 0 | return false; |
| 139 | |
} |
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
public void setLog(String log) { |
| 147 | 0 | if (this.log == null || !this.log.equals(log)) { |
| 148 | 0 | events = new ArrayList<EventLog>(Managers.getManager(IEventManager.class).getEventLogs(log)); |
| 149 | |
|
| 150 | 0 | fireTableDataChanged(); |
| 151 | |
|
| 152 | 0 | this.log = log; |
| 153 | |
} |
| 154 | 0 | } |
| 155 | |
} |