aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui/widgets/LogTableModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/ui/widgets/LogTableModel.java')
-rw-r--r--src/main/ui/widgets/LogTableModel.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/main/ui/widgets/LogTableModel.java b/src/main/ui/widgets/LogTableModel.java
new file mode 100644
index 0000000..dc7dcbd
--- /dev/null
+++ b/src/main/ui/widgets/LogTableModel.java
@@ -0,0 +1,79 @@
+package ui.widgets;
+
+import model.ca.AuditLogEntry;
+import model.ca.CertificationAuthority;
+
+import javax.swing.table.AbstractTableModel;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * Table model that displays audit logs.
+ */
+public class LogTableModel extends AbstractTableModel {
+ /**
+ * Columns
+ */
+ private static final String[] COLS = new String[] {
+ "Time",
+ "Operator",
+ "Action"
+ };
+
+ /**
+ * Pointer to the {@link CertificationAuthority#getLogs()}.
+ */
+ private List<AuditLogEntry> ptrData;
+
+ /**
+ * EFFECTS: Set the pointer to templates
+ * MODIFIES: this
+ */
+ public void setPtrData(List<AuditLogEntry> ptrData) {
+ this.ptrData = ptrData;
+ }
+
+ /**
+ * EFFECT: Return number of rows.
+ */
+ @Override
+ public int getRowCount() {
+ return ptrData == null ? 0 : ptrData.size();
+ }
+
+ /**
+ * EFFECT: Return number of columns.
+ */
+ @Override
+ public int getColumnCount() {
+ return COLS.length;
+ }
+
+ /**
+ * EFFECTS: Get column name.
+ * REQUIRES: column in [9, getColumnCount())
+ */
+ @Override
+ public String getColumnName(int column) {
+ return COLS[column];
+ }
+
+ /**
+ * EFFECTS: Return the value for a cell:
+ * String (Time)
+ * String (Operator)
+ * String (Action)
+ * Throws {@link IllegalArgumentException} if columnIndex is not in 0 ~ 2
+ * REQUIRES: rowIndex must in range.
+ */
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ final AuditLogEntry e = ptrData.get(rowIndex);
+ switch (columnIndex) {
+ case 0: return e.getTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
+ case 1: return e.getUser();
+ case 2: return e.getAction();
+ default: throw new IllegalArgumentException();
+ }
+ }
+}