Class AbstractTemplatesPage

All Implemented Interfaces:
IPage, IPageBookViewPage, ITemplatesPage, ITemplatesPageExtension

public abstract class AbstractTemplatesPage extends Page implements ITemplatesPage, ITemplatesPageExtension
Abstract default implementation for ITemplatesPage.

Clients who are defining an editor may elect to provide a corresponding templates page. This templates page will be presented to the user via the Templates View (the user decides whether their workbench window contains this view) whenever that editor is active. This class should be subclassed by clients.

Internally, a AbstractTemplatesPage uses the template store to display different categories. A link to editor mode on the templates page allows to filtering of the categories to only that are supported in this context.

  • Constructor Details

    • AbstractTemplatesPage

      protected AbstractTemplatesPage(ITextEditor editor, ISourceViewer viewer)
      Creates a new templates page.
      editor - the editor
      viewer - the source viewer
  • Method Details

    • createControl

      public void createControl(Composite ancestor)
      Description copied from interface: IPage
      Creates the SWT control for this page under the given parent control.

      Clients should not call this method (the workbench calls this method when it needs to, which may be never).

      Specified by:
      createControl in interface IPage
      Specified by:
      createControl in class Page
      ancestor - the parent control
    • setFocus

      public void setFocus()
      Description copied from class: Page
      The Page implementation of this IPage method does nothing. Subclasses must implement.
      Specified by:
      setFocus in interface IPage
      Specified by:
      setFocus in class Page
    • getControl

      public Control getControl()
      Description copied from class: Page
      The Page implementation of this IPage method returns null. Subclasses must reimplement.
      Specified by:
      getControl in interface IPage
      Specified by:
      getControl in class Page
      the SWT control for this page, or null if this page does not have a control
    • dispose

      public void dispose()
      Description copied from class: Page
      The Page implementation of this IPage method disposes of this page's control (if it has one and it has not already been disposed). Subclasses may extend.
      Specified by:
      dispose in interface IPage
      dispose in class Page
    • getImage

      protected Image getImage(Template template)
      Returns the image to be used for the given template.

      Clients can override to provide a different image.

      template - the template
      the image, must not be disposed
    • editTemplate

      protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable)
      Creates and opens a dialog to edit the given template.

      Subclasses may override this method to provide a custom dialog.

      template - the template being edited
      edit - true if the dialog allows editing
      isNameModifiable - true if the template name may be modified
      the created or modified template, or null if the editing failed
    • updatePatternViewer

      protected void updatePatternViewer(Template template)
      Update the pattern viewer to show the current template.

      Subclasses can extend this method to update their own pattern viewer.

      template - the template
    • createPatternViewer

      protected SourceViewer createPatternViewer(Composite parent)
      Creates, configures and returns a source viewer to present the template pattern on the templates page.

      Clients may override to provide a custom source viewer featuring e.g. syntax coloring.

      parent - the parent control
      a configured source viewer
    • getPatternViewer

      protected final SourceViewer getPatternViewer()
      Returns the pattern viewer created by createPatternViewer()
      the pattern viewer
    • insertTemplate

      protected abstract void insertTemplate(Template template, IDocument document)
      Inserts the given template into the editor.
      template - the template
      document - the document
    • getContextTypeRegistry

      protected abstract ContextTypeRegistry getContextTypeRegistry()
      Returns the context type registry used in this page.
      the context type registry
    • getTemplateStore

      public abstract TemplateStore getTemplateStore()
      Returns the template store used in this page.
      Specified by:
      getTemplateStore in interface ITemplatesPageExtension
      the template store
      3.6 public, before it was protected
    • getTemplatePreferenceStore

      protected abstract IPreferenceStore getTemplatePreferenceStore()
      Returns the preference store used to create the template store returned by getTemplateStore().
      the preference store
    • getPreferencePageId

      protected abstract String getPreferencePageId()
      Returns the Template preference page id to be used by this template page.
      id the preference page if or null if none exists
    • getContextTypeIds

      protected abstract String[] getContextTypeIds(IDocument document, int offset)
      Returns the context type ids supported at the given document offset.
      document - the document
      offset - the offset
      an array of supported context ids
    • isValidTemplate

      protected abstract boolean isValidTemplate(IDocument document, Template template, int offset, int length)
      Checks whether the given template is valid for the document at the given offset and length.
      document - the document
      template - the template
      offset - the offset
      length - the length
      true if the template is valid
    • getSelectedTemplates

      public TemplatePersistenceData[] getSelectedTemplates()
      Returns the currently selected templates
      Specified by:
      getSelectedTemplates in interface ITemplatesPageExtension
      selected templates
      3.6 public, before it was private