Class AbstractTemplatesPage
- All Implemented Interfaces:
IPage
,IPageBookViewPage
,ITemplatesPage
,ITemplatesPageExtension
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.
- Since:
- 3.4
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractTemplatesPage
(ITextEditor editor, ISourceViewer viewer) Creates a new templates page. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createControl
(Composite ancestor) Creates the SWT control for this page under the given parent control.protected SourceViewer
createPatternViewer
(Composite parent) Creates, configures and returns a source viewer to present the template pattern on the templates page.void
dispose()
ThePage
implementation of thisIPage
method disposes of this page's control (if it has one and it has not already been disposed).protected Template
editTemplate
(Template template, boolean edit, boolean isNameModifiable) Creates and opens a dialog to edit the given template.protected abstract String[]
getContextTypeIds
(IDocument document, int offset) Returns the context type ids supported at the given document offset.protected abstract ContextTypeRegistry
Returns the context type registry used in this page.ThePage
implementation of thisIPage
method returnsnull
.protected Image
Returns the image to be used for the given template.protected final SourceViewer
Returns the pattern viewer created by createPatternViewer()protected abstract String
Returns the Template preference page id to be used by this template page.Returns the currently selected templatesprotected abstract IPreferenceStore
Returns the preference store used to create the template store returned bygetTemplateStore()
.abstract TemplateStore
Returns the template store used in this page.protected abstract void
insertTemplate
(Template template, IDocument document) Inserts the given template into the editor.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.void
setFocus()
ThePage
implementation of thisIPage
method does nothing.protected void
updatePatternViewer
(Template template) Update the pattern viewer to show the current template.Methods inherited from class org.eclipse.ui.part.Page
getSite, init, makeContributions, setActionBars
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.ui.part.IPage
setActionBars
Methods inherited from interface org.eclipse.ui.part.IPageBookViewPage
getSite, init
-
Constructor Details
-
AbstractTemplatesPage
Creates a new templates page.- Parameters:
editor
- the editorviewer
- the source viewer
-
-
Method Details
-
createControl
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 interfaceIPage
- Specified by:
createControl
in classPage
- Parameters:
ancestor
- the parent control
-
setFocus
public void setFocus()Description copied from class:Page
ThePage
implementation of thisIPage
method does nothing. Subclasses must implement. -
getControl
Description copied from class:Page
ThePage
implementation of thisIPage
method returnsnull
. Subclasses must reimplement.- Specified by:
getControl
in interfaceIPage
- Specified by:
getControl
in classPage
- Returns:
- 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
ThePage
implementation of thisIPage
method disposes of this page's control (if it has one and it has not already been disposed). Subclasses may extend. -
getImage
Returns the image to be used for the given template.Clients can override to provide a different image.
- Parameters:
template
- the template- Returns:
- the image, must not be disposed
-
editTemplate
Creates and opens a dialog to edit the given template.Subclasses may override this method to provide a custom dialog.
- Parameters:
template
- the template being editededit
-true
if the dialog allows editingisNameModifiable
-true
if the template name may be modified- Returns:
- the created or modified template, or
null
if the editing failed
-
updatePatternViewer
Update the pattern viewer to show the current template.Subclasses can extend this method to update their own pattern viewer.
- Parameters:
template
- the template
-
createPatternViewer
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.
- Parameters:
parent
- the parent control- Returns:
- a configured source viewer
-
getPatternViewer
Returns the pattern viewer created by createPatternViewer()- Returns:
- the pattern viewer
-
insertTemplate
Inserts the given template into the editor.- Parameters:
template
- the templatedocument
- the document
-
getContextTypeRegistry
Returns the context type registry used in this page.- Returns:
- the context type registry
-
getTemplateStore
Returns the template store used in this page.- Specified by:
getTemplateStore
in interfaceITemplatesPageExtension
- Returns:
- the template store
- Since:
- 3.6 public, before it was protected
-
getTemplatePreferenceStore
Returns the preference store used to create the template store returned bygetTemplateStore()
.- Returns:
- the preference store
-
getPreferencePageId
Returns the Template preference page id to be used by this template page.- Returns:
- id the preference page if or
null
if none exists
-
getContextTypeIds
Returns the context type ids supported at the given document offset.- Parameters:
document
- the documentoffset
- the offset- Returns:
- 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.- Parameters:
document
- the documenttemplate
- the templateoffset
- the offsetlength
- the length- Returns:
true
if the template is valid
-
getSelectedTemplates
Returns the currently selected templates- Specified by:
getSelectedTemplates
in interfaceITemplatesPageExtension
- Returns:
- selected templates
- Since:
- 3.6 public, before it was private
-