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