Пример #1
0
 @Override
 public boolean select(Viewer viewer, Object parentElement, Object element) {
   if (element instanceof OutlineNode) {
     OutlineNode n = (OutlineNode) element;
     // No file name is either error (type=0) or something like NDDL
     if (n.getFileName() == null) return n.getType() != null;
     return n.getFileName().endsWith(getFileName());
   }
   return false;
 }
Пример #2
0
  /**
   * Focuses the editor to the text of the selected item.
   *
   * @param event the selection event
   */
  @Override
  public void selectionChanged(SelectionChangedEvent event) {
    super.selectionChanged(event);
    ISelection selection = event.getSelection();
    if (selection.isEmpty()) {
      editor.resetHighlightRange();
    } else {
      OutlineNode node = (OutlineNode) ((IStructuredSelection) selection).getFirstElement();
      IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());

      Position position = computePosition(node.getAst(), doc);
      if (position != null) {
        try {
          editor.setHighlightRange(position.getOffset(), position.getLength(), true);
          editor.getViewer().revealRange(position.getOffset(), position.getLength());
        } catch (IllegalArgumentException x) {
          editor.resetHighlightRange();
        }
      } else {
        editor.resetHighlightRange();
      }
    }
  }