MonitoringAttributesViewPanel.java revision 8a8a81b8bac1333b0eeae6f07ca58741ab063722
/*
* 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 2009-2010 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* The panel that allows the user to select which attributes must be displayed
* in the traffic monitoring tables.
*
* @param <T> the type of the objects that this panel manages. For now it only
* manages String and MonitoringAttribute objects.
*/
public class MonitoringAttributesViewPanel<T> extends StatusGenericPanel
{
private static final long serialVersionUID = 6462932163745559L;
private LinkedHashSet<T> monitoringAttributes;
private boolean isCanceled = true;
/**
* Note: the order of the checkboxes and the elements in the Attributes
* enumeration will be the same.
*/
private JCheckBox[] checkboxes = {};
private JButton selectNone;
/**
* Creates an instance of this panel that uses String as attributes.
* @param attributes the list of possible attributes.
* @return an instance of this panel that uses String as attributes.
*/
public static MonitoringAttributesViewPanel<String> createStringInstance(LinkedHashSet<String> attributes)
{
return new MonitoringAttributesViewPanel<>(attributes);
}
/**
* Creates an instance of this panel that uses MonitoringAttributes as
* attributes.
* @param attributes the list of possible attributes.
* @return an instance of this panel that uses MonitoringAttributes as
* attributes.
*/
public static MonitoringAttributesViewPanel<MonitoringAttributes>
{
return new MonitoringAttributesViewPanel<>(attributes);
}
/**
* Creates an instance of this panel that uses LocalizableMessage as
* attributes.
* @param attributes the list of possible attributes.
* @return an instance of this panel that uses LocalizableMessage as attributes.
*/
public static MonitoringAttributesViewPanel<LocalizableMessage>
{
return new MonitoringAttributesViewPanel<>(attributes);
}
/** {@inheritDoc} */
public boolean requiresScroll()
{
return false;
}
/**
* Default constructor.
* @param attributes the attributes that will be proposed to the user.
*
*/
{
createLayout();
}
/**
* Sets the attributes that must be selected in this dialog.
* @param selectedAttributes the selected attributes.
*/
public void setSelectedAttributes(
{
int i = 0;
for (T attribute : monitoringAttributes)
{
i++;
}
}
/**
* Creates the layout of the panel (but the contents are not populated here).
*/
private void createLayout()
{
checkBoxPanel.setOpaque(false);
int i = 0;
for (T attribute : monitoringAttributes)
{
i++;
}
{
{
{
cb.setSelected(true);
}
}
});
{
{
{
cb.setSelected(false);
}
}
});
gbc = new GridBagConstraints();
int preferredViewHeight = -1;
{
{
}
}
if (preferredViewHeight < 0)
{
}
}
/** {@inheritDoc} */
public LocalizableMessage getTitle()
{
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
public Component getPreferredFocusComponent()
{
return checkboxes[0];
}
/** {@inheritDoc} */
public void toBeDisplayed(boolean visible)
{
if (visible)
{
isCanceled = true;
}
}
/** {@inheritDoc} */
public void okClicked()
{
// Check that at least one checkbox is selected.
int i = 0;
for (T attribute : monitoringAttributes)
{
if (checkboxes[i].isSelected())
{
}
i++;
}
if (selectedAttributes.isEmpty())
{
}
else
{
isCanceled = false;
super.closeClicked();
}
}
/** {@inheritDoc} */
{
}
/**
* Returns <CODE>true</CODE> if the user closed the dialog by cancelling it
* and <CODE>false</CODE> otherwise.
* @return <CODE>true</CODE> if the user closed the dialog by cancelling it
* and <CODE>false</CODE> otherwise.
*/
public boolean isCanceled()
{
return isCanceled;
}
/**
* Returns the list of attributes that the user selected.
* @return the list of attributes that the user selected.
*/
public LinkedHashSet<T> getAttributes()
{
return selectedAttributes;
}
/**
* Returns the message for the provided attribute.
* @param attribute the attribute.
* @return the message for the provided attribute.
*/
{
if (attribute instanceof MonitoringAttributes)
{
}
else if (attribute instanceof LocalizableMessage)
{
m = (LocalizableMessage)attribute;
}
else
{
}
return m;
}
}