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-2016 ForgeRock AS. 016 */ 017 018package org.opends.guitools.controlpanel.datamodel; 019 020import java.util.ArrayList; 021 022import javax.swing.table.AbstractTableModel; 023 024/** The table used to display the backups. */ 025public class BackupTableModel extends AbstractTableModel 026{ 027 private static final long serialVersionUID = -3511425157550147124L; 028 private ArrayList<BackupDescriptor> backups = new ArrayList<>(); 029 030 /** Clears the contents of the table model. */ 031 public void clear() 032 { 033 backups.clear(); 034 } 035 036 /** 037 * Adds a backup to the model. 038 * @param backup the backup to be added. 039 */ 040 public void add(BackupDescriptor backup) 041 { 042 backups.add(backup); 043 } 044 045 @Override 046 public Object getValueAt(int row, int column) 047 { 048 switch (column) 049 { 050 case 0: 051 return get(row).getID(); 052 case 1: 053 return get(row).getPath(); 054 case 2: 055 return get(row).getCreationDate(); 056 case 3: 057 return get(row).getType(); 058 default: 059 throw new IllegalArgumentException("Invalid column: "+column); 060 } 061 } 062 063 @Override 064 public int getRowCount() 065 { 066 return backups.size(); 067 } 068 069 @Override 070 public int getColumnCount() 071 { 072 return 4; 073 } 074 075 /** 076 * Gets the BackupDescriptor in a given row. 077 * @param row the row. 078 * @return the BackupDescriptor in a given row. 079 */ 080 public BackupDescriptor get(int row) 081 { 082 return backups.get(row); 083 } 084}