/** Moves the outline view to show the element where the cursor in the text editor is placed. */
  public void selectionChanged(IWorkbenchPart part, ISelection selection) {

    if (selection instanceof ITextSelection) {
      ITextSelection textSelection = (ITextSelection) selection;
      int start = textSelection.getOffset();
      int length = textSelection.getLength();

      JsonTreeNode element = fContentProvider.findNearestElement(start, length);
      if (element != null) {
        element.setTextSelection(true);
        getTreeViewer().reveal(element);
        TreeSelection treeSelection = new TreeSelection(new TreePath(new Object[] {element}));
        getTreeViewer().setSelection(treeSelection);
      }
    }
  }
  /** Selects the text in the editor associated with the item selected in the outline view tree. */
  public void selectionChanged(SelectionChangedEvent event) {

    ISelection selection = event.getSelection();

    if (selection.isEmpty()) fTextEditor.resetHighlightRange();
    else {
      JsonTreeNode jsonTreeNode =
          (JsonTreeNode) ((IStructuredSelection) selection).getFirstElement();
      if (jsonTreeNode.isTextSelection()) {
        jsonTreeNode.setTextSelection(false);
        return;
      }

      int start = jsonTreeNode.getStart();
      int length = jsonTreeNode.getLength();
      try {
        fTextEditor.selectAndReveal(start, length);
      } catch (IllegalArgumentException x) {
        fTextEditor.resetHighlightRange();
      }
    }
  }