Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How do I create an Outline view for my own language editor?"

(See Also:)
Line 43: Line 43:
 
When the user selects a node in the Outline view, the editor should change selection
 
When the user selects a node in the Outline view, the editor should change selection
 
to the selected element and make it visible.
 
to the selected element and make it visible.
 +
 +
When https://bugs.eclipse.org/bugs/show_bug.cgi?id=507205 is fixed, a recommended way would be to rely on the Common Navigator Framework in order to implement Tree-based navigation outline pages.
  
 
== See Also: ==
 
== See Also: ==

Revision as of 05:08, 8 November 2016

The Outline view is not generated by the editor framework. In fact, this view is offered by the org.eclipse.ui.views plug-in. When the user changes editors, your editor will be asked to provide an IContentOutlinePage adapter for an Outline view. This is how you could implement your outline viewer:

   public Object getAdapter(Class required) {
      if (IContentOutlinePage.class.equals(required)) {
         if (myOutlinePage == null) {
            myOutlinePage = new CoolLanguageContentOutlinePage(
                           getDocumentProvider(), this);
            myOutlinePage.setInput(getEditorInput());
         }
         return myOutlinePage;
      }
      return super.getAdapter(required);
   }

Most programming languages are inherently hierarchical. Therefore, to show the content outline of a certain program file, most editors deploy a tree. If you think that a tree is the most appropriate way to show the outline of your programs, you should consider subclassing from class ContentOutlinePage in the org.eclipse.ui.views.contentoutline package. This class already sets you up with a TreeViewer, and all you need to provide are a content provider, a label provider, and the input:

   public void createControl(Composite parent) {
      super.createControl(parent);
      TreeViewer viewer= getTreeViewer();
      viewer.setContentProvider(new MyContentProvider());
      viewer.setLabelProvider(new MyLabelProvider());
      viewer.addSelectionChangedListener(this);
      viewer.setInput(myInput);
   }

You will want to update the selection in your Outline view when the cursor is moved in the editor. Similarly, if the structure of the program changed—code added or removed—the outline has to be updated. This is typically performed with a JFace text model reconciler.

When the user selects a node in the Outline view, the editor should change selection to the selected element and make it visible.

When https://bugs.eclipse.org/bugs/show_bug.cgi?id=507205 is fixed, a recommended way would be to rely on the Common Navigator Framework in order to implement Tree-based navigation outline pages.

See Also:

FAQ How do I use a model reconciler?

FAQ Language integration phase 4: What are the finishing touches?


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.