SimplifiedViewEntryPanel.java revision 2f6d798e90520dd1b83ac30e53838ae6fd41a150
/*
* 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 2013-2015 ForgeRock AS.
*/
/**
* The panel displaying a simplified view of an entry.
*/
public class SimplifiedViewEntryPanel extends ViewEntryPanel
{
private static final long serialVersionUID = 2775960608128921072L;
private JPanel attributesPanel;
private ScrollPaneBorderListener scrollListener;
private GenericDialog binaryDlg;
private BinaryValuePanel binaryPanel;
private GenericDialog editBinaryDlg;
private GenericDialog editOcDlg;
private ObjectClassEditorPanel editOcPanel;
private JLabel requiredLabel;
private JCheckBox showOnlyAttrsWithValues;
private DropTargetListener dropTargetListener;
private GenericDialog browseEntriesDlg;
private CustomSearchResult searchResult;
private boolean isReadOnly;
private JScrollPane scrollAttributes;
/** Map containing as key the attribute name and as value a localizable message. */
/**
* Map containing as key an object class and as value the preferred naming
* attribute for the objectclass.
*/
static
{
"userpassword", "mail", "telephonenumber", "facsimiletelephonenumber",
"employeenumber", "street", "l", "st", "postalcode", "mobile",
"homephone", "pager", "description", "postaladdress"});
"facsimiletelephonenumber"});
};
/**
* Default constructor.
*
*/
public SimplifiedViewEntryPanel()
{
super();
createLayout();
}
/** {@inheritDoc} */
public Component getPreferredFocusComponent()
{
return null;
}
/** {@inheritDoc} */
public boolean requiresBorder()
{
return false;
}
/**
* Creates the layout of the panel (but the contents are not populated here).
*/
private void createLayout()
{
dropTargetListener = new DropTargetListener()
{
/** {@inheritDoc} */
public void dragEnter(DropTargetDragEvent e)
{
}
/** {@inheritDoc} */
public void dragExit(DropTargetEvent e)
{
}
/** {@inheritDoc} */
public void dragOver(DropTargetDragEvent e)
{
}
/** {@inheritDoc} */
public void dropActionChanged(DropTargetDragEvent e)
{
}
/** {@inheritDoc} */
public void drop(DropTargetDropEvent e)
{
try {
//flavor not supported, reject drop
{
e.rejectDrop();
}
//cast into appropriate data type
{
{
{
}
}
}
else if (comp instanceof JTextField)
{
{
}
}
e.getDropTargetContext().dropComplete(true);
}
{
e.rejectDrop();
}
}
};
addTitlePanel(this, gbc);
{
/** {@inheritDoc} */
{
}
});
attributesPanel.setOpaque(false);
}
/** {@inheritDoc} */
{
boolean sameEntry = false;
{
}
searchResult = sr;
this.isReadOnly = isReadOnly;
// Build the attributes panel.
if (isReadOnly)
{
{
{
}
else
{
{
if (v instanceof String
{
}
}
}
}
}
else
{
{
{
}
{
{
}
else
{
}
}
if (isPassword(attr))
{
{
}
}
if (attr.equalsIgnoreCase(
{
int nOcs = 0;
{
if (!"top".equals(o))
{
nOcs ++;
}
}
if (nOcs > 1)
{
}
else
{
}
}
else if (isSingleValue(attr))
{
}
{
}
else
{
}
if (isPassword(attr))
{
if (isSingleValue(attr))
{
}
else
{
}
}
}
}
{
updateAttributeVisibility(false);
}
else if (isVisible())
{
repaint();
}
{
/** {@inheritDoc} */
public void run()
{
{
}
ignoreEntryChangeEvents = false;
}
});
}
{
if (index == -1)
{
}
else
{
}
{
// TODO: use message
subType = "binary";
}
if (isNameAttribute)
{
{
}
else
{
}
}
else
{
{
}
else
{
{
}
}
}
l.append(":");
}
boolean isReadOnly)
{
// Get all attributes that the entry can have
{
}
// Put first the attributes associated with the objectclass in
// hmOrderedAttrNames
{
{
{
if (index != -1)
{
}
else
{
}
}
}
}
// Handle the root entry separately: most of its attributes are operational
// so we filter a list of harcoded attributes.
if (isRootEntry)
{
"numsubordinates", "subschemasubentry", "entrydn",
"hassubordinates"};
{
boolean found = false;
{
if (found)
{
break;
}
}
if (!found)
{
{
if (found)
{
break;
}
}
}
if (!found)
{
}
}
}
else
{
// Try to get the attributes from the schema: first display the required
// attributes with a friendly name (in alphabetical order), then (in
// alphabetical order) the attributes with no friendly name. Finally
// do the same with the other attributes.
{
{
if (objectClass != null)
{
{
}
{
}
}
}
}
// Now try to put first the attributes for which we have a friendly
// name (the most common ones).
attrsWithNoOptions, true);
attrsWithNoOptions, false);
attrsWithNoOptions, true);
attrsWithNoOptions, false);
// In read-only mode display only the attributes with values
if (isReadOnly)
{
}
{
if (add)
{
boolean found = false;
{
if (found)
{
break;
}
}
if (!found)
{
}
}
}
}
return attrNames;
}
private void updateAttributes(
boolean addIfFriendlyName)
{
{
if (hasFriendlyName == addIfFriendlyName)
{
if (index != -1)
{
}
else
{
if (!hasCertificateSyntax(attr,
{
}
else
{
}
}
}
}
}
{
// GridLayout is used to avoid the 512 limit of GridBagLayout
{
if (attrName.equalsIgnoreCase(
{
{
schema);
}
ocPanel.setEditButtonVisible(false);
break;
}
{
}
else if (!isBinary)
{
{
}
else
{
}
break;
}
else
{
final byte[] binaryValue = (byte[])o;
{
/** {@inheritDoc} */
{
{
binaryPanel = new BinaryValuePanel();
binaryDlg = new GenericDialog(
}
binaryDlg.setVisible(true);
}
});
}
}
return panel;
}
{
{
}
return results;
}
{
{
if (attrName.equalsIgnoreCase(
{
final ObjectClassValue ocDescriptor;
{
}
else
{
ocDescriptor = null;
}
{
private ObjectClassValue newValue;
/** {@inheritDoc} */
{
{
editOcPanel = new ObjectClassEditorPanel();
editOcDlg = new GenericDialog(
null,
}
{
}
else
{
}
editOcDlg.setVisible(true);
if (editOcPanel.valueChanged())
{
}
}
});
panel = ocCellPanel;
break;
}
{
if (!o.equals(""))
{
}
}
else if (!isBinary)
{
if (isSingleValue(attrName))
{
if (mustAddBrowseButton(attrName))
{
}
}
else
{
final LocalizableMessage text = LocalizableMessage.raw(Utilities.getStringFromCollection(sValues, "\n"));
{
}
else
{
}
if (mustAddBrowseButton(attrName))
{
{
}
}
}
break;
}
else
{
pane.setDisplayDelete(true);
final byte[] binaryValue = (byte[])o;
{
}
{
private BinaryValue newValue;
/** {@inheritDoc} */
{
if (editBinaryDlg == null)
{
editBinaryDlg = new GenericDialog(
editBinaryDlg.setModal(true);
}
{
// We use an empty binary array to not breaking the logic:
// it means that there is no value for the attribute.
{
}
else
{
}
}
else
{
}
editBinaryDlg.setVisible(true);
if (editBinaryPanel.valueChanged())
{
}
}
});
{
/** {@inheritDoc} */
{
if (editBinaryPanel != null)
{
}
}
});
}
}
return panel;
}
{
boolean isSingleValue = false;
{
{
}
}
return isSingleValue;
}
{
boolean isRequired = false;
{
{
{
{
isRequired = true;
break;
}
}
}
}
return isRequired;
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
{
try
{
}
catch (Throwable t)
{
}
{
}
// Check passwords
{
{
{
}
}
}
{
{
}
}
{
throw new CheckEntrySyntaxException(errors);
}
try
{
}
catch (IOException ioe)
{
throw new OnlineUpdateException(
}
finally
{
if (ldifImportConfig != null)
{
}
}
return entry;
}
{
{
{
if (value instanceof ObjectClassValue)
{
{
}
}
else if (value instanceof Collection<?>)
{
{
}
}
else
{
}
}
}
return values;
}
{
return getDisplayedStringValues(attr);
}
{
}
{
return CONFIRM_PASSWORD+
}
{
}
/**
* Returns the LDIF representation of the displayed entry.
* @return the LDIF representation of the displayed entry.
*/
{
{
if (isConfirmPassword(attrName))
{
continue;
}
else if (isPassword(attrName))
{
{
{
}
}
else
{
}
}
else
{
}
}
// Add the attributes that are not displayed
{
{
}
}
}
{
boolean isAttrName = false;
{
{
isAttrName = true;
break;
}
}
return isAttrName;
}
{
{
}
return false;
}
{
boolean mustAddBrowseButton =
if (!mustAddBrowseButton)
{
{
{
// There is no name for a regex syntax.
if (syntaxName!=null) {
}
}
}
}
return mustAddBrowseButton;
}
/** {@inheritDoc} */
{
{
{
if (value instanceof Collection<?>)
{
}
else
{
}
}
}
return values;
}
{
{
}
}
/** {@inheritDoc} */
protected String getDisplayedDN()
{
try
{
{
{
{
{
if (firstNonEmpty != null)
{
}
}
}
else
{
}
}
if (attributeTypes.isEmpty())
{
// Check the attributes in the order that we display them and use
// the first one.
{
{
if (isPassword(attrName) ||
{
continue;
}
{
if (o instanceof String)
{
{
}
break;
}
}
}
}
}
if (!attributeTypes.isEmpty())
{
{
}
else
{
}
}
else
{
{
}
}
}
}
catch (Throwable t)
{
throw new RuntimeException("Unexpected error: "+t, t);
}
}
{
{
v = v.trim();
if (v.length() > 0)
{
return v;
}
}
return null;
}
{
if (browseEntriesDlg == null)
{
Utilities.getParentDialog(this));
browseEntriesDlg.setModal(true);
}
else
{
}
{
}
{
}
else
{
}
{
}
{
}
browseEntriesDlg.setVisible(true);
{
if (textComponent instanceof JTextArea)
{
{
{
}
}
}
else
{
}
}
}
{
if (o instanceof byte[])
{
}
else
{
}
}
{
{
{
}
}
ignoreEntryChangeEvents = true;
{
{
}
{
}
{
if (objectClass != null)
{
{
}
{
}
}
}
{
}
{
{
continue;
}
if (isPassword(attrName))
{
{
}
else
{
}
}
else if (!schemaReadOnlyAttributesLowerCase.contains(
attrName.toLowerCase()))
{
}
}
}
ignoreEntryChangeEvents = false;
}
private void updateAttributeVisibility(boolean showAll)
{
{
{
label.setVisible(true);
comp.setVisible(true);
}
else
{
boolean hasValue = false;
{
if (hasValue)
{
break;
}
}
}
}
repaint();
}
{
}
{
if (value instanceof byte[])
{
}
{
}
else if (value instanceof Collection<?>)
{
}
}
/** Calls #addBrowseClicked(). */
private final class AddBrowseClickedActionListener implements ActionListener
{
private final JTextComponent tc;
{
}
{
}
}
/**
* A class that makes an association between a component (JTextField, a
* BinaryCellValue...) and the associated value that will be used to create
* the modified entry corresponding to the contents of the panel.
*
*/
class EditorComponent
{
/**
* Creates an EditorComponent using a text component.
* @param tf the text component.
*/
{
{
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
{
}
});
}
/**
* Creates an EditorComponent using a BinaryCellPanel.
* @param binaryPanel the BinaryCellPanel.
*/
{
comp = binaryPanel;
}
/**
* Creates an EditorComponent using a ObjectClassCellPanel.
* @param ocPanel the ObjectClassCellPanel.
*/
{
}
/**
* Returns the value that the component is displaying. The returned value
* is a Set of Strings (for multi-valued attributes), a byte[] for binary
* values or a String for single-valued attributes. Single-valued
* attributes refer to the definition in the schema (and not to the fact
* that there is a single value for the attribute in this entry).
* @return the value that the component is displaying.
*/
{
if (comp instanceof ObjectClassCellPanel)
{
if (structural != null)
{
}
{
{
}
}
{
{
{
}
}
}
else if (comp instanceof JTextComponent)
{
}
else
{
if (o instanceof BinaryValue)
{
try
{
}
catch (ParseException pe)
{
}
}
else
{
returnValue = o;
}
}
return returnValue;
}
}
}