Coverage Report - org.jtheque.core.managers.view.impl.components.model.EventsTableModel
 
Classes in this File Line Coverage Branch Coverage Complexity
EventsTableModel
0 %
0/29
0 %
0/12
2.556
EventsTableModel$Columns
N/A
N/A
2.556
 
 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  
  * This file is part of JTheque.
 17  
  *
 18  
  * JTheque is free software: you can redistribute it and/or modify
 19  
  * it under the terms of the GNU General Public License as published by
 20  
  * the Free Software Foundation, either version 3 of the License.
 21  
  *
 22  
  * JTheque is distributed in the hope that it will be useful,
 23  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 24  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 25  
  * GNU General Public License for more details.
 26  
  *
 27  
  * You should have received a copy of the GNU General Public License
 28  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 29  
  */
 30  
 
 31  
 /**
 32  
  * A table model for the events.
 33  
  *
 34  
  * @author Baptiste Wicht
 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  
      * The different columns of the films to buy table.
 44  
      *
 45  
      * @author Baptiste Wicht
 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  
      * Headers of the table.
 57  
      */
 58  
     private String[] headers;
 59  
 
 60  
     /**
 61  
      * The films to buy to display.
 62  
      */
 63  
     private List<EventLog> events;
 64  
 
 65  
     /**
 66  
      * Construct a new <code>FilmsToBuyTableModel</code>.
 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  
      * Return the event log at the index.
 78  
      *
 79  
      * @param row The index of the event to get.
 80  
      * @return The event level at the position or null if there is no event at this position.
 81  
      */
 82  
     public EventLog getValueAt(int row) {
 83  0
         return events.get(row);
 84  
     }
 85  
 
 86  
     /**
 87  
      * Set the header of the table.
 88  
      *
 89  
      * @param headers The header of the table model
 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  
      * Set the event log to display.
 143  
      *
 144  
      * @param log The event log to display.
 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  
 }