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 46: Line 46:
 
== See Also: ==
 
== See Also: ==
 
   
 
   
[[FAQ_How_do_I_use_a_model_reconciler%3F]]
+
[[FAQ How do I use a model reconciler%3F]]
  
[[FAQ_Language_integration_phase_4%3A_What_are_the_finishing_touches%3F]]
+
[[FAQ Language integration phase 4: What are the finishing touches?]]
  
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+
{{Template: FAQ_Tagline}}

Revision as of 08:05, 17 January 2007

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&#151;code added or removed&#151;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.

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.

Back to the top