mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
26.26.2009 7faa5e4d10edda3015f96a3a98cc2115aa16f1dd
Fix for issue 3555 (Control panel : Manage entries menu does not refresh the view off the DIT)

Create a listener that will notify some panels that an import or a restore has been done.
2 files added
4 files modified
307 ■■■■■ changed files
opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java 40 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/event/BackendPopulatedEvent.java 62 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/event/BackendPopulatedListener.java 42 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java 124 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java 20 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java 19 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java
@@ -44,6 +44,8 @@
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.guitools.controlpanel.browser.IconPool;
import org.opends.guitools.controlpanel.browser.LDAPConnectionPool;
import org.opends.guitools.controlpanel.event.BackendPopulatedEvent;
import org.opends.guitools.controlpanel.event.BackendPopulatedListener;
import org.opends.guitools.controlpanel.event.BackupCreatedEvent;
import org.opends.guitools.controlpanel.event.BackupCreatedListener;
import org.opends.guitools.controlpanel.event.ConfigChangeListener;
@@ -101,6 +103,9 @@
  private LinkedHashSet<BackupCreatedListener> backupListeners =
    new LinkedHashSet<BackupCreatedListener>();
  private LinkedHashSet<BackendPopulatedListener> backendPopulatedListeners =
    new LinkedHashSet<BackendPopulatedListener>();
  private LinkedHashSet<IndexModifiedListener> indexListeners =
    new LinkedHashSet<IndexModifiedListener>();
@@ -364,6 +369,20 @@
  }
  /**
   * Informs that a set of backends have been populated.  The method will notify
   * to all the backend populated listeners.
   * @param backends the populated backends.
   */
  public void backendPopulated(Set<BackendDescriptor> backends)
  {
    BackendPopulatedEvent ev = new BackendPopulatedEvent(backends);
    for (BackendPopulatedListener listener : backendPopulatedListeners)
    {
      listener.backendPopulated(ev);
    }
  }
  /**
   * Informs that an index has been modified.  The method will notify to all
   * the index listeners that an index has been modified.
   * @param modifiedIndex the modified index.
@@ -682,6 +701,27 @@
  }
  /**
   * Adds a backend populated listener.
   * @param listener the listener.
   */
  public void addBackendPopulatedListener(BackendPopulatedListener listener)
  {
    backendPopulatedListeners.add(listener);
  }
  /**
   * Removes a backend populated listener.
   * @param listener the listener.
   * @return <CODE>true</CODE> if the listener is found and <CODE>false</CODE>
   * otherwise.
   */
  public boolean removeBackendPopulatedListener(
      BackendPopulatedListener listener)
  {
    return backendPopulatedListeners.remove(listener);
  }
  /**
   * Adds an index modification listener.
   * @param listener the listener.
   */
opends/src/guitools/org/opends/guitools/controlpanel/event/BackendPopulatedEvent.java
New file
@@ -0,0 +1,62 @@
/*
 * 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
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * 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
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  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 2009 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.event;
import java.util.Collections;
import java.util.Set;
import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
/**
 * The event used to notify that a backend has been populated (using import
 * or restore for example).
 *
 */
public class BackendPopulatedEvent
{
  private Set<BackendDescriptor> backends;
  /**
   * The constructor of the event.
   * @param backends the set of populated backends.
   */
  public BackendPopulatedEvent(Set<BackendDescriptor> backends)
  {
    this.backends = Collections.unmodifiableSet(backends);
  }
  /**
   * Returns the set of populated backends.
   * @return the set of populated backends.
   */
  public Set<BackendDescriptor> getBackends()
  {
    return backends;
  }
}
opends/src/guitools/org/opends/guitools/controlpanel/event/BackendPopulatedListener.java
New file
@@ -0,0 +1,42 @@
/*
 * 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
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * 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
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  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 2009 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.event;
/**
 * The listeners that receive notifications when a set of backends are
 * populated.
 *
 */
public interface BackendPopulatedListener
{
  /**
   * Method called when a set of backends are populated.
   * @param ev the event notifying that a set of backends have been populated.
   */
  public void backendPopulated(BackendPopulatedEvent ev);
}
opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
@@ -72,6 +72,7 @@
import javax.swing.event.TreeModelListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import org.opends.admin.ads.util.ApplicationTrustManager;
@@ -84,6 +85,8 @@
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
import org.opends.guitools.controlpanel.datamodel.IndexDescriptor;
import org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
import org.opends.guitools.controlpanel.event.BackendPopulatedEvent;
import org.opends.guitools.controlpanel.event.BackendPopulatedListener;
import org.opends.guitools.controlpanel.event.BrowserEvent;
import org.opends.guitools.controlpanel.event.BrowserEventListener;
import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
@@ -109,6 +112,7 @@
 *
 */
public abstract class AbstractBrowseEntriesPanel extends StatusGenericPanel
implements BackendPopulatedListener
{
  private JComboBox baseDNs;
  /**
@@ -239,6 +243,7 @@
    }
    super.setInfo(info);
    treePane.setInfo(info);
    info.addBackendPopulatedListener(this);
  }
  /**
@@ -707,28 +712,26 @@
      {
        treePane.getTree().setRootVisible(displayAll);
        treePane.getTree().setShowsRootHandles(!displayAll);
        boolean isBaseDN = false;
        boolean added = false;
        for (BackendDescriptor backend :
          getInfo().getServerDescriptor().getBackends())
        {
          for (BaseDNDescriptor baseDN : backend.getBaseDns())
          {
            boolean isBaseDN = false;
            if ((theDN != null) && baseDN.getDn().equals(theDN))
            {
              isBaseDN = true;
            }
            String dn = Utilities.unescapeUtf8(baseDN.getDn().toString());
            if (displayAll)
            if (displayAll || isBaseDN)
            {
              controller.addSuffix(dn, null);
            }
            else if (s.equals(dn))
            {
              controller.addSuffix(dn, null);
              added = true;
            }
          }
        }
        if (!isBaseDN && !displayAll)
        if (!added && !displayAll)
        {
          BasicNode rootNode =
            (BasicNode)controller.getTree().getModel().getRoot();
@@ -840,6 +843,103 @@
   */
  protected abstract Component createMainPanel();
  /**
   * {@inheritDoc}
   */
  public void backendPopulated(BackendPopulatedEvent ev)
  {
    if (controller.getConfigurationConnection() != null)
    {
      boolean displayAll = false;
      boolean errorOccurred = false;
      DN theDN = null;
      String s = getBaseDN();
      if (s != null)
      {
        displayAll = s.equals(ALL_BASE_DNS);
        if (!displayAll)
        {
          try
          {
            theDN = DN.decode(s);
          }
          catch (Throwable t)
          {
            errorOccurred = true;
          }
        }
      }
      else
      {
        errorOccurred = true;
      }
      if (!errorOccurred)
      {
        treePane.getTree().setRootVisible(displayAll);
        treePane.getTree().setShowsRootHandles(!displayAll);
        BasicNode rootNode =
          (BasicNode)controller.getTree().getModel().getRoot();
        boolean isSubordinate = false;
        for (BackendDescriptor backend : ev.getBackends())
        {
          for (BaseDNDescriptor baseDN : backend.getBaseDns())
          {
            boolean isBaseDN = false;
            if ((theDN != null) && baseDN.getDn().equals(theDN))
            {
              isBaseDN = true;
            }
            else if ((theDN != null) && baseDN.getDn().isAncestorOf(theDN))
            {
              isSubordinate = true;
            }
            String dn = Utilities.unescapeUtf8(baseDN.getDn().toString());
            if (displayAll || isBaseDN)
            {
              try
              {
                if (!controller.hasSuffix(dn))
                {
                  controller.addSuffix(dn, null);
                }
                else
                {
                  int index = controller.findChildNode(rootNode, dn);
                  if (index >= 0)
                  {
                    TreeNode node = rootNode.getChildAt(index);
                    if (node != null)
                    {
                      TreePath path = new TreePath(
                          controller.getTreeModel().getPathToRoot(node));
                      controller.startRefresh(
                          controller.getNodeInfoFromPath(path));
                    }
                  }
                }
              }
              catch (IllegalArgumentException iae)
              {
                // The suffix node exists but is not a suffix node.
                // Simply log a message.
                LOG.log(Level.WARNING, "Suffix: "+dn+
                    " added as a non suffix node. Exception: "+iae, iae);
              }
            }
          }
        }
        if (isSubordinate)
        {
          if (controller.findChildNode(rootNode, s) == -1)
          {
            controller.addNodeUnderRoot(s);
          }
        }
      }
    }
  }
  /**
   * {@inheritDoc}
   */
@@ -1322,12 +1422,13 @@
          treePane.getTree().setShowsRootHandles(!displayAll);
          if (s != null)
          {
            boolean isBaseDN = false;
            boolean added = false;
            for (BackendDescriptor backend :
              getInfo().getServerDescriptor().getBackends())
            {
              for (BaseDNDescriptor baseDN : backend.getBaseDns())
              {
                boolean isBaseDN = false;
                String dn = Utilities.unescapeUtf8(baseDN.getDn().toString());
                if ((theDN != null) && baseDN.getDn().equals(theDN))
                {
@@ -1337,11 +1438,12 @@
                {
                  try
                  {
                    if (!controller.hasSuffix(dn))
                    if (displayAll || isBaseDN)
                    {
                      if (displayAll || isBaseDN)
                      if (!controller.hasSuffix(dn))
                      {
                        controller.addSuffix(dn, null);
                        added = true;
                      }
                    }
                  }
@@ -1354,7 +1456,7 @@
                  }
                }
              }
              if (!isBaseDN && !displayAll)
              if (!added && !displayAll)
              {
                BasicNode rootNode =
                  (BasicNode)controller.getTree().getModel().getRoot();
opends/src/guitools/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.ui;
@@ -53,6 +53,7 @@
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
import org.opends.guitools.controlpanel.event.BrowseActionListener;
import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
@@ -748,6 +749,23 @@
        lastException = t;
        state = State.FINISHED_WITH_ERROR;
      }
      HashSet<BackendDescriptor> backends = new HashSet<BackendDescriptor>();
      for (BackendDescriptor backend :
        getInfo().getServerDescriptor().getBackends())
      {
        for (String backendID : getBackends())
        {
          if (backendID.equalsIgnoreCase(backend.getBackendID()))
          {
            backends.add(backend);
            break;
          }
        }
      }
      if (!backends.isEmpty())
      {
        getInfo().backendPopulated(backends);
      }
    }
    /**
opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.ui;
@@ -416,6 +416,23 @@
        lastException = t;
        state = State.FINISHED_WITH_ERROR;
      }
      HashSet<BackendDescriptor> backends = new HashSet<BackendDescriptor>();
      for (BackendDescriptor backend :
        getInfo().getServerDescriptor().getBackends())
      {
        for (String backendID : getBackends())
        {
          if (backendID.equalsIgnoreCase(backend.getBackendID()))
          {
            backends.add(backend);
            break;
          }
        }
      }
      if (!backends.isEmpty())
      {
        getInfo().backendPopulated(backends);
      }
    }
    /**