/** Adds a pop up menu. */
  private void addPopupMenu() {
    final JPopupMenu popup = new JPopupMenu();
    JMenuItem menuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_NEW_INDEX_MENU.get());
    menuItem.addActionListener(
        new ActionListener() {
          /** {@inheritDoc} */
          public void actionPerformed(ActionEvent ev) {
            newIndexClicked();
          }
        });
    popup.add(menuItem);
    menuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_NEW_VLV_INDEX_MENU.get());
    menuItem.addActionListener(
        new ActionListener() {
          /** {@inheritDoc} */
          public void actionPerformed(ActionEvent ev) {
            newVLVIndexClicked();
          }
        });
    popup.add(menuItem);
    popup.add(new JSeparator());
    deleteMenuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_DELETE_INDEX_MENU.get());
    deleteMenuItem.addActionListener(
        new ActionListener() {
          /** {@inheritDoc} */
          public void actionPerformed(ActionEvent ev) {
            deleteClicked();
          }
        });
    popup.add(deleteMenuItem);
    deleteMenuItem.setEnabled(false);

    ((CustomTree) treePane.getTree()).setPopupMenu(popup);
  }
 /** Updates the contents of the right panel. */
 private void updateEntryPane() {
   ViewPositions pos = Utilities.getViewPositions(entryPane);
   TreePath[] paths = treePane.getTree().getSelectionPaths();
   TreePath path = null;
   if ((paths != null) && (paths.length == 1)) {
     path = paths[0];
   }
   lastIndexTreePath = path;
   if (path != null) {
     Object node = path.getLastPathComponent();
     if (node instanceof IndexTreeNode) {
       entryPane.updateStandardIndex(((IndexTreeNode) node).getIndex());
     } else if (node instanceof VLVIndexTreeNode) {
       entryPane.updateVLVIndex(((VLVIndexTreeNode) node).getIndex());
     } else if (node == standardIndexes) {
       String backendName = (String) backends.getSelectedItem();
       entryPane.updateBackendIndexes(backendName);
     } else if (node == vlvIndexes) {
       String backendName = (String) backends.getSelectedItem();
       entryPane.updateBackendVLVIndexes(backendName);
     } else {
       entryPane.displayVoid();
     }
   } else {
     if ((paths != null) && (paths.length > 1)) {
       entryPane.displayMultiple();
     } else {
       entryPane.displayVoid();
     }
   }
   Utilities.updateViewPositions(pos);
 }
 private void deleteClicked() {
   ArrayList<Message> errors = new ArrayList<Message>();
   TreePath[] paths = treePane.getTree().getSelectionPaths();
   ArrayList<AbstractIndexDescriptor> indexesToDelete = new ArrayList<AbstractIndexDescriptor>();
   ArrayList<String> indexesNames = new ArrayList<String>();
   if (paths != null) {
     for (TreePath path : paths) {
       Object node = path.getLastPathComponent();
       if (node instanceof IndexTreeNode) {
         indexesToDelete.add(((IndexTreeNode) node).getIndex());
       } else if (node instanceof VLVIndexTreeNode) {
         indexesToDelete.add(((VLVIndexTreeNode) node).getIndex());
       }
     }
   } else {
     errors.add(ERR_CTRL_PANEL_NO_INDEX_SELECTED.get());
   }
   for (AbstractIndexDescriptor index : indexesToDelete) {
     indexesNames.add(index.getName());
   }
   String nameLabel = Utilities.getStringFromCollection(indexesNames, ", ");
   String backendName = indexesToDelete.get(0).getBackend().getBackendID();
   if (errors.isEmpty()) {
     ProgressDialog dlg =
         new ProgressDialog(
             Utilities.createFrame(),
             Utilities.getParentDialog(this),
             INFO_CTRL_PANEL_DELETE_INDEXES_TITLE.get(),
             getInfo());
     DeleteIndexTask newTask = new DeleteIndexTask(getInfo(), dlg, indexesToDelete);
     for (Task task : getInfo().getTasks()) {
       task.canLaunch(newTask, errors);
     }
     if (errors.isEmpty()) {
       if (displayConfirmationDialog(
           INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(),
           INFO_CTRL_PANEL_CONFIRMATION_INDEXES_DELETE_DETAILS.get(nameLabel, backendName))) {
         launchOperation(
             newTask,
             INFO_CTRL_PANEL_DELETING_INDEXES_SUMMARY.get(),
             INFO_CTRL_PANEL_DELETING_INDEXES_COMPLETE.get(),
             INFO_CTRL_PANEL_DELETING_INDEXES_SUCCESSFUL.get(nameLabel, backendName),
             ERR_CTRL_PANEL_DELETING_INDEXES_ERROR_SUMMARY.get(),
             ERR_CTRL_PANEL_DELETING_INDEXES_ERROR_DETAILS.get(nameLabel),
             null,
             dlg);
         dlg.setVisible(true);
       }
     }
   }
   if (!errors.isEmpty()) {
     displayErrorDialog(errors);
   }
 }
  /** {@inheritDoc} */
  private Component createSplitPane() {
    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    pane.setOpaque(true); // content panes must be opaque

    treePane = new TreePanel();
    Utilities.setBorder(treePane, new EmptyBorder(10, 0, 10, 0));

    entryPane = new IndexBrowserRightPanel();
    treeScroll = Utilities.createScrollPane(treePane);

    entryPane.addIndexSelectionListener(
        new IndexSelectionListener() {
          /** {@inheritDoc} */
          public void indexSelected(IndexSelectionEvent ev) {
            AbstractIndexDescriptor index = ev.getIndex();
            TreeNode parentNode;
            if (index instanceof IndexDescriptor) {
              parentNode = standardIndexes;
            } else {
              parentNode = vlvIndexes;
            }
            DefaultTreeModel model = (DefaultTreeModel) treePane.getTree().getModel();
            int n = model.getChildCount(parentNode);
            for (int i = 0; i < n; i++) {
              AbstractIndexTreeNode node = (AbstractIndexTreeNode) model.getChild(parentNode, i);
              if (node.getName().equals(index.getName())) {
                TreePath newSelectionPath = new TreePath(node.getPath());
                treePane.getTree().setSelectionPath(newSelectionPath);
                treePane.getTree().scrollPathToVisible(newSelectionPath);
                break;
              }
            }
          }
        });

    //  Create a split pane
    pane.setLeftComponent(treeScroll);
    pane.setRightComponent(entryPane);
    pane.setResizeWeight(0.0);

    treePane
        .getTree()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              /** {@inheritDoc} */
              public void valueChanged(TreeSelectionEvent ev) {
                if (!ignoreSelectionEvents) {
                  TreePath[] paths = treePane.getTree().getSelectionPaths();

                  if (entryPane.mustCheckUnsavedChanges()) {
                    ignoreSelectionEvents = true;
                    treePane.getTree().setSelectionPath(lastIndexTreePath);
                    switch (entryPane.checkUnsavedChanges()) {
                      case DO_NOT_SAVE:
                        break;
                      case SAVE:
                        break;
                      case CANCEL:
                        ignoreSelectionEvents = false;
                        return;
                    }
                    if (paths != null) {
                      treePane.getTree().setSelectionPaths(paths);
                    } else {
                      treePane.getTree().clearSelection();
                    }
                    ignoreSelectionEvents = false;
                  }

                  boolean deletableElementsSelected = false;
                  boolean nonDeletableElementsSelected = false;
                  if (paths != null) {
                    for (TreePath path : paths) {
                      Object node = path.getLastPathComponent();
                      if (node instanceof IndexTreeNode) {
                        IndexDescriptor index = ((IndexTreeNode) node).getIndex();
                        if (index.isDatabaseIndex()) {
                          nonDeletableElementsSelected = true;
                        } else {
                          deletableElementsSelected = true;
                        }
                      } else if (node instanceof VLVIndexTreeNode) {
                        deletableElementsSelected = true;
                      }
                    }
                  }
                  deleteMenuItem.setEnabled(
                      deletableElementsSelected && !nonDeletableElementsSelected);
                  updateEntryPane();
                }
              }
            });
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Tree root");
    for (DefaultMutableTreeNode node : categoryNodes) {
      root.add(node);
    }
    DefaultTreeModel model = new DefaultTreeModel(root);
    JTree tree = treePane.getTree();
    tree.setModel(model);
    tree.setRootVisible(false);
    tree.setVisibleRowCount(20);
    tree.expandPath(new TreePath(root));
    tree.setCellRenderer(new IndexTreeCellRenderer());
    addPopupMenu();

    treeScroll.setPreferredSize(
        new Dimension(
            2 * treeScroll.getPreferredSize().width, 8 * treeScroll.getPreferredSize().height));
    entryPane.setBorder(getRightPanelBorder());
    entryPane.setPreferredSize(
        new Dimension(
            (treeScroll.getPreferredSize().width * 5) / 2, treeScroll.getPreferredSize().height));
    pane.setDividerLocation(treeScroll.getPreferredSize().width);
    entryPane.displayVoid();
    return pane;
  }