BackupListPanel.java revision 4bf97a0d53caa31340e8ffdccba31cdc4cf02dbd
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/** Abstract class used to refactor code in panels that contain a backup list on it. */
public abstract class BackupListPanel extends StatusGenericPanel
{
private static final long serialVersionUID = -4804555239922795163L;
/** The refreshing list message, displayed when the list of backups is refreshed. */
protected static final LocalizableMessage REFRESHING_LIST = INFO_CTRL_PANEL_REFRESHING_LIST_SUMMARY.get();
/** The message informing that no backups where found. */
protected static final LocalizableMessage NO_BACKUPS_FOUND = INFO_CTRL_PANEL_NO_BACKUPS_FOUND.get();
/** The text field containing the parent directory. */
protected JTextField parentDirectory;
/** Label for the path field. */
/** Label for the list. */
protected JLabel lAvailableBackups;
/** Refreshing list label (displayed instead of the list when this one is being refreshed). */
protected JLabel lRefreshingList;
/** Refresh list button. */
protected JButton refreshList;
/** Verify backup button. */
protected JButton verifyBackup;
/** Browse button. */
/** The scroll that contains the list of backups (actually is a table). */
protected JScrollPane tableScroll;
/** The list of backups. */
protected JTable backupList;
private JLabel lRemoteFileHelp;
/** Whether the backup parent directory has been initialized with a value. */
private boolean backupDirectoryInitialized;
private BackupTableCellRenderer renderer;
/** Default constructor. */
protected BackupListPanel()
{
super();
}
public Component getPreferredFocusComponent()
{
return parentDirectory;
}
/**
* Returns the selected backup in the list.
*
* @return the selected backup in the list.
*/
protected BackupDescriptor getSelectedBackup()
{
if (row != -1)
{
}
return backup;
}
/**
* Notification that the verify button was clicked. Whatever is required to be
* done must be done in this method.
*/
protected abstract void verifyBackupClicked();
/**
* Creates the components and lays them in the panel.
*
* @param gbc
* the grid bag constraints to be used.
*/
{
new BrowseActionListener(parentDirectory, BrowseActionListener.BrowseType.LOCATION_DIRECTORY, this));
backupList = new JTable();
// Done to provide a good size to the table.
{
}
backupList.setShowGrid(false);
renderer = new BackupTableCellRenderer();
{
}
buttonPanel.setOpaque(false);
refreshList.setOpaque(false);
{
{
refreshList();
}
});
verifyBackup.setOpaque(false);
{
{
}
});
{
{
}
};
}
/**
* Refresh the list of backups by looking in the backups defined under the
* provided parent backup directory.
*/
protected void refreshList()
{
refreshList.setEnabled(false);
verifyBackup.setEnabled(false);
tableScroll.setVisible(false);
{
{
// Open the backup directory and make sure it is valid.
try
{
}
catch (Throwable t)
{
firstThrowable = t;
}
// Check the subdirectories
// Check the first level of directories (we might have done
// a backup of one backend and then a backup of several backends under the same directory).
if (f.isDirectory())
{
{
if (children[i].isDirectory())
{
try
{
}
{
{
}
}
}
}
}
{
throw firstThrowable;
}
return backups;
}
{
if (t == null)
{
}
else
{
performErrorActions(t, model);
}
{
}
{
}
}
{
if (!returnValue.isEmpty())
{
{
}
tableScroll.setVisible(true);
lRefreshingList.setVisible(false);
}
else
{
}
}
{
boolean displayError = true;
if (t instanceof OpenDsException)
{
OpenDsException e = (OpenDsException) t;
{
displayError = false;
}
}
if (displayError)
{
}
}
{
if (isSuccess)
{
// This is done to perform checks against whether we require to display an error message.
}
else
{
}
}
};
}
/**
* Creates a list with backup descriptor.
* This is done simply to have a good initial size for the table.
*
* @return a list with bogus backup descriptors.
*/
{
return list;
}
{
{
{
public void run()
{
refreshList();
backupDirectoryInitialized = true;
}
});
}
{
public void run()
{
}
});
}
{
{
try
{
return f.getCanonicalPath();
}
catch (Throwable t)
{
return f.getAbsolutePath();
}
}
else
{
}
}
public void toBeDisplayed(boolean visible)
{
if (visible && backupDirectoryInitialized)
{
refreshList();
}
}
}