AbstractVLVIndexPanel.java revision 656ab2dd56a9464df6e907d75ca1e40c927e945f
/*
* 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 2014-2015 ForgeRock AS
*/
/**
* Abstract class used to re-factor some code between the classes that are used
*/
abstract class AbstractVLVIndexPanel extends StatusGenericPanel
{
private static final long serialVersionUID = -82857384664911898L;
/** Title panel. */
protected final TitlePanel titlePanel = new TitlePanel(LocalizableMessage.EMPTY, LocalizableMessage.EMPTY);
/** Name label. */
private final JLabel lName = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_VLV_INDEX_NAME_LABEL.get());
/** Base DN label. */
private final JLabel lBaseDN = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_VLV_INDEX_BASE_DN_LABEL.get());
/** Search scope label. */
private final JLabel lSearchScope = createPrimaryLabel(INFO_CTRL_PANEL_VLV_INDEX_SEARCH_SCOPE_LABEL.get());
/** Search filter label. */
private final JLabel lFilter = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_VLV_INDEX_FILTER_LABEL.get());
/** Sort order label. */
private final JLabel lSortOrder = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_VLV_INDEX_SORT_ORDER_LABEL.get());
/** Backends label. */
/** Max block size label. */
private final JLabel lMaxBlockSize = createPrimaryLabel(INFO_CTRL_PANEL_VLV_INDEX_MAX_BLOCK_SIZE_LABEL.get());
/** Read-only name label. */
/** Read-only backend name label. */
/** Name text field. */
/** Base DNs combo box. */
/** Subtree text field. */
/** Base Object scope radio button. */
protected final JRadioButton baseObject = createRadioButton(INFO_CTRL_PANEL_VLV_INDEX_BASE_OBJECT_LABEL.get());
/** Single Level scope radio button. */
protected final JRadioButton singleLevel = createRadioButton(INFO_CTRL_PANEL_VLV_INDEX_SINGLE_LEVEL_LABEL.get());
/** Subordinate subtree scope radio button. */
/** Whole subtree scope radio button. */
/** Filter text field. */
/** Max block size text field. */
/** Attributes combo box. */
/** The list containing the sort order elements. */
/** The add button. */
private final JButton add = Utilities.createButton(INFO_CTRL_PANEL_VLV_INDEX_ADD_BUTTON_LABEL.get());
/** The move up button. */
private final JButton moveUp = Utilities.createButton(INFO_CTRL_PANEL_VLV_INDEX_MOVE_UP_BUTTON_LABEL.get());
/** The move down button. */
private final JButton moveDown = Utilities.createButton(INFO_CTRL_PANEL_VLV_INDEX_MOVE_DOWN_BUTTON_LABEL.get());
/** The remove button. */
protected final JButton remove = Utilities.createButton(INFO_CTRL_PANEL_VLV_INDEX_REMOVE_BUTTON_LABEL.get());
/** Ascending order combo box. */
/** Combo box containing the sort order. */
protected DefaultListModel sortOrderModel;
/** The list of labels. */
private final JLabel[] labels = { lName, lBaseDN, lSearchScope, lFilter, lSortOrder, lBackend, lMaxBlockSize };
/**
* The relative component that must be used to center the parent dialog of
* this panel.
*/
private final Component relativeComponent;
/** Other base DN message. */
/** Ascending message. */
/** Descending message. */
/** Custom attributes message. */
/** Standard attributes message. */
private final LocalizableMessage STANDARD_ATTRIBUTES = INFO_CTRL_PANEL_STANDARD_ATTRIBUTES_LABEL.get();
/** The list of standard attribute names. */
/** The list of configuration attribute names. */
private final TreeSet<String> configurationAttrNames = new TreeSet<String>(new LowerCaseComparator());
/** The list of custom attribute names. */
private final int defaultVLVEntryLimitValue;
{
}
/** Minimum value for max block size. */
private final int MIN_MAX_BLOCK_SIZE = LocalDBVLVIndexCfgDefn.getInstance().getMaxBlockSizePropertyDefinition()
.getLowerLimit();
/** Maximum value for max block size. */
private final int MAX_MAX_BLOCK_SIZE = 2147483647;
/** Default value for max block size. */
private final int DEFAULT_MAX_BLOCK_SIZE = defaultVLVEntryLimitValue;
/**
* Constructor.
*
* @param backendID
* the backend ID where the index is defined (or will be defined).
* @param relativeComponent
* the relative component where the dialog containing this panel must
* be centered.
*/
{
{
}
this.relativeComponent = relativeComponent;
}
/**
* Sets the name of the backend where the index is defined or will be defined.
*
* @param backendID
* the ID of the backend.
*/
{
}
/**
* Returns the LDIF representing the new index.
*
* @param indexName
* the name of the index.
* @return the LDIF representing the new index.
*/
{
final String dn = Utilities.getRDNString("ds-cfg-backend-id", backendName.getText()) + ",cn=Backends,cn=config";
{
}
}
/**
* Returns the scope of the VLV index as it appears on the panel.
*
* @return the scope of the VLV index as it appears on the panel.
*/
{
if (baseObject.isSelected())
{
}
else if (singleLevel.isSelected())
{
}
else if (subordinateSubtree.isSelected())
{
}
else
{
}
return scope;
}
/**
* Returns the list of VLV sort order elements as they are displayed in the
* panel.
*
* @return the list of VLV sort order elements as they are displayed in the
* panel.
*/
{
{
}
return sortOrder;
}
/**
* Returns the string representation for the provided list of VLV sort order.
*
* @param sortOrder
* the list of VLV sort order elements.
* @return the string representation for the provided list of VLV sort order.
*/
{
for (VLVSortOrder s : sortOrder)
{
{
}
if (s.isAscending())
{
}
else
{
}
}
}
/**
* Updates the layout with the provided server descriptor.
*
* @param desc
* the server descriptor.
* @return <CODE>true</CODE> if an error has been displayed and
* <CODE>false</CODE> otherwise.
*/
{
final boolean[] repack = { false };
final boolean[] error = { false };
{
}
{
LinkedHashSet<CategorizedComboBoxElement> newElements = new LinkedHashSet<CategorizedComboBoxElement>();
synchronized (standardAttrNames)
{
{
{
{
}
{
}
else
{
}
}
}
}
{
newElements.add(new CategorizedComboBoxElement(CUSTOM_ATTRIBUTES, CategorizedComboBoxElement.Type.CATEGORY));
{
}
}
{
newElements.add(new CategorizedComboBoxElement(STANDARD_ATTRIBUTES, CategorizedComboBoxElement.Type.CATEGORY));
{
}
}
}
else
{
updateErrorPane(errorPane, ERR_CTRL_PANEL_SCHEMA_NOT_FOUND_SUMMARY.get(), ColorAndFontConstants.errorTitleFont,
repack[0] = true;
error[0] = true;
}
{
public void run()
{
{
}
if (repack[0])
{
if (relativeComponent != null)
{
Utilities.centerGoldenMean(Utilities.getParentDialog(AbstractVLVIndexPanel.this), relativeComponent);
}
}
}
});
return !error[0];
}
{
{
{
return true;
}
}
return false;
}
/**
* Returns <CODE>true</CODE> if the user accepts to continue creating the VLV
* index even if no indexes are created for the provided filter for the VLV
* index. Returns <CODE>false</CODE> if the user does not accept to create the
* index. Note that the confirmation dialog will only be displayed when the
* indexes are not defined, if the dialog is not displayed the method returns
* <CODE>true</CODE>.
*
* @return <CODE>true</CODE> if the user accepts to continue creating the VLV
* index even if no indexes are created for the provided filter for
* the VLV index. Returns <CODE>false</CODE> if the user does not
* accept to create the index.
*/
protected boolean checkIndexRequired()
{
try
{
{
{
}
}
return true;
}
catch (Throwable t)
{
// Bug
throw new RuntimeException("Unexpected error: " + t, t);
}
}
/**
* Updates the provided list of error messages by analyzing the provided
* filter. The idea is basically to analyze the filter and check if what
* appears on the filter is indexed or not. If it is not indexed it updates
* the error message list with a message explaining that.
*
* @param filter
* the filter to analyze.
* @param msgs
* the list of messages to be updated.
*/
{
switch (filter.getFilterType())
{
case AND:
case OR:
{
{
}
}
break;
case NOT:
break;
default:
IndexType[] indexTypes =
INFO_CTRL_PANEL_VLV_INDEX_PRESENCE_TYPE.get(), INFO_CTRL_PANEL_VLV_INDEX_APPROXIMATE_TYPE.get(), null };
{
{
{
{
indexTypeNames[i]));
}
}
else
{
{
}
else
{
}
}
}
}
}
}
/**
* Returns the index descriptor for a given index name (<CODE>null</CODE> if
* no index descriptor is found for that name).
*
* @param indexName
* the name of the index.
* @return the index descriptor for a given index name.
*/
{
{
{
{
return i;
}
}
}
return null;
}
/**
* Updates the base DN combo box with the provided backend.
*
* @param backend
* the backend to be used with the provided backend.
*/
{
{
try
{
}
catch (Throwable t)
{
throw new RuntimeException("Unexpected error: " + t, t);
}
}
}
/**
* Updates a list of errors with the errors found in the panel.
*
* @param checkName
* whether the name of the VLV index must be checked or not.
* @return a list containing the error messages found.
*/
{
{
setPrimaryValid(l);
}
if (checkName)
{
{
}
{
// Check that there is no other VLV index with same name
{
{
break;
}
}
}
}
{
}
else
{
try
{
}
catch (OpenDsException oe)
{
}
}
if ("".equals(f))
{
}
else
{
try
{
LDAPFilter.decode(f);
}
catch (LDAPException le)
{
}
}
{
}
try
{
if (n < MIN_MAX_BLOCK_SIZE || n > MAX_MAX_BLOCK_SIZE)
{
errors.add(ERR_CTRL_PANEL_INVALID_MAX_BLOCK_SIZE_FOR_VLV_PROVIDED.get(MIN_MAX_BLOCK_SIZE, MAX_MAX_BLOCK_SIZE));
}
}
catch (Throwable t)
{
errors.add(ERR_CTRL_PANEL_INVALID_MAX_BLOCK_SIZE_FOR_VLV_PROVIDED.get(MIN_MAX_BLOCK_SIZE, MAX_MAX_BLOCK_SIZE));
}
return errors;
}
/**
* Returns the backend for the index.
*
* @return the backend for the index.
*/
private BackendDescriptor getBackend()
{
{
{
return b;
}
}
return null;
}
/**
* Returns the base DN for the VLV index.
*
* @return the base DN for the VLV index.
*/
{
{
}
}
/**
* Returns the selected attribute.
*
* @return the selected attribute.
*/
private String getSelectedAttribute()
{
}
/**
* Creates the basic layout of the panel.
*
* @param c
* the container of the layout.
* @param gbc
* the grid bag constraints to be used.
* @param nameReadOnly
* whether the panel is read-only or not.
*/
{
addErrorPane(c, gbc);
if (nameReadOnly)
{
}
if (nameReadOnly)
{
}
else
{
p.setOpaque(false);
}
p.setOpaque(false);
DefaultComboBoxModel model = new DefaultComboBoxModel(new Object[] { COMBO_SEPARATOR, OTHER_BASE_DN });
{
{
}
});
JLabel inlineHelp = Utilities.createInlineHelpLabel(INFO_CTRL_PANEL_SUBTREE_INLINE_HELP_LABEL.get());
singleLevel.setSelected(true);
{
}
{
{
{
remove.setEnabled(true);
}
else
{
moveUp.setEnabled(false);
moveUp.setEnabled(false);
remove.setEnabled(false);
}
}
};
{
button.setEnabled(false);
}
{
{
{
int i = attributes.getSelectedIndex();
if (i > 0)
{
// To avoid issues, try to figure out first the new selection
int newIndex = -1;
{
{
newIndex = j;
}
}
if (newIndex == -1)
{
{
{
newIndex = j;
}
}
}
if (newIndex != -1)
{
}
model.removeElementAt(i);
}
}
}
});
{
{
{
}
}
});
{
{
{
}
}
});
{
{
synchronized (standardAttrNames)
{
{
boolean dealingWithCustom = true;
{
{
{
break;
}
}
{
dealingWithCustom = false;
if (isCustom)
{
break;
}
}
}
}
}
{
}
}
});
sortOrderModel = new DefaultListModel();
Dimension d =
}
}