IndexPanel.java revision 866cc640d33ce92abbd907d35d4c1b62f2328959
/*
* 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-2009 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* The panel that displays an existing index (it appears on the right of the
* 'Manage Indexes' dialog).
*/
public class IndexPanel extends AbstractIndexPanel
{
private static final long serialVersionUID = 1439500626486823366L;
private IndexDescriptor index;
private ScrollPaneBorderListener scrollListener;
private boolean ignoreCheckSave;
private ModifyIndexTask newModifyTask;
/**
* Default constructor.
*/
public IndexPanel()
{
super();
createLayout();
}
/**
* Creates the layout of the panel (but the contents are not populated here).
*/
private void createLayout()
{
p.setOpaque(false);
super.createBasicLayout(p, gbc, true);
gbc = new GridBagConstraints();
buttonPanel.setOpaque(false);
deleteIndex.setOpaque(false);
{
/** {@inheritDoc} */
{
deleteIndex();
}
});
saveChanges.setOpaque(false);
{
{
saveIndex(false);
}
});
{
{
}
{
}
{
}
});
{
{
}
};
{
}
}
/** {@inheritDoc} */
public LocalizableMessage getTitle()
{
return INFO_CTRL_PANEL_INDEX_PANEL_TITLE.get();
}
/** {@inheritDoc} */
public Component getPreferredFocusComponent()
{
return entryLimit;
}
/** {@inheritDoc} */
{
isLocal() ?
{
public void run()
{
}
});
}
/** {@inheritDoc} */
public void okClicked()
{
}
/**
* Method used to know if there are unsaved changes or not. It is used by the
* index selection listener when the user changes the selection.
*
* @return <CODE>true</CODE> if there are unsaved changes (and so the
* selection of the index should be canceled) and <CODE>false</CODE>
* otherwise.
*/
public boolean mustCheckUnsavedChanges()
{
}
/**
* Tells whether the user chose to save the changes in the panel, to not save
* them or simply cancelled the selection in the tree.
*
* @return the value telling whether the user chose to save the changes in the
* panel, to not save them or simply cancelled the selection change in
* the tree.
*/
{
UnsavedChangesDialog unsavedChangesDlg = new UnsavedChangesDialog(Utilities.getParentDialog(this), getInfo());
unsavedChangesDlg.setVisible(true);
{
saveIndex(false);
{
}
}
return result;
}
/** Checks the enabling state of the save button. */
private void checkSaveButton()
{
{
isModified());
}
}
private void deleteIndex()
{
Utilities.getParentDialog(this),
{
}
{
{
dlg.setVisible(true);
}
}
else
{
}
}
/**
* Saves the index modifications.
*
* @param modal
* whether the progress dialog for the task must be modal or not.
*/
{
if (!isModified())
{
return;
}
{
{
}
{
saveChanges.setEnabled(false);
dlg.setVisible(true);
}
}
{
}
}
/**
* Updates the contents of the panel with the provided index.
*
* @param index
* the index descriptor to be used to update the panel.
*/
{
ignoreCheckSave = true;
approximate.setSelected(false);
equality.setSelected(false);
ordering.setSelected(false);
substring.setSelected(false);
presence.setSelected(false);
{
switch(type)
{
case APPROXIMATE:
approximate.setSelected(true);
break;
case PRESENCE:
presence.setSelected(true);
break;
case EQUALITY:
equality.setSelected(true);
break;
case ORDERING:
ordering.setSelected(true);
break;
case SUBSTRING:
substring.setSelected(true);
break;
}
}
{
}
if (index.isDatabaseIndex())
{
}
if (index.isDatabaseIndex())
{
warning.setVisible(true);
}
{
{
warning.setVisible(true);
}
else
{
warning.setVisible(false);
}
}
ignoreCheckSave = false;
}
/**
* Returns <CODE>true</CODE> if the index has been modified and
* <CODE>false</CODE> otherwise.
*
* @return <CODE>true</CODE> if the index has been modified and
* <CODE>false</CODE> otherwise.
*/
private boolean isModified()
{
}
/**
* The task in charge of modifying the index.
*/
protected class ModifyIndexTask extends Task
{
private String attributeName;
private String backendName;
private int entryLimitValue;
private IndexDescriptor indexToModify;
private IndexDescriptor modifiedIndex;
/**
* The constructor of the task.
*
* @param info
* the control panel info.
* @param dlg
* the progress dialog that shows the progress of the task.
*/
{
indexTypes = getTypes();
}
/** {@inheritDoc} */
{
return Type.MODIFY_INDEX;
}
/** {@inheritDoc} */
{
return backendSet;
}
/** {@inheritDoc} */
public LocalizableMessage getTaskDescription()
{
}
/** {@inheritDoc} */
public boolean canLaunch(Task taskToBeLaunched, Collection<LocalizableMessage> incompatibilityReasons)
{
boolean canLaunch = true;
{
// All the operations are incompatible if they apply to this
// backend for safety. This is a short operation so the limitation
// has not a lot of impact.
{
canLaunch = false;
}
}
return canLaunch;
}
/**
* Updates the configuration of the modified index.
*
* @throws OpenDsException
* if there is an error updating the configuration.
*/
private void updateConfiguration() throws OpenDsException
{
boolean configHandlerUpdated = false;
try
{
if (!isServerRunning())
{
configHandlerUpdated = true;
getInfo().stopPooling();
if (getInfo().mustDeregisterConfig())
{
}
getInfo().setMustDeregisterConfig(true);
}
else
{
{
public void run()
{
}
});
}
{
public void run()
{
}
});
if (isServerRunning())
{
// Create additional indexes and display the equivalent command.
// Everything is done in the method createAdditionalIndexes
}
else
{
modifyIndex();
}
{
public void run()
{
}
});
}
finally
{
if (configHandlerUpdated)
{
DirectoryServer.getInstance().initializeConfiguration(ConfigReader.configClassName, ConfigReader.configFile);
getInfo().startPooling();
}
}
}
/**
* Returns the LDIF representation of the modified index.
*
* @return the LDIF representation of the modified index.
*/
private String getIndexLDIF()
{
final String dn = Utilities.getRDNString("ds-cfg-backend-id", backendName) + ",cn=Backends,cn=config";
{
}
{
}
}
private void modifyIndex() throws OpenDsException
{
try
{
}
catch (IOException ioe)
{
}
catch (ConfigException ce)
{
}
finally
{
if (ldifImportConfig != null)
{
}
}
}
/**
* Modifies index using the provided connection.
*
* @param ctx
* the connection to be used to update the index configuration.
* @throws OpenDsException
* if there is an error updating the server.
*/
{
{
}
{
}
{
}
}
/** {@inheritDoc} */
protected String getCommandLinePath()
{
return null;
}
/** {@inheritDoc} */
{
}
/**
* Returns the full command-line path of the dsconfig command-line if we can
* provide an equivalent command-line (the server is running).
*
* @return the full command-line path of the dsconfig command-line if we can
* provide an equivalent command-line (the server is running).
*/
private String getConfigCommandLineName()
{
if (isServerRunning() && isModified())
{
return getCommandLinePath("dsconfig");
}
else
{
return null;
}
}
/** {@inheritDoc} */
public void runTask()
{
try
{
}
catch (Throwable t)
{
lastException = t;
}
}
/** {@inheritDoc} */
public void postOperation()
{
{
}
}
{
{
// To add
{
{
}
}
// To delete
{
{
}
}
{
}
{
}
}
{
}
return args;
}
}
}