File Source: ErrorTableModel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.error.ErrorTableModel__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.addons.ui_swing.dialogs.error;
    24  
    25  import com.dmdirc.addons.ui_swing.UIUtilities;
    26  import com.dmdirc.logger.ErrorLevel;
    27  import com.dmdirc.logger.ErrorListener;
    28  import com.dmdirc.logger.ErrorManager;
    29  import com.dmdirc.logger.ErrorReportStatus;
    30  import com.dmdirc.logger.ProgramError;
    31  
    32  import java.util.Date;
    33  import java.util.List;
    34  
    35  import javax.swing.table.AbstractTableModel;
    36  
    37  /**
    38   * Table model for displaying program errors.
    39   */
    40  public final class ErrorTableModel extends AbstractTableModel implements
    41          ErrorListener {
    42  
    43      /**
    44       * A version number for this class. It should be changed whenever the class
    45       * structure is changed (or anything else that would prevent serialized
    46       * objects being unserialized with the new class).
    47       */
    48      private static final long serialVersionUID = 1;
    49      /** Data list. */
    50      private final List<ProgramError> errors;
    51  
    52      /** Creates a new instance of ErrorTableModel. */
    53      public ErrorTableModel() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.error.ErrorTableModel()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.logger.ErrorManager:getErrorManager(...)@54 != null
                  * 
                  *  Postconditions:
                  *    init'ed(this.errors)
                  */
    54          this(ErrorManager.getErrorManager().getErrors());
    55      }
    56  
    57      /** 
    58       * Creates a new instance of ErrorTableModel. 
    59       *
    60       * @param errors List of errors.
    61       */
    62      public ErrorTableModel(final List<ProgramError> errors) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.error.ErrorTableModel(List)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.logger.ErrorManager:getErrorManager(...)@67 != null
                  * 
                  *  Postconditions:
                  *    this.errors == errors
                  *    init'ed(this.errors)
                  */
    63          super();
    64  
    65          this.errors = errors;
    66  
    67          ErrorManager.getErrorManager().addErrorListener(this);
    68      }
    69  
    70      /**
    71       * Sets the list of errors.
    72       *
    73       * @param errors List of errors
    74       */
    75      public void setErrors(final List<ProgramError> errors) {
                 /* 
    P/P           *  Method: void setErrors(List)
                  * 
                  *  Preconditions:
                  *    this.errors != null
                  */
    76          this.errors.clear();
    77          this.errors.addAll(errors);
    78  
    79          fireTableDataChanged();
    80      }
    81  
    82      /** {@inheritDoc} */
    83      @Override
    84      public int getRowCount() {
                 /* 
    P/P           *  Method: int getRowCount()
                  * 
                  *  Preconditions:
                  *    this.errors != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    85          synchronized (errors) {
    86              return errors.size();
    87          }
    88      }
    89  
    90      /** {@inheritDoc} */
    91      @Override
    92      public int getColumnCount() {
                 /* 
    P/P           *  Method: int getColumnCount()
                  * 
                  *  Postconditions:
                  *    return_value == 5
                  */
    93          return 5;
    94      }
    95  
    96      /** {@inheritDoc} */
    97      @Override
    98      public String getColumnName(final int columnIndex) {
                 /* 
    P/P           *  Method: String getColumnName(int)
                  * 
                  *  Preconditions:
                  *    columnIndex in {0..4}
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{&amp;"ID",&amp;"Time",&amp;"Severity",&amp;"Report Status",&amp;"Message"}
                  * 
                  *  Test Vectors:
                  *    columnIndex: {0}, {1}, {2}, {3}, {4}
                  */
    99          switch (columnIndex) {
   100              case 0:
   101                  return "ID";
   102              case 1:
   103                  return "Time";
   104              case 2:
   105                  return "Severity";
   106              case 3:
   107                  return "Report Status";
   108              case 4:
   109                  return "Message";
   110              default:
   111                  throw new IndexOutOfBoundsException(columnIndex + ">= 5");
   112          }
   113      }
   114  
   115      /** {@inheritDoc} */
   116      @Override
   117      public Class<?> getColumnClass(final int columnIndex) {
                 /* 
    P/P           *  Method: Class getColumnClass(int)
                  * 
                  *  Preconditions:
                  *    columnIndex in {0..4}
                  * 
                  *  Test Vectors:
                  *    columnIndex: {0}, {1}, {2}, {3}, {4}
                  */
   118          switch (columnIndex) {
   119              case 0:
   120                  return Integer.class;
   121              case 1:
   122                  return Date.class;
   123              case 2:
   124                  return ErrorLevel.class;
   125              case 3:
   126                  return ErrorReportStatus.class;
   127              case 4:
   128                  return String.class;
   129              default:
   130                  throw new IndexOutOfBoundsException(columnIndex + ">= 5");
   131          }
   132      }
   133  
   134      /** {@inheritDoc} */
   135      @Override
   136      public boolean isCellEditable(final int rowIndex, final int columnIndex) {
                 /* 
    P/P           *  Method: bool isCellEditable(int, int)
                  * 
                  *  Postconditions:
                  *    return_value == 0
                  */
   137          return false;
   138      }
   139  
   140      /** {@inheritDoc} */
   141      @Override
   142      public Object getValueAt(final int rowIndex, final int columnIndex) {
                 /* 
    P/P           *  Method: Object getValueAt(int, int)
                  * 
                  *  Preconditions:
                  *    columnIndex in {0..4}
                  *    this.errors != null
                  * 
                  *  Presumptions:
                  *    java.util.List:get(...)@146 != null
                  *    java.util.List:get(...)@148 != null
                  *    java.util.List:get(...)@150 != null
                  *    java.util.List:get(...)@152 != null
                  *    java.util.List:get(...)@154 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    columnIndex: {0}, {1}, {2}, {3}, {4}
                  */
   143          synchronized (errors) {
   144              switch (columnIndex) {
   145                  case 0:
   146                      return errors.get(rowIndex).getID();
   147                  case 1:
   148                      return errors.get(rowIndex).getDate();
   149                  case 2:
   150                      return errors.get(rowIndex).getLevel();
   151                  case 3:
   152                      return errors.get(rowIndex).getReportStatus();
   153                  case 4:
   154                      return errors.get(rowIndex).getMessage();
   155                  default:
   156                      throw new IndexOutOfBoundsException(columnIndex + ">= 5");
   157              }
   158          }
   159      }
   160  
   161      /** {@inheritDoc} */
   162      @Override
   163      public void setValueAt(final Object aValue, final int rowIndex,
   164              final int columnIndex) {
                 /* 
    P/P           *  Method: void setValueAt(Object, int, int)
                  * 
                  *  Preconditions:
                  *    columnIndex == 3
                  *    this.errors != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.logger.ErrorReportStatus:instanceof(...)@168 == 1
                  *    java.util.List:get(...)@169 != null
                  */
   165          synchronized (errors) {
   166              switch (columnIndex) {
   167                  case 3:
   168                      if (aValue instanceof ErrorReportStatus) {
   169                          errors.get(rowIndex).setReportStatus(
   170                                  (ErrorReportStatus) aValue);
   171                          break;
   172                      } else {
   173                          throw new IllegalArgumentException("Received: " +
   174                                  aValue.getClass() + ", expecting: " +
   175                                  ErrorReportStatus.class);
   176                      }
   177                  default:
   178                      throw new UnsupportedOperationException("Only editing the " +
   179                              "status is allowed");
   180              }
   181              fireTableCellUpdated(rowIndex, columnIndex);
   182          }
   183      }
   184  
   185      /**
   186       * Gets the error at the specified row.
   187       *
   188       * @param rowIndex Row to retrieve
   189       *
   190       * @return Specified error
   191       */
   192      public ProgramError getError(final int rowIndex) {
                 /* 
    P/P           *  Method: ProgramError getError(int)
                  * 
                  *  Preconditions:
                  *    this.errors != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   193          synchronized (errors) {
   194              return errors.get(rowIndex);
   195          }
   196      }
   197  
   198      /**
   199       * Returns the index of the specified error or -1 if the error is not found.
   200       *
   201       * @param error ProgramError to locate
   202       *
   203       * @return Error index or -1 if not found
   204       */
   205      public int indexOf(final ProgramError error) {
                 /* 
    P/P           *  Method: int indexOf(ProgramError)
                  * 
                  *  Preconditions:
                  *    this.errors != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   206          synchronized (errors) {
   207              return errors.indexOf(error);
   208          }
   209      }
   210  
   211      /**
   212       * Adds an error to the list.
   213       *
   214       * @param error ProgramError to add
   215       */
   216      public void addRow(final ProgramError error) {
                 /* 
    P/P           *  Method: void addRow(ProgramError)
                  * 
                  *  Preconditions:
                  *    this.errors != null
                  */
   217          synchronized (errors) {
   218              errors.add(error);
   219              fireTableRowsInserted(errors.indexOf(error), errors.indexOf(error));
   220          }
   221      }
   222  
   223      /**
   224       * Removes a specified row from the list.
   225       *
   226       * @param row Row to remove
   227       */
   228      public void removeRow(final int row) {
                 /* 
    P/P           *  Method: void removeRow(int)
                  * 
                  *  Preconditions:
                  *    this.errors != null
                  */
   229          synchronized (errors) {
   230              errors.remove(row);
   231              fireTableRowsDeleted(row, row);
   232          }
   233      }
   234  
   235      /**
   236       * Removes a specified error from the list.
   237       *
   238       * @param error ProgramError to remove
   239       */
   240      public void removeRow(final ProgramError error) {
                 /* 
    P/P           *  Method: void removeRow(ProgramError)
                  * 
                  *  Preconditions:
                  *    this.errors != null
                  */
   241          synchronized (errors) {
   242              if (errors.contains(error)) {
   243                  final int row = errors.indexOf(error);
   244                  errors.remove(row);
   245                  fireTableRowsDeleted(row, row);
   246              }
   247          }
   248      }
   249  
   250      /** {@inheritDoc} */
   251      @Override
   252      public void errorAdded(final ProgramError error) {
                 /* 
    P/P           *  Method: void errorAdded(ProgramError)
                  */
   253          UIUtilities.invokeLater(new Runnable() {
   254  
   255              /** {@inheritDoc} */
   256              @Override
   257              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.errors != null
                          */
   258                  synchronized (ErrorTableModel.this) {
   259                      addRow(error);
   260                  }
   261              }
   262          });
   263      }
   264  
   265      /** {@inheritDoc} */
   266      @Override
   267      public void errorDeleted(final ProgramError error) {
                 /* 
    P/P           *  Method: void errorDeleted(ProgramError)
                  */
   268          UIUtilities.invokeLater(new Runnable() {
   269  
   270              /** {@inheritDoc} */
   271              @Override
   272              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.errors != null
                          */
   273                  synchronized (ErrorTableModel.this) {
   274                      removeRow(error);
   275                  }
   276              }
   277          });
   278      }
   279  
   280      /** {@inheritDoc} */
   281      @Override
   282      public void errorStatusChanged(final ProgramError error) {
                 /* 
    P/P           *  Method: void errorStatusChanged(ProgramError)
                  */
   283          UIUtilities.invokeLater(new Runnable() {
   284  
   285              /** {@inheritDoc} */
   286              @Override
   287              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.errors != null
                          */
   288                  synchronized (ErrorTableModel.this) {
   289                      final int errorRow = indexOf(error);
   290                      if (errorRow != -1 && errorRow < getRowCount()) {
   291                          fireTableRowsUpdated(errorRow, errorRow);
   292                      }
   293                  }
   294              }
   295          });
   296      }
   297  
   298      /** {@inheritDoc} */
   299      @Override
   300      public boolean isReady() {
                 /* 
    P/P           *  Method: bool isReady()
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  */
   301          return true;
   302      }
   303  }








SofCheck Inspector Build Version : 2.17854
ErrorTableModel.java 2009-Jun-25 01:54:24
ErrorTableModel.class 2009-Sep-02 17:04:14
ErrorTableModel$1.class 2009-Sep-02 17:04:14
ErrorTableModel$2.class 2009-Sep-02 17:04:14
ErrorTableModel$3.class 2009-Sep-02 17:04:14