/**
  * 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());
 }
Exemplo n.º 2
0
  /**
   * 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 void updateTableModel(BackendDescriptor backend) {
   tableModel.setData(new HashSet<AbstractIndexDescriptor>(backend.getVLVIndexes()), getInfo());
 }