3853N/A/*
3853N/A * CDDL HEADER START
3853N/A *
3853N/A * The contents of this file are subject to the terms of the
3853N/A * Common Development and Distribution License, Version 1.0 only
3853N/A * (the "License"). You may not use this file except in compliance
3853N/A * with the License.
3853N/A *
3853N/A * You can obtain a copy of the license at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
3853N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
3853N/A * See the License for the specific language governing permissions
3853N/A * and limitations under the License.
3853N/A *
3853N/A * When distributing Covered Code, include this CDDL HEADER in each
3853N/A * file and include the License file at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
3853N/A * add the following below this CDDL HEADER, with the fields enclosed
3853N/A * by brackets "[]" replaced with your own identifying information:
3853N/A * Portions Copyright [yyyy] [name of copyright owner]
3853N/A *
3853N/A * CDDL HEADER END
3853N/A *
3853N/A *
4994N/A * Copyright 2008-2010 Sun Microsystems, Inc.
3853N/A */
3853N/A
3853N/Apackage org.opends.guitools.controlpanel.ui;
3853N/A
3853N/Aimport static org.opends.messages.AdminToolMessages.*;
3853N/A
3853N/Aimport java.awt.CardLayout;
3853N/Aimport java.awt.Component;
3853N/Aimport java.awt.GridBagConstraints;
3853N/Aimport java.awt.Insets;
3853N/Aimport java.awt.event.ActionEvent;
3853N/Aimport java.awt.event.ActionListener;
3853N/Aimport java.util.ArrayList;
3853N/A
3853N/Aimport javax.swing.JButton;
3853N/Aimport javax.swing.JPanel;
3853N/Aimport javax.swing.SwingUtilities;
3853N/Aimport javax.swing.border.Border;
3853N/Aimport javax.swing.border.EmptyBorder;
3853N/Aimport javax.swing.tree.TreePath;
3853N/A
5014N/Aimport org.opends.guitools.controlpanel.browser.BasicNodeError;
3853N/Aimport org.opends.guitools.controlpanel.browser.BrowserController;
3853N/Aimport org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
3853N/Aimport org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
3853N/Aimport org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
3853N/Aimport org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
3853N/Aimport org.opends.guitools.controlpanel.event.EntryReadErrorEvent;
3853N/Aimport org.opends.guitools.controlpanel.event.EntryReadEvent;
3853N/Aimport org.opends.guitools.controlpanel.event.EntryReadListener;
3853N/Aimport org.opends.guitools.controlpanel.event.LDAPEntryChangedEvent;
3853N/Aimport org.opends.guitools.controlpanel.event.LDAPEntryChangedListener;
3853N/Aimport org.opends.guitools.controlpanel.task.DeleteEntryTask;
3853N/Aimport org.opends.guitools.controlpanel.task.ModifyEntryTask;
3853N/Aimport org.opends.guitools.controlpanel.task.Task;
3853N/Aimport org.opends.guitools.controlpanel.util.Utilities;
3853N/Aimport org.opends.messages.Message;
3853N/Aimport org.opends.quicksetup.Constants;
3853N/Aimport org.opends.server.config.ConfigConstants;
3853N/Aimport org.opends.server.types.DN;
3853N/Aimport org.opends.server.types.Entry;
3853N/Aimport org.opends.server.types.OpenDsException;
5125N/Aimport org.opends.server.util.ServerConstants;
3853N/A
3853N/A/**
3853N/A * This is the panel that contains all the different views to display an entry.
3853N/A *
3853N/A */
3853N/Apublic class LDAPEntryPanel extends StatusGenericPanel
3853N/Aimplements EntryReadListener
3853N/A{
3853N/A private static final long serialVersionUID = -6608246173472437830L;
3853N/A private JButton saveChanges;
3853N/A private JButton delete;
3853N/A private JPanel mainPanel;
3853N/A private CardLayout cardLayout;
3853N/A
3853N/A private ErrorSearchingEntryPanel errorSearchingPanel;
3853N/A private LDIFViewEntryPanel ldifEntryPanel;
3853N/A private TableViewEntryPanel tableEntryPanel;
3853N/A private SimplifiedViewEntryPanel simplifiedEntryPanel;
3853N/A
3853N/A private ViewEntryPanel displayedEntryPanel;
3853N/A
3853N/A private CustomSearchResult searchResult;
3853N/A private BrowserController controller;
3853N/A private TreePath treePath;
3853N/A
3853N/A private ModifyEntryTask newTask;
3853N/A
3853N/A private final String NOTHING_SELECTED = "Nothing Selected";
3853N/A private final String MULTIPLE_SELECTED = "Multiple Selected";
3853N/A private final String LDIF_VIEW = "LDIF View";
3853N/A private final String ATTRIBUTE_VIEW = "Attribute View";
3853N/A private final String SIMPLIFIED_VIEW = "Simplified View";
3853N/A private final String ERROR_SEARCHING = "Error Searching";
3853N/A
3853N/A private View view = View.SIMPLIFIED_VIEW;
3853N/A
3853N/A /**
3853N/A * The different views that we have to display an LDAP entry.
3853N/A *
3853N/A */
3853N/A public enum View
3853N/A {
3853N/A /**
3853N/A * Simplified view.
3853N/A */
3853N/A SIMPLIFIED_VIEW,
3853N/A /**
3853N/A * Attribute view (contained in a table).
3853N/A */
3853N/A ATTRIBUTE_VIEW,
3853N/A /**
3853N/A * LDIF view (text based).
3853N/A */
3853N/A LDIF_VIEW
3853N/A };
3853N/A
3853N/A /**
3853N/A * Default constructor.
3853N/A *
3853N/A */
3853N/A public LDAPEntryPanel()
3853N/A {
3853N/A super();
3853N/A createLayout();
3853N/A }
3853N/A
3853N/A /**
3853N/A * Creates the layout of the panel (but the contents are not populated here).
3853N/A *
3853N/A */
3853N/A private void createLayout()
3853N/A {
3853N/A GridBagConstraints gbc = new GridBagConstraints();
3853N/A cardLayout = new CardLayout();
3853N/A mainPanel = new JPanel(cardLayout);
3853N/A mainPanel.setOpaque(false);
3853N/A gbc.gridx = 0;
3853N/A gbc.gridy = 0;
3853N/A gbc.gridwidth = 2;
3853N/A gbc.weightx = 1.0;
3853N/A gbc.weighty = 1.0;
3853N/A gbc.fill = GridBagConstraints.BOTH;
3853N/A add(mainPanel, gbc);
3853N/A gbc.gridwidth = 1;
3853N/A gbc.anchor = GridBagConstraints.WEST;
3853N/A gbc.insets = new Insets(5, 5, 5, 5);
3853N/A gbc.weighty = 0.0;
3853N/A gbc.gridy ++;
3853N/A gbc.fill = GridBagConstraints.NONE;
3853N/A delete = Utilities.createButton(INFO_CTRL_PANEL_DELETE_ENTRY_BUTTON.get());
3853N/A delete.setOpaque(false);
3853N/A add(delete, gbc);
3853N/A delete.addActionListener(new ActionListener()
3853N/A {
3853N/A public void actionPerformed(ActionEvent ev)
3853N/A {
3853N/A deleteEntry();
3853N/A }
3853N/A });
3853N/A
3853N/A gbc.anchor = GridBagConstraints.EAST;
3853N/A gbc.gridx ++;
3853N/A saveChanges =
3853N/A Utilities.createButton(INFO_CTRL_PANEL_SAVE_CHANGES_LABEL.get());
3853N/A saveChanges.setOpaque(false);
3853N/A add(saveChanges, gbc);
3853N/A saveChanges.addActionListener(new ActionListener()
3853N/A {
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void actionPerformed(ActionEvent ev)
3853N/A {
3853N/A saveChanges(true);
3853N/A }
3853N/A });
3853N/A
3853N/A Border border = new EmptyBorder(10, 10, 10, 10);
3853N/A
3853N/A NoItemSelectedPanel noEntryPanel = new NoItemSelectedPanel();
3853N/A noEntryPanel.setMessage(INFO_CTRL_PANEL_NO_ENTRY_SELECTED_LABEL.get());
3853N/A Utilities.setBorder(noEntryPanel, border);
3853N/A mainPanel.add(noEntryPanel, NOTHING_SELECTED);
3853N/A
3853N/A NoItemSelectedPanel multipleEntryPanel = new NoItemSelectedPanel();
3853N/A multipleEntryPanel.setMessage(
3853N/A INFO_CTRL_PANEL_MULTIPLE_ENTRIES_SELECTED_LABEL.get());
3853N/A Utilities.setBorder(multipleEntryPanel, border);
3853N/A mainPanel.add(multipleEntryPanel, MULTIPLE_SELECTED);
3853N/A
3853N/A errorSearchingPanel = new ErrorSearchingEntryPanel();
3853N/A if (errorSearchingPanel.requiresBorder())
3853N/A {
3853N/A Utilities.setBorder(multipleEntryPanel, border);
3853N/A }
3853N/A mainPanel.add(errorSearchingPanel, ERROR_SEARCHING);
3853N/A
3853N/A LDAPEntryChangedListener listener = new LDAPEntryChangedListener()
3853N/A {
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void entryChanged(LDAPEntryChangedEvent ev)
3853N/A {
3853N/A boolean enable = saveChanges.isVisible() &&
3853N/A !authenticationRequired(getInfo().getServerDescriptor());
3853N/A if (enable)
3853N/A {
3853N/A if (ev.getEntry() == null)
3853N/A {
3853N/A // Something changed that is wrong: assume the entry has been
3853N/A // modified, when the user tries to save we will inform of the
3853N/A // problem
3853N/A enable = true;
3853N/A }
3853N/A else
3853N/A {
3853N/A boolean modified =
3853N/A !Utilities.areDnsEqual(ev.getEntry().getDN().toString(),
3853N/A searchResult.getDN()) ||
3853N/A !ModifyEntryTask.getModifications(ev.getEntry(), searchResult,
3853N/A getInfo()).isEmpty();
3853N/A enable = modified;
3853N/A }
3853N/A }
3853N/A saveChanges.setEnabled(enable);
3853N/A }
3853N/A };
3853N/A
3853N/A ldifEntryPanel = new LDIFViewEntryPanel();
3853N/A ldifEntryPanel.addLDAPEntryChangedListener(listener);
3853N/A if (ldifEntryPanel.requiresBorder())
3853N/A {
3853N/A Utilities.setBorder(ldifEntryPanel, border);
3853N/A }
3853N/A mainPanel.add(ldifEntryPanel, LDIF_VIEW);
3853N/A
3853N/A tableEntryPanel = new TableViewEntryPanel();
3853N/A tableEntryPanel.addLDAPEntryChangedListener(listener);
3853N/A if (tableEntryPanel.requiresBorder())
3853N/A {
3853N/A Utilities.setBorder(tableEntryPanel, border);
3853N/A }
3853N/A mainPanel.add(tableEntryPanel, ATTRIBUTE_VIEW);
3853N/A
3853N/A simplifiedEntryPanel = new SimplifiedViewEntryPanel();
3853N/A simplifiedEntryPanel.addLDAPEntryChangedListener(listener);
3853N/A if (simplifiedEntryPanel.requiresBorder())
3853N/A {
3853N/A Utilities.setBorder(simplifiedEntryPanel, border);
3853N/A }
3853N/A mainPanel.add(simplifiedEntryPanel, SIMPLIFIED_VIEW);
3853N/A
3853N/A cardLayout.show(mainPanel, NOTHING_SELECTED);
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void okClicked()
3853N/A {
3853N/A // No ok button
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void entryRead(EntryReadEvent ev)
3853N/A {
3853N/A searchResult = ev.getSearchResult();
3853N/A
3853N/A updateEntryView(searchResult, treePath);
3853N/A }
3853N/A
3853N/A /**
3853N/A * Updates the panel with the provided search result.
3853N/A * @param searchResult the search result corresponding to the selected node.
3853N/A * @param treePath the tree path of the selected node.
3853N/A */
3853N/A private void updateEntryView(CustomSearchResult searchResult,
3853N/A TreePath treePath)
3853N/A {
3853N/A boolean isReadOnly = isReadOnly(searchResult.getDN());
3853N/A boolean canDelete = canDelete(searchResult.getDN());
3853N/A
3853N/A delete.setVisible(canDelete);
3853N/A saveChanges.setVisible(!isReadOnly);
3853N/A String cardKey;
3853N/A switch (view)
3853N/A {
3853N/A case LDIF_VIEW:
3853N/A displayedEntryPanel = ldifEntryPanel;
3853N/A cardKey = LDIF_VIEW;
3853N/A break;
3853N/A case ATTRIBUTE_VIEW:
3853N/A displayedEntryPanel = tableEntryPanel;
3853N/A cardKey = ATTRIBUTE_VIEW;
3853N/A break;
3853N/A default:
3853N/A displayedEntryPanel = simplifiedEntryPanel;
3853N/A cardKey = SIMPLIFIED_VIEW;
3853N/A }
3853N/A displayedEntryPanel.update(searchResult, isReadOnly, treePath);
3853N/A saveChanges.setEnabled(false);
3853N/A cardLayout.show(mainPanel, cardKey);
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the view to be displayed by this panel.
3853N/A * @param view the view.
3853N/A */
3853N/A public void setView(View view)
3853N/A {
3853N/A if (view != this.view)
3853N/A {
3853N/A this.view = view;
3853N/A if (searchResult != null)
3853N/A {
3853N/A updateEntryView(searchResult, treePath);
3853N/A }
3853N/A }
3853N/A }
3853N/A
3853N/A /**
3853N/A * Displays a message informing that an error occurred reading the entry.
3853N/A * @param ev the entry read error event.
3853N/A */
3853N/A public void entryReadError(EntryReadErrorEvent ev)
3853N/A {
3853N/A searchResult = null;
3853N/A
3853N/A errorSearchingPanel.setError(ev.getDN(), ev.getError());
3853N/A
3853N/A delete.setVisible(false);
3853N/A saveChanges.setVisible(false);
3853N/A
3853N/A cardLayout.show(mainPanel, ERROR_SEARCHING);
3853N/A
3853N/A displayedEntryPanel = null;
3853N/A }
3853N/A
3853N/A /**
5014N/A * Displays a message informing that an error occurred resolving a referral.
5014N/A * @param dn the DN of the local entry.
5014N/A * @param referrals the list of referrals defined in the entry.
5014N/A * @param error the error that occurred resolving the referral.
5014N/A */
5014N/A public void referralSolveError(String dn, String[] referrals,
5014N/A BasicNodeError error)
5014N/A {
5014N/A searchResult = null;
5014N/A
5014N/A errorSearchingPanel.setReferralError(dn, referrals, error);
5014N/A
5014N/A delete.setVisible(false);
5014N/A saveChanges.setVisible(false);
5014N/A
5014N/A cardLayout.show(mainPanel, ERROR_SEARCHING);
5014N/A
5014N/A displayedEntryPanel = null;
5014N/A }
5014N/A
5014N/A /**
3853N/A * Displays a panel informing that nothing is selected.
3853N/A *
3853N/A */
3853N/A public void noEntrySelected()
3853N/A {
3853N/A searchResult = null;
3853N/A
3853N/A delete.setVisible(false);
3853N/A saveChanges.setVisible(false);
3853N/A
3853N/A cardLayout.show(mainPanel, NOTHING_SELECTED);
3853N/A
3853N/A displayedEntryPanel = null;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Displays a panel informing that multiple entries are selected.
3853N/A *
3853N/A */
3853N/A public void multipleEntriesSelected()
3853N/A {
3853N/A searchResult = null;
3853N/A
3853N/A delete.setVisible(false);
3853N/A saveChanges.setVisible(false);
3853N/A
3853N/A cardLayout.show(mainPanel, MULTIPLE_SELECTED);
3853N/A
3853N/A displayedEntryPanel = null;
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public GenericDialog.ButtonType getButtonType()
3853N/A {
3853N/A return GenericDialog.ButtonType.NO_BUTTON;
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public Message getTitle()
3853N/A {
3853N/A return INFO_CTRL_PANEL_EDIT_LDAP_ENTRY_TITLE.get();
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public Component getPreferredFocusComponent()
3853N/A {
3853N/A return saveChanges;
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void configurationChanged(ConfigurationChangeEvent ev)
3853N/A {
3853N/A final ServerDescriptor desc = ev.getNewDescriptor();
3853N/A SwingUtilities.invokeLater(new Runnable()
3853N/A {
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void run()
3853N/A {
3853N/A boolean isReadOnly = true;
3853N/A boolean canDelete = false;
3853N/A if ((searchResult != null) && desc.isAuthenticated())
3853N/A {
3853N/A isReadOnly = isReadOnly(searchResult.getDN());
3853N/A canDelete = canDelete(searchResult.getDN());
3853N/A }
3853N/A
3853N/A delete.setVisible(canDelete);
3853N/A saveChanges.setVisible(!isReadOnly);
3853N/A }
3853N/A });
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void setInfo(ControlPanelInfo info)
3853N/A {
3853N/A super.setInfo(info);
3853N/A simplifiedEntryPanel.setInfo(info);
3853N/A ldifEntryPanel.setInfo(info);
3853N/A tableEntryPanel.setInfo(info);
3853N/A errorSearchingPanel.setInfo(info);
3853N/A }
3853N/A
3853N/A private DN[] parentReadOnly;
3853N/A private DN[] nonDeletable;
3853N/A {
3853N/A try
3853N/A {
3853N/A parentReadOnly = new DN[] {
3853N/A DN.decode(ConfigConstants.DN_TASK_ROOT),
3853N/A DN.decode(ConfigConstants.DN_MONITOR_ROOT),
3853N/A DN.decode(ConfigConstants.DN_BACKUP_ROOT),
5125N/A DN.decode(Constants.REPLICATION_CHANGES_DN),
5125N/A DN.decode(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT)
3853N/A };
3853N/A nonDeletable = new DN[] {
3853N/A DN.decode(ConfigConstants.DN_CONFIG_ROOT),
3853N/A DN.decode(ConfigConstants.DN_DEFAULT_SCHEMA_ROOT),
3853N/A DN.decode(ConfigConstants.DN_TRUST_STORE_ROOT)
3853N/A };
3853N/A }
3853N/A catch (Throwable t)
3853N/A {
4676N/A throw new RuntimeException("Error decoding DNs: "+t, t);
3853N/A }
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns <CODE>true</CODE> if the provided DN corresponds to a read-only
3853N/A * entry and <CODE>false</CODE> otherwise.
3853N/A * @param sDn the DN of the entry.
3853N/A * @return <CODE>true</CODE> if the provided DN corresponds to a read-only
3853N/A * entry and <CODE>false</CODE> otherwise.
3853N/A */
3853N/A public boolean isReadOnly(String sDn)
3853N/A {
3853N/A boolean isReadOnly = false;
3853N/A try
3853N/A {
3853N/A DN dn = DN.decode(sDn);
3853N/A for (DN parentDN : parentReadOnly)
3853N/A {
3853N/A if (dn.isDescendantOf(parentDN))
3853N/A {
3853N/A isReadOnly = true;
3853N/A break;
3853N/A }
3853N/A }
3853N/A if (!isReadOnly)
3853N/A {
3853N/A isReadOnly = dn.equals(DN.NULL_DN);
3853N/A }
3853N/A }
3853N/A catch (Throwable t)
3853N/A {
4676N/A throw new RuntimeException("Error decoding DNs: "+t, t);
3853N/A }
3853N/A return isReadOnly;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns <CODE>true</CODE> if the provided DN corresponds to an entry that
3853N/A * can be deleted and <CODE>false</CODE> otherwise.
3853N/A * @param sDn the DN of the entry.
3853N/A * @return <CODE>true</CODE> if the provided DN corresponds to an entry that
3853N/A * can be deleted and <CODE>false</CODE> otherwise.
3853N/A */
3853N/A public boolean canDelete(String sDn)
3853N/A {
3853N/A boolean canDelete = true;
3853N/A try
3853N/A {
3853N/A DN dn = DN.decode(sDn);
3853N/A for (DN parentDN : parentReadOnly)
3853N/A {
3853N/A if (dn.isDescendantOf(parentDN))
3853N/A {
3853N/A canDelete = false;
3853N/A break;
3853N/A }
3853N/A }
3853N/A if (canDelete)
3853N/A {
3853N/A for (DN cannotDelete : nonDeletable)
3853N/A {
3853N/A if (cannotDelete.equals(dn))
3853N/A {
3853N/A canDelete = false;
3853N/A break;
3853N/A }
3853N/A }
3853N/A }
3853N/A if (canDelete)
3853N/A {
3853N/A canDelete = !dn.equals(DN.NULL_DN);
3853N/A }
3853N/A }
3853N/A catch (Throwable t)
3853N/A {
4676N/A throw new RuntimeException("Error decoding DNs: "+t, t);
3853N/A }
3853N/A return canDelete;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Saves the changes done to the entry.
3853N/A * @param modal whether the progress dialog for the task must be modal or
3853N/A * not.
3853N/A */
3853N/A private void saveChanges(boolean modal)
3853N/A {
3853N/A newTask = null;
3853N/A final ArrayList<Message> errors = new ArrayList<Message>();
3853N/A // Check that the entry is correct.
3853N/A try
3853N/A {
3853N/A ProgressDialog dlg = new ProgressDialog(
4832N/A Utilities.getFrame(this),
4832N/A Utilities.getFrame(this),
3853N/A INFO_CTRL_PANEL_MODIFYING_ENTRY_CHANGES_TITLE.get(), getInfo());
3853N/A dlg.setModal(modal);
3853N/A Entry entry = displayedEntryPanel.getEntry();
3853N/A newTask = new ModifyEntryTask(getInfo(), dlg, entry,
3853N/A searchResult, controller, treePath);
3853N/A for (Task task : getInfo().getTasks())
3853N/A {
3853N/A task.canLaunch(newTask, errors);
3853N/A }
3853N/A if ((errors.size() == 0) && newTask.hasModifications())
3853N/A {
3853N/A String dn = entry.getDN().toString();
3853N/A launchOperation(newTask,
3853N/A INFO_CTRL_PANEL_MODIFYING_ENTRY_SUMMARY.get(dn),
3853N/A INFO_CTRL_PANEL_MODIFYING_ENTRY_COMPLETE.get(),
3853N/A INFO_CTRL_PANEL_MODIFYING_ENTRY_SUCCESSFUL.get(dn),
3853N/A ERR_CTRL_PANEL_MODIFYING_ENTRY_ERROR_SUMMARY.get(),
3853N/A ERR_CTRL_PANEL_MODIFYING_ENTRY_ERROR_DETAILS.get(dn),
3853N/A null,
3853N/A dlg);
3853N/A saveChanges.setEnabled(false);
3853N/A dlg.setVisible(true);
3853N/A }
4013N/A else if (errors.size() == 0)
4013N/A {
4013N/A // Mark the panel as it has no changes. This can happen because every
4013N/A // time the user types something the saveChanges button is enabled
4013N/A // (for performance reasons with huge entries).
4013N/A saveChanges.setEnabled(false);
4013N/A }
3853N/A }
3853N/A catch (OpenDsException ode)
3853N/A {
3853N/A errors.add(ERR_CTRL_PANEL_INVALID_ENTRY.get(
3853N/A ode.getMessageObject().toString()));
3853N/A }
3853N/A if (errors.size() > 0)
3853N/A {
3853N/A displayErrorDialog(errors);
3853N/A }
3853N/A }
3853N/A
3853N/A private void deleteEntry()
3853N/A {
3853N/A final ArrayList<Message> errors = new ArrayList<Message>();
3853N/A // Check that the entry is correct.
5130N/A // Rely in numsubordinates and hassubordinates
5130N/A boolean isLeaf = !BrowserController.getHasSubOrdinates(searchResult);
3853N/A
3853N/A if (treePath != null)
3853N/A {
3853N/A Message title = isLeaf ? INFO_CTRL_PANEL_DELETING_ENTRY_TITLE.get() :
3853N/A INFO_CTRL_PANEL_DELETING_SUBTREE_TITLE.get();
3853N/A ProgressDialog dlg = new ProgressDialog(
4832N/A Utilities.createFrame(),
4832N/A Utilities.getParentDialog(this), title, getInfo());
3853N/A DeleteEntryTask newTask = new DeleteEntryTask(getInfo(), dlg,
3853N/A new TreePath[]{treePath}, controller);
3853N/A for (Task task : getInfo().getTasks())
3853N/A {
3853N/A task.canLaunch(newTask, errors);
3853N/A }
3853N/A if (errors.size() == 0)
3853N/A {
3853N/A Message confirmationMessage =
3853N/A isLeaf ? INFO_CTRL_PANEL_DELETE_ENTRY_CONFIRMATION_DETAILS.get(
3853N/A searchResult.getDN()) :
3853N/A INFO_CTRL_PANEL_DELETE_SUBTREE_CONFIRMATION_DETAILS.get(
3853N/A searchResult.getDN());
3853N/A if (displayConfirmationDialog(
3853N/A INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(),
3853N/A confirmationMessage))
3853N/A {
3853N/A String dn = searchResult.getDN();
3853N/A if (isLeaf)
3853N/A {
3853N/A launchOperation(newTask,
3853N/A INFO_CTRL_PANEL_DELETING_ENTRY_SUMMARY.get(dn),
3853N/A INFO_CTRL_PANEL_DELETING_ENTRY_COMPLETE.get(),
3853N/A INFO_CTRL_PANEL_DELETING_ENTRY_SUCCESSFUL.get(dn),
3853N/A ERR_CTRL_PANEL_DELETING_ENTRY_ERROR_SUMMARY.get(),
3853N/A ERR_CTRL_PANEL_DELETING_ENTRY_ERROR_DETAILS.get(dn),
3853N/A null,
3853N/A dlg);
3853N/A }
3853N/A else
3853N/A {
3853N/A launchOperation(newTask,
3853N/A INFO_CTRL_PANEL_DELETING_SUBTREE_SUMMARY.get(dn),
3853N/A INFO_CTRL_PANEL_DELETING_SUBTREE_COMPLETE.get(),
3853N/A INFO_CTRL_PANEL_DELETING_SUBTREE_SUCCESSFUL.get(dn),
3853N/A ERR_CTRL_PANEL_DELETING_SUBTREE_ERROR_SUMMARY.get(),
3853N/A ERR_CTRL_PANEL_DELETING_SUBTREE_ERROR_DETAILS.get(dn),
3853N/A null,
3853N/A dlg);
3853N/A }
3853N/A dlg.setVisible(true);
3853N/A }
3853N/A }
3853N/A }
3853N/A if (errors.size() > 0)
3853N/A {
3853N/A displayErrorDialog(errors);
3853N/A }
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the browser controller in charge of the tree.
3853N/A * @return the browser controller in charge of the tree.
3853N/A */
3853N/A public BrowserController getController()
3853N/A {
3853N/A return controller;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the browser controller in charge of the tree.
3853N/A * @param controller the browser controller in charge of the tree.
3853N/A */
3853N/A public void setController(BrowserController controller)
3853N/A {
3853N/A this.controller = controller;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the tree path associated with the node that is being displayed.
3853N/A * @return the tree path associated with the node that is being displayed.
3853N/A */
3853N/A public TreePath getTreePath()
3853N/A {
3853N/A return treePath;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the tree path associated with the node that is being displayed.
3853N/A * @param treePath the tree path associated with the node that is being
3853N/A * displayed.
3853N/A */
3853N/A public void setTreePath(TreePath treePath)
3853N/A {
3853N/A this.treePath = treePath;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Method used to know if there are unsaved changes or not. It is used by
3853N/A * the entry selection listener when the user changes the selection.
3853N/A * @return <CODE>true</CODE> if there are unsaved changes (and so the
3853N/A * selection of the entry should be cancelled) and <CODE>false</CODE>
3853N/A * otherwise.
3853N/A */
3853N/A public boolean mustCheckUnsavedChanges()
3853N/A {
3853N/A return (displayedEntryPanel != null) &&
3853N/A saveChanges.isVisible() && saveChanges.isEnabled();
3853N/A }
3853N/A
3853N/A /**
3853N/A * Tells whether the user chose to save the changes in the panel, to not save
4902N/A * them or simply canceled the selection change in the tree.
3853N/A * @return the value telling whether the user chose to save the changes in the
4902N/A * panel, to not save them or simply canceled the selection in the tree.
3853N/A */
3853N/A public UnsavedChangesDialog.Result checkUnsavedChanges()
3853N/A {
3853N/A UnsavedChangesDialog.Result result;
3853N/A UnsavedChangesDialog unsavedChangesDlg = new UnsavedChangesDialog(
3853N/A Utilities.getParentDialog(this), getInfo());
3853N/A unsavedChangesDlg.setMessage(INFO_CTRL_PANEL_UNSAVED_CHANGES_SUMMARY.get(),
3853N/A INFO_CTRL_PANEL_UNSAVED_ENTRY_CHANGES_DETAILS.get(searchResult.getDN()));
3853N/A Utilities.centerGoldenMean(unsavedChangesDlg,
3853N/A Utilities.getParentDialog(this));
3853N/A unsavedChangesDlg.setVisible(true);
3853N/A result = unsavedChangesDlg.getResult();
3853N/A if (result == UnsavedChangesDialog.Result.SAVE)
3853N/A {
3853N/A saveChanges(false);
3853N/A if ((newTask == null) || // The user data is not valid
3853N/A newTask.getState() != Task.State.FINISHED_SUCCESSFULLY)
3853N/A {
3853N/A result = UnsavedChangesDialog.Result.CANCEL;
3853N/A }
3853N/A }
3853N/A
3853N/A return result;
3853N/A }
3853N/A}