private void newVLVIndexClicked() {
   if (newVLVIndexPanel == null) {
     newVLVIndexPanel =
         new NewVLVIndexPanel(
             (String) backends.getSelectedItem(), Utilities.getParentDialog(this));
     newVLVIndexPanel.setInfo(getInfo());
     newVLVIndexDialog = new GenericDialog(null, newVLVIndexPanel);
     Utilities.centerGoldenMean(newVLVIndexDialog, Utilities.getParentDialog(this));
     newVLVIndexPanel.addConfigurationElementCreatedListener(
         new ConfigurationElementCreatedListener() {
           /** {@inheritDoc} */
           public void elementCreated(ConfigurationElementCreatedEvent ev) {
             Object o = ev.getConfigurationObject();
             if (o instanceof AbstractIndexDescriptor) {
               lastCreatedIndex = (AbstractIndexDescriptor) o;
             }
           }
         });
   } else if (!newVLVIndexDialog.isVisible()) {
     String backendID = (String) backends.getSelectedItem();
     for (BackendDescriptor backend : getInfo().getServerDescriptor().getBackends()) {
       if (backend.getBackendID().equalsIgnoreCase(backendID)) {
         newVLVIndexPanel.update(backend);
         break;
       }
     }
   }
   newVLVIndexDialog.setVisible(true);
 }
 /**
  * Constructor of the task.
  *
  * @param info the control panel information.
  * @param dlg the progress dialog where the task progress will be displayed.
  * @param tasks the tasks to be canceled.
  */
 public CancelTaskTask(ControlPanelInfo info, ProgressDialog dlg, List<TaskEntry> tasks) {
   super(info, dlg);
   backendSet = new HashSet<String>();
   for (BackendDescriptor backend : info.getServerDescriptor().getBackends()) {
     backendSet.add(backend.getBackendID());
   }
   this.tasks = new ArrayList<TaskEntry>(tasks);
 }
  /**
   * Refresh the contents of the panel with the provided server descriptor.
   *
   * @param desc the server descriptor.
   */
  private void refreshContents(final ServerDescriptor desc) {
    super.updateIndexMap(desc, hmIndexes);
    filterIndexes(hmIndexes);

    updateBaseDNComboBoxModel((DefaultComboBoxModel) baseDNs.getModel(), desc);

    // Check that all backends
    boolean allDisabled = false;
    for (BackendDescriptor backend : desc.getBackends()) {
      if (displayBackend(backend)) {
        if (backend.isEnabled()) {
          allDisabled = false;
          break;
        }
      }
    }
    if (!allDisabled) {
      updateErrorPaneAndOKButtonIfAuthRequired(
          desc,
          isLocal()
              ? INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_FOR_DISABLE_BACKEND.get()
              : INFO_CTRL_PANEL_CANNOT_CONNECT_TO_REMOTE_DETAILS.get(desc.getHostname()));
    }
    SwingUtilities.invokeLater(
        new Runnable() {
          /** {@inheritDoc} */
          public void run() {
            ViewPositions pos;
            JScrollPane scroll = Utilities.getContainingScroll(RebuildIndexPanel.this);
            if (scroll != null) {
              pos = Utilities.getViewPositions(scroll);
            } else {
              pos = Utilities.getViewPositions(RebuildIndexPanel.this);
            }

            boolean comboVisible = baseDNs.getModel().getSize() > 0;
            baseDNs.setVisible(comboVisible);
            lNoBaseDNsFound.setVisible(!comboVisible);
            addRemove.getAvailableList().repaint();
            addRemove.getSelectedList().repaint();

            Utilities.updateViewPositions(pos);
            if (!desc.isLocal()) {
              displayErrorMessage(
                  INFO_CTRL_PANEL_SERVER_REMOTE_SUMMARY.get(),
                  INFO_CTRL_PANEL_SERVER_MUST_BE_LOCAL_REBUILD_INDEX_SUMMARY.get());
              setEnabledOK(false);
            } else {
              displayMainPanel();
              setEnabledOK(true);
            }
          }
        });
  }
  /** Reads configuration information from the configuration files. */
  public void readConfiguration() {
    List<OpenDsException> ex = new ArrayList<OpenDsException>();
    Set<ConnectionHandlerDescriptor> ls = new HashSet<ConnectionHandlerDescriptor>();
    Set<BackendDescriptor> bs = new HashSet<BackendDescriptor>();
    Set<DN> as = new HashSet<DN>();
    try {
      DirectoryServer.getInstance().initializeConfiguration();

      if (mustReadSchema()) {
        try {
          readSchema();
          if (getSchema() != null) {
            // Update the schema: so that when we call the server code the
            // latest schema read on the server we are managing is used.
            DirectoryServer.setSchema(getSchema());
          }
        } catch (OpenDsException oe) {
          ex.add(oe);
        }
      }

      // Get the Directory Server configuration handler and use it.
      RootCfg root = ServerManagementContext.getInstance().getRootConfiguration();
      try {
        AdministrationConnectorCfg adminConnector = root.getAdministrationConnector();
        this.adminConnector = getConnectionHandler(adminConnector);
      } catch (ConfigException ce) {
        ex.add(ce);
      }
      for (String connHandler : root.listConnectionHandlers()) {
        try {
          ConnectionHandlerCfg connectionHandler = root.getConnectionHandler(connHandler);
          ls.add(getConnectionHandler(connectionHandler, connHandler));
        } catch (OpenDsException oe) {
          ex.add(oe);
        }
      }
      isSchemaEnabled = root.getGlobalConfiguration().isCheckSchema();

      for (String backendName : root.listBackends()) {
        try {
          BackendCfg backend = root.getBackend(backendName);
          Set<BaseDNDescriptor> baseDNs = new HashSet<BaseDNDescriptor>();
          for (DN dn : backend.getBaseDN()) {
            BaseDNDescriptor baseDN =
                new BaseDNDescriptor(BaseDNDescriptor.Type.NOT_REPLICATED, dn, null, -1, -1, -1);
            baseDNs.add(baseDN);
          }
          Set<IndexDescriptor> indexes = new HashSet<IndexDescriptor>();
          Set<VLVIndexDescriptor> vlvIndexes = new HashSet<VLVIndexDescriptor>();
          BackendDescriptor.Type type;
          if (backend instanceof LocalDBBackendCfg) {
            type = BackendDescriptor.Type.LOCAL_DB;
            LocalDBBackendCfg db = (LocalDBBackendCfg) backend;
            try {
              for (String indexName : db.listLocalDBIndexes()) {
                LocalDBIndexCfg index = db.getLocalDBIndex(indexName);
                indexes.add(
                    new IndexDescriptor(
                        index.getAttribute().getNameOrOID(),
                        index.getAttribute(),
                        null,
                        index.getIndexType(),
                        index.getIndexEntryLimit()));
              }
            } catch (OpenDsException oe) {
              ex.add(oe);
            }
            indexes.add(new IndexDescriptor("dn2id", null, null, new TreeSet<IndexType>(), -1));
            indexes.add(
                new IndexDescriptor("id2children", null, null, new TreeSet<IndexType>(), -1));
            indexes.add(
                new IndexDescriptor("id2subtree", null, null, new TreeSet<IndexType>(), -1));

            try {
              for (String vlvIndexName : db.listLocalDBVLVIndexes()) {
                LocalDBVLVIndexCfg index = db.getLocalDBVLVIndex(vlvIndexName);
                String s = index.getSortOrder();
                List<VLVSortOrder> sortOrder = getVLVSortOrder(s);
                vlvIndexes.add(
                    new VLVIndexDescriptor(
                        index.getName(),
                        null,
                        index.getBaseDN(),
                        index.getScope(),
                        index.getFilter(),
                        sortOrder,
                        index.getMaxBlockSize()));
              }
            } catch (OpenDsException oe) {
              ex.add(oe);
            }
          } else if (backend instanceof LDIFBackendCfg) {
            type = BackendDescriptor.Type.LDIF;
          } else if (backend instanceof MemoryBackendCfg) {
            type = BackendDescriptor.Type.MEMORY;
          } else if (backend instanceof BackupBackendCfg) {
            type = BackendDescriptor.Type.BACKUP;
          } else if (backend instanceof MonitorBackendCfg) {
            type = BackendDescriptor.Type.MONITOR;
          } else if (backend instanceof TaskBackendCfg) {
            type = BackendDescriptor.Type.TASK;
          } else {
            type = BackendDescriptor.Type.OTHER;
          }
          BackendDescriptor desc =
              new BackendDescriptor(
                  backend.getBackendId(),
                  baseDNs,
                  indexes,
                  vlvIndexes,
                  -1,
                  backend.isEnabled(),
                  type);
          for (AbstractIndexDescriptor index : indexes) {
            index.setBackend(desc);
          }
          for (AbstractIndexDescriptor index : vlvIndexes) {
            index.setBackend(desc);
          }

          bs.add(desc);
        } catch (OpenDsException oe) {
          ex.add(oe);
        }
      }

      boolean isReplicationSecure = false;
      try {
        CryptoManagerCfg cryptoManager = root.getCryptoManager();
        isReplicationSecure = cryptoManager.isSSLEncryption();
      } catch (OpenDsException oe) {
        ex.add(oe);
      }

      replicationPort = -1;
      ReplicationSynchronizationProviderCfg sync = null;
      try {
        sync =
            (ReplicationSynchronizationProviderCfg)
                root.getSynchronizationProvider("Multimaster Synchronization");
      } catch (OpenDsException oe) {
        // Ignore this one
      }
      if (sync != null) {
        try {
          if (sync.isEnabled() && sync.hasReplicationServer()) {
            ReplicationServerCfg replicationServer = sync.getReplicationServer();
            if (replicationServer != null) {
              replicationPort = replicationServer.getReplicationPort();
              ConnectionHandlerDescriptor.Protocol protocol =
                  isReplicationSecure
                      ? ConnectionHandlerDescriptor.Protocol.REPLICATION_SECURE
                      : ConnectionHandlerDescriptor.Protocol.REPLICATION;
              Set<CustomSearchResult> emptySet = Collections.emptySet();
              ConnectionHandlerDescriptor connHandler =
                  new ConnectionHandlerDescriptor(
                      new HashSet<InetAddress>(),
                      replicationPort,
                      protocol,
                      ConnectionHandlerDescriptor.State.ENABLED,
                      "Multimaster Synchronization",
                      emptySet);
              ls.add(connHandler);
            }
          }
          String[] domains = sync.listReplicationDomains();
          if (domains != null) {
            for (String domain2 : domains) {
              ReplicationDomainCfg domain = sync.getReplicationDomain(domain2);
              DN dn = domain.getBaseDN();
              for (BackendDescriptor backend : bs) {
                for (BaseDNDescriptor baseDN : backend.getBaseDns()) {
                  if (baseDN.getDn().equals(dn)) {
                    baseDN.setType(
                        sync.isEnabled()
                            ? BaseDNDescriptor.Type.REPLICATED
                            : BaseDNDescriptor.Type.DISABLED);
                    baseDN.setReplicaID(domain.getServerId());
                  }
                }
              }
            }
          }
        } catch (OpenDsException oe) {
          ex.add(oe);
        }
      }

      try {
        RootDNCfg rootDN = root.getRootDN();
        String[] rootUsers = rootDN.listRootDNUsers();
        as.clear();
        if (rootUsers != null) {
          for (String rootUser2 : rootUsers) {
            RootDNUserCfg rootUser = rootDN.getRootDNUser(rootUser2);
            as.addAll(rootUser.getAlternateBindDN());
          }
        }
      } catch (OpenDsException oe) {
        ex.add(oe);
      }
    } catch (OpenDsException oe) {
      ex.add(oe);
    } catch (final Throwable t) {
      LOG.log(Level.WARNING, "Error reading configuration: " + t, t);
      OfflineUpdateException oue =
          new OfflineUpdateException(ERR_READING_CONFIG_LDAP.get(t.getMessage().toString()), t);
      ex.add(oue);
    }

    if (ex.size() > 0) {
      if (environmentSettingException != null) {
        ex.add(0, environmentSettingException);
      }
    }

    for (OpenDsException oe : ex) {
      LOG.log(Level.WARNING, "Error reading configuration: " + oe, oe);
    }
    exceptions = Collections.unmodifiableList(ex);
    administrativeUsers = Collections.unmodifiableSet(as);
    listeners = Collections.unmodifiableSet(ls);
    backends = Collections.unmodifiableSet(bs);
  }
  /**
   * Repopulates the contents of the tree.
   *
   * @param tree the tree to be repopulated.
   */
  private void repopulateTree(JTree tree) {
    ignoreSelectionEvents = true;

    final Point currentPosition = treeScroll.getViewport().getViewPosition();
    DefaultMutableTreeNode root = getRoot(tree);

    TreePath path = tree.getSelectionPath();
    DefaultMutableTreeNode lastSelectedNode = null;
    if (path != null) {
      lastSelectedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    }
    TreePath newSelectionPath = null;

    BackendDescriptor backend = null;
    String backendName = (String) backends.getSelectedItem();
    if (backendName != null) {
      for (BackendDescriptor b : getInfo().getServerDescriptor().getBackends()) {
        if (b.getBackendID().equalsIgnoreCase(backendName)) {
          backend = b;
          break;
        }
      }
    }

    ArrayList<ArrayList<? extends AbstractIndexTreeNode>> nodes =
        new ArrayList<ArrayList<? extends AbstractIndexTreeNode>>();
    ArrayList<IndexTreeNode> standardIndexNodes = new ArrayList<IndexTreeNode>();
    ArrayList<VLVIndexTreeNode> vlvIndexNodes = new ArrayList<VLVIndexTreeNode>();
    nodes.add(standardIndexNodes);
    nodes.add(vlvIndexNodes);

    if (backend != null) {
      for (IndexDescriptor index : backend.getIndexes()) {
        standardIndexNodes.add(new IndexTreeNode(index.getName(), index));
      }
      for (VLVIndexDescriptor index : backend.getVLVIndexes()) {
        vlvIndexNodes.add(new VLVIndexTreeNode(index.getName(), index));
      }
    }

    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    int i = 0;
    int positionUnderRoot = 0;
    for (DefaultMutableTreeNode parent : categoryNodes) {
      if (nodes.get(i).size() == 0) {
        if (root.getIndex(parent) != -1) {
          model.removeNodeFromParent(parent);
          parent.removeAllChildren();
        }
      } else {
        boolean expand = true;
        if (root.getIndex(parent) == -1) {
          model.insertNodeInto(parent, root, positionUnderRoot);
        } else {
          expand = tree.isExpanded(new TreePath(parent)) || (parent.getChildCount() == 0);
          parent.removeAllChildren();
        }
        for (AbstractIndexTreeNode node : nodes.get(i)) {
          parent.add(node);
          if ((newSelectionPath == null)
              && ((lastSelectedNode != null) || (lastCreatedIndex != null))) {
            if (lastCreatedIndex != null) {
              if ((node instanceof IndexTreeNode)
                  && (lastCreatedIndex instanceof IndexDescriptor)) {
                if (node.getName().equals(lastCreatedIndex.getName())) {
                  newSelectionPath = new TreePath(node.getPath());
                  lastCreatedIndex = null;
                }
              } else if ((node instanceof VLVIndexTreeNode)
                  && (lastCreatedIndex instanceof VLVIndexDescriptor)) {
                if (node.getName().equals(lastCreatedIndex.getName())) {
                  newSelectionPath = new TreePath(node.getPath());
                  lastCreatedIndex = null;
                }
              }
            } else if (node.getName().equals(lastSelectedNode.getUserObject())) {
              newSelectionPath = new TreePath(node.getPath());
            }
          }
        }
        model.nodeStructureChanged(parent);
        if (expand) {
          tree.expandPath(new TreePath(parent.getPath()));
        }
        positionUnderRoot++;
      }
      i++;
    }

    if (newSelectionPath == null) {
      if (firstTreeRepopulate) {
        newSelectionPath = new TreePath(standardIndexes.getPath());
      }
    }
    if (newSelectionPath != null) {
      tree.setSelectionPath(newSelectionPath);
      tree.scrollPathToVisible(newSelectionPath);
    }

    updateEntryPane();

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            if (firstTreeRepopulate) {
              treeScroll.getViewport().setViewPosition(new Point(0, 0));
            } else {
              treeScroll.getViewport().setViewPosition(currentPosition);
            }
          }
        });
    firstTreeRepopulate = false;
    ignoreSelectionEvents = false;
  }
 /** {@inheritDoc} */
 protected boolean displayBackend(BackendDescriptor backend) {
   return !backend.isConfigBackend() && (backend.getType() == BackendDescriptor.Type.LOCAL_DB);
 }
 /**
  * The event will contain all the indexes in a given backend.
  *
  * @param backend the backend whose indexes have been modified.
  */
 public IndexModifiedEvent(BackendDescriptor backend) {
   this.modifiedIndexes.addAll(backend.getIndexes());
   this.modifiedIndexes.addAll(backend.getVLVIndexes());
 }
 /** {@inheritDoc} */
 protected void updateTableModel(BackendDescriptor backend) {
   tableModel.setData(new HashSet<AbstractIndexDescriptor>(backend.getVLVIndexes()), getInfo());
 }