001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2015 ForgeRock AS.
026 */
027
028package org.opends.guitools.controlpanel.datamodel;
029
030import java.util.ArrayList;
031
032import javax.swing.table.AbstractTableModel;
033
034/**
035 * The table used to display the backups.
036 *
037 */
038public class BackupTableModel extends AbstractTableModel
039{
040  private static final long serialVersionUID = -3511425157550147124L;
041  private ArrayList<BackupDescriptor> backups = new ArrayList<>();
042
043  /** Clears the contents of the table model. */
044  public void clear()
045  {
046    backups.clear();
047  }
048
049  /**
050   * Adds a backup to the model.
051   * @param backup the backup to be added.
052   */
053  public void add(BackupDescriptor backup)
054  {
055    backups.add(backup);
056  }
057
058  /** {@inheritDoc} */
059  public Object getValueAt(int row, int column)
060  {
061    switch (column)
062    {
063    case 0:
064      return get(row).getID();
065    case 1:
066      return get(row).getPath();
067    case 2:
068      return get(row).getCreationDate();
069    case 3:
070      return get(row).getType();
071      default:
072        throw new IllegalArgumentException("Invalid column: "+column);
073    }
074  }
075
076  /**
077   * Returns the row count.
078   * @return the row count.
079   */
080  public int getRowCount()
081  {
082    return backups.size();
083  }
084
085  /**
086   * Returns the column count.
087   * @return the column count.
088   */
089  public int getColumnCount()
090  {
091    return 4;
092  }
093
094  /**
095   * Gets the BackupDescriptor in a given row.
096   * @param row the row.
097   * @return the BackupDescriptor in a given row.
098   */
099  public BackupDescriptor get(int row)
100  {
101    return backups.get(row);
102  }
103}