| | |
| | | import org.opends.server.util.ServerConstants; |
| | | |
| | | /** The panel displaying a simplified view of an entry. */ |
| | | public class SimplifiedViewEntryPanel extends ViewEntryPanel |
| | | class SimplifiedViewEntryPanel extends ViewEntryPanel |
| | | { |
| | | private static final long serialVersionUID = 2775960608128921072L; |
| | | private JPanel attributesPanel; |
| | |
| | | private GenericDialog browseEntriesDlg; |
| | | private LDAPEntrySelectionPanel browseEntriesPanel; |
| | | |
| | | private Map<String, List<String>> lastUserPasswords = new HashMap<>(); |
| | | private final Map<String, List<String>> lastUserPasswords = new HashMap<>(); |
| | | |
| | | private CustomSearchResult searchResult; |
| | | private boolean isReadOnly; |
| | | private TreePath treePath; |
| | | private JScrollPane scrollAttributes; |
| | | |
| | | private LinkedHashMap<String, List<EditorComponent>> hmEditors = new LinkedHashMap<>(); |
| | | private final Map<String, List<EditorComponent>> hmEditors = new LinkedHashMap<>(); |
| | | |
| | | private Set<String> requiredAttrs = new HashSet<>(); |
| | | private Map<String, JComponent> hmLabels = new HashMap<>(); |
| | | private Map<String, String> hmDisplayedNames = new HashMap<>(); |
| | | private Map<String, JComponent> hmComponents = new HashMap<>(); |
| | | private final Set<String> requiredAttrs = new HashSet<>(); |
| | | private final Map<String, JComponent> hmLabels = new HashMap<>(); |
| | | private final Map<String, String> hmDisplayedNames = new HashMap<>(); |
| | | private final Map<String, JComponent> hmComponents = new HashMap<>(); |
| | | |
| | | private final String CONFIRM_PASSWORD = "confirm password"; |
| | | |
| | | /** Map containing as key the attribute name and as value a localizable message. */ |
| | | static Map<String, LocalizableMessage> hmFriendlyAttrNames = new HashMap<>(); |
| | | private final static Map<String, LocalizableMessage> hmFriendlyAttrNames = new HashMap<>(); |
| | | /** |
| | | * Map containing as key an object class and as value the preferred naming |
| | | * attribute for the objectclass. |
| | | */ |
| | | static Map<String, String> hmNameAttrNames = new HashMap<>(); |
| | | static Map<String, String[]> hmOrdereredAttrNames = new HashMap<>(); |
| | | private static final Map<String, String> hmNameAttrNames = new HashMap<>(); |
| | | private static final Map<String, String[]> hmOrdereredAttrNames = new HashMap<>(); |
| | | static |
| | | { |
| | | hmFriendlyAttrNames.put(ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME, |
| | |
| | | hmOrdereredAttrNames.put("domain", new String[]{"dc", "description"}); |
| | | } |
| | | |
| | | private LocalizableMessage NAME = INFO_CTRL_PANEL_NAME_LABEL.get(); |
| | | private static final LocalizableMessage NAME = INFO_CTRL_PANEL_NAME_LABEL.get(); |
| | | |
| | | /** Default constructor. */ |
| | | public SimplifiedViewEntryPanel() |
| | |
| | | List<Object> values = sr.getAttributeValues(attr); |
| | | JComponent comp = getReadOnlyComponent(attr, values); |
| | | gbc.weightx = 0.0; |
| | | if (values.size() > 1) |
| | | { |
| | | gbc.anchor = GridBagConstraints.NORTHWEST; |
| | | } |
| | | else |
| | | { |
| | | gbc.anchor = GridBagConstraints.WEST; |
| | | if (values.size() == 1) |
| | | { |
| | | Object v = values.get(0); |
| | | if (v instanceof String |
| | | && ((String) v).contains("\n")) |
| | | { |
| | | gbc.anchor = GridBagConstraints.NORTHWEST; |
| | | } |
| | | } |
| | | } |
| | | gbc.anchor = anchor1(values); |
| | | gbc.insets.left = 0; |
| | | gbc.gridwidth = GridBagConstraints.RELATIVE; |
| | | attributesPanel.add(label, gbc); |
| | |
| | | } |
| | | else |
| | | { |
| | | for (String attr : sortedAttributes) |
| | | for (final String attr : sortedAttributes) |
| | | { |
| | | JLabel label = getLabelForAttribute(attr, sr); |
| | | if (isRequired(attr, sr)) |
| | |
| | | } |
| | | } |
| | | |
| | | if (isPassword(attr)) |
| | | final boolean isPasswordAttr = isPassword(attr); |
| | | if (isPasswordAttr) |
| | | { |
| | | List<String> pwds = new ArrayList<>(); |
| | | for (Object o : values) |
| | |
| | | } |
| | | |
| | | JComponent comp = getReadWriteComponent(attr, values); |
| | | |
| | | gbc.weightx = 0.0; |
| | | if (ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME.equalsIgnoreCase(attr)) |
| | | { |
| | | int nOcs = 0; |
| | | for (Object o : values) |
| | | { |
| | | if (!"top".equals(o)) |
| | | { |
| | | nOcs ++; |
| | | } |
| | | } |
| | | if (nOcs > 1) |
| | | { |
| | | gbc.anchor = GridBagConstraints.NORTHWEST; |
| | | } |
| | | else |
| | | { |
| | | gbc.anchor = GridBagConstraints.WEST; |
| | | } |
| | | } |
| | | else if (isSingleValue(attr)) |
| | | { |
| | | gbc.anchor = GridBagConstraints.WEST; |
| | | } |
| | | else if (values.size() <= 1 && |
| | | (hasBinaryValue(values) || isBinary(attr))) |
| | | { |
| | | gbc.anchor = GridBagConstraints.WEST; |
| | | } |
| | | else |
| | | { |
| | | gbc.anchor = GridBagConstraints.NORTHWEST; |
| | | } |
| | | gbc.anchor = anchor2(attr, values); |
| | | gbc.insets.left = 0; |
| | | gbc.gridwidth = GridBagConstraints.RELATIVE; |
| | | attributesPanel.add(label, gbc); |
| | |
| | | hmLabels.put(attr.toLowerCase(), label); |
| | | hmComponents.put(attr.toLowerCase(), comp); |
| | | |
| | | if (isPassword(attr)) |
| | | if (isPasswordAttr) |
| | | { |
| | | label = Utilities.createPrimaryLabel( |
| | | INFO_CTRL_PANEL_PASSWORD_CONFIRM_LABEL.get()); |
| | |
| | | hmComponents.put(key, comp); |
| | | |
| | | gbc.weightx = 0.0; |
| | | if (isSingleValue(attr)) |
| | | { |
| | | gbc.anchor = GridBagConstraints.WEST; |
| | | } |
| | | else |
| | | { |
| | | gbc.anchor = GridBagConstraints.NORTHWEST; |
| | | } |
| | | gbc.anchor = isSingleValue(attr) ? GridBagConstraints.WEST : GridBagConstraints.NORTHWEST; |
| | | gbc.insets.left = 0; |
| | | gbc.gridwidth = GridBagConstraints.RELATIVE; |
| | | attributesPanel.add(label, gbc); |
| | |
| | | }); |
| | | } |
| | | |
| | | private int anchor2(final String attr, List<Object> values) |
| | | { |
| | | if (ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME.equalsIgnoreCase(attr)) |
| | | { |
| | | int nOcs = 0; |
| | | for (Object o : values) |
| | | { |
| | | if (!"top".equals(o)) |
| | | { |
| | | nOcs++; |
| | | } |
| | | } |
| | | return nOcs > 1 ? GridBagConstraints.NORTHWEST : GridBagConstraints.WEST; |
| | | } |
| | | else if (isSingleValue(attr)) |
| | | { |
| | | return GridBagConstraints.WEST; |
| | | } |
| | | else if (values.size() <= 1 && (hasBinaryValue(values) || isBinary(attr))) |
| | | { |
| | | return GridBagConstraints.WEST; |
| | | } |
| | | else |
| | | { |
| | | return GridBagConstraints.NORTHWEST; |
| | | } |
| | | } |
| | | |
| | | private int anchor1(List<Object> values) |
| | | { |
| | | if (values.size() > 1) |
| | | { |
| | | return GridBagConstraints.NORTHWEST; |
| | | } |
| | | if (values.size() == 1) |
| | | { |
| | | Object v = values.get(0); |
| | | if (v instanceof String && ((String) v).contains("\n")) |
| | | { |
| | | return GridBagConstraints.NORTHWEST; |
| | | } |
| | | } |
| | | return GridBagConstraints.WEST; |
| | | } |
| | | |
| | | private JLabel getLabelForAttribute(String attrName, CustomSearchResult sr) |
| | | { |
| | | LocalizableMessageBuilder l = new LocalizableMessageBuilder(); |
| | |
| | | if (isRootEntry) |
| | | { |
| | | List<String> attrsNotToAdd = Arrays.asList("entryuuid", "hassubordinates", |
| | | "numsubordinates", "subschemasubentry", "entrydn", "hassubordinates"); |
| | | "numsubordinates", "subschemasubentry", "entrydn"); |
| | | for (String attr : sr.getAttributeNames()) |
| | | { |
| | | if (!find(attrNames, attr) && !find(attrsNotToAdd, attr)) |
| | |
| | | * BinaryCellValue...) and the associated value that will be used to create |
| | | * the modified entry corresponding to the contents of the panel. |
| | | */ |
| | | class EditorComponent |
| | | private class EditorComponent |
| | | { |
| | | private Component comp; |
| | | private final Component comp; |
| | | |
| | | /** |
| | | * Creates an EditorComponent using a text component. |
| | | * @param tf the text component. |
| | | */ |
| | | public EditorComponent(JTextComponent tf) |
| | | private EditorComponent(JTextComponent tf) |
| | | { |
| | | comp = tf; |
| | | tf.getDocument().addDocumentListener(new DocumentListener() |
| | |
| | | * Creates an EditorComponent using a BinaryCellPanel. |
| | | * @param binaryPanel the BinaryCellPanel. |
| | | */ |
| | | public EditorComponent(BinaryCellPanel binaryPanel) |
| | | private EditorComponent(BinaryCellPanel binaryPanel) |
| | | { |
| | | comp = binaryPanel; |
| | | } |
| | |
| | | * Creates an EditorComponent using a ObjectClassCellPanel. |
| | | * @param ocPanel the ObjectClassCellPanel. |
| | | */ |
| | | public EditorComponent(ObjectClassCellPanel ocPanel) |
| | | private EditorComponent(ObjectClassCellPanel ocPanel) |
| | | { |
| | | comp = ocPanel; |
| | | } |
| | |
| | | */ |
| | | public Object getValue() |
| | | { |
| | | Object returnValue; |
| | | if (comp instanceof ObjectClassCellPanel) |
| | | { |
| | | ObjectClassValue ocDesc = ((ObjectClassCellPanel)comp).getValue(); |
| | |
| | | values.addAll(getObjectClassSuperiorValues(oc)); |
| | | } |
| | | } |
| | | returnValue = values; |
| | | return values; |
| | | } else if (comp instanceof JTextArea) |
| | | { |
| | | LinkedHashSet<String> values = new LinkedHashSet<>(); |
| | |
| | | values.add(line); |
| | | } |
| | | } |
| | | returnValue = values; |
| | | return values; |
| | | } |
| | | else if (comp instanceof JTextComponent) |
| | | { |
| | | returnValue = ((JTextComponent)comp).getText(); |
| | | return ((JTextComponent) comp).getText(); |
| | | } |
| | | else |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | returnValue = ((BinaryValue)o).getBytes(); |
| | | return ((BinaryValue) o).getBytes(); |
| | | } |
| | | catch (ParseException pe) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | returnValue = o; |
| | | return o; |
| | | } |
| | | } |
| | | return returnValue; |
| | | } |
| | | } |
| | | } |