public abstract class AbstractTextSearchViewPage extends Page implements ISearchResultPage
AbstractTextSearchResult
instances. This class assumes that
the input element set via setInput(ISearchResult,Object)
is a subclass of AbstractTextSearchResult
.
This result page supports a tree and/or a table presentation of search
results. Subclasses can determine which presentations they want to support at
construction time by passing the appropriate flags.
Subclasses must customize the viewers for each presentation with a label
provider and a content provider. elementsChanged()
and clear()
methods.Modifier and Type | Field and Description |
---|---|
protected static Match[] |
EMPTY_MATCH_ARRAY
An empty array.
|
static int |
FLAG_LAYOUT_FLAT
Flag (
value 1 ) denoting flat list layout. |
static int |
FLAG_LAYOUT_TREE
Flag (
value 2 ) denoting tree layout. |
Modifier | Constructor and Description |
---|---|
protected |
AbstractTextSearchViewPage()
Constructs this page with the default layout flags.
|
protected |
AbstractTextSearchViewPage(int supportedLayouts)
This constructor must be passed a combination of layout flags combined
with bitwise or.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
canRemoveMatchesWith(ISelection selection)
Determines whether the provided selection can be used to remove matches from the result.
|
protected abstract void |
clear()
This method is called whenever all elements have been removed from the
shown
AbstractSearchResult . |
protected abstract void |
configureTableViewer(TableViewer viewer)
Configures the given viewer.
|
protected abstract void |
configureTreeViewer(TreeViewer viewer)
Configures the given viewer.
|
void |
createControl(Composite parent)
Creates the SWT control for this page under the given parent
control.
|
protected TableViewer |
createTableViewer(Composite parent)
Creates the table viewer to be shown on this page.
|
protected TreeViewer |
createTreeViewer(Composite parent)
Creates the tree viewer to be shown on this page.
|
void |
dispose()
The
Page implementation of this IPage method
disposes of this page's control (if it has one and it has not already
been disposed). |
protected abstract void |
elementsChanged(Object[] objects)
This method is called whenever the set of matches for the given elements
changes.
|
protected void |
evaluateChangedElements(Match[] matches,
Set changedElements)
Evaluates the elements to that are later passed to
elementsChanged(Object[]) . |
protected void |
fillContextMenu(IMenuManager mgr)
Fills the context menu for this page.
|
protected void |
fillToolbar(IToolBarManager tbm)
Fills the toolbar contribution for this page.
|
Control |
getControl()
The
Page implementation of this IPage method returns
null . |
Match |
getCurrentMatch()
Returns the currently selected match.
|
IRegion |
getCurrentMatchLocation(Match match)
Returns the current location of the match.
|
int |
getDisplayedMatchCount(Object element)
Returns the number of matches that are currently displayed for the given
element.
|
Match[] |
getDisplayedMatches(Object element)
Returns the matches that are currently displayed for the given element.
|
Integer |
getElementLimit()
Gets the maximal number of top level elements to be shown in a viewer.
|
String |
getID()
Returns the id set via
setID . |
AbstractTextSearchResult |
getInput()
Returns the currently shown result.
|
String |
getLabel()
Returns a user readable label for this search result page.
|
int |
getLayout()
Return the layout this page is currently using.
|
protected IDialogSettings |
getSettings()
Returns a dialog settings object for this search result page.
|
Object |
getUIState()
Returns an object representing the current user interface state of the
page.
|
protected StructuredViewer |
getViewer()
Returns the viewer currently used in this page.
|
protected ISearchResultViewPart |
getViewPart()
Returns the view part set with
setViewPart(ISearchResultViewPart) . |
void |
gotoNextMatch()
Selects the element corresponding to the next match and shows the match
in an editor.
|
void |
gotoPreviousMatch()
Selects the element corresponding to the previous match and shows the
match in an editor.
|
protected void |
handleOpen(OpenEvent event)
This method is called when the search page gets an 'open' event from its
underlying viewer (for example on double click).
|
protected void |
handleSearchResultChanged(SearchResultEvent e)
Handles a search result event for the current search result.
|
void |
init(IPageSite pageSite)
The
Page implementation of this IPageBookViewPage method
stores a reference to the supplied site (the site which contains this
page). |
void |
internalRemoveSelected()
Note: this is internal API and should not be called from clients outside
of the search plug-in.
|
boolean |
isLayoutSupported(int layout)
Determines whether a certain layout is supported by this search result
page.
|
protected IEditorPart |
open(IWorkbenchPage page,
IFile file,
boolean activate)
Opens an editor on the given file resource.
|
protected IEditorPart |
openAndSelect(IWorkbenchPage page,
IFile file,
int offset,
int length,
boolean activate)
Opens an editor on the given file resource and tries to select the given offset and length.
|
protected void |
postEnsureSelection()
Posts a UI update to make sure an element is selected.
|
void |
restoreState(IMemento memento)
Restores the page state.
|
void |
saveState(IMemento memento)
Saves the page state in a memento.
|
void |
setElementLimit(Integer limit)
Sets the maximal number of top level elements to be shown in a viewer.
|
void |
setFocus()
The
Page implementation of this IPage method
does nothing. |
void |
setID(String id)
Sets the id for this page.
|
void |
setInput(ISearchResult newSearch,
Object viewState)
Sets the search result to be shown in this search results page.
|
void |
setLayout(int layout)
Sets the layout of this search result page.
|
void |
setViewPart(ISearchResultViewPart part)
Sets the view part
|
protected void |
showMatch(Match match,
int currentOffset,
int currentLength)
Deprecated.
Use
showMatch(Match, int, int, boolean) instead |
protected void |
showMatch(Match match,
int currentOffset,
int currentLength,
boolean activate)
Opens an editor on the given element and selects the given range of text.
|
getSite, makeContributions, setActionBars
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getSite
setActionBars
protected static final Match[] EMPTY_MATCH_ARRAY
public static final int FLAG_LAYOUT_FLAT
value 1
) denoting flat list layout.public static final int FLAG_LAYOUT_TREE
value 2
) denoting tree layout.protected AbstractTextSearchViewPage(int supportedLayouts)
supportedLayouts
- flags determining which layout options this page supports.
Must not be 0FLAG_LAYOUT_FLAT
,
FLAG_LAYOUT_TREE
protected AbstractTextSearchViewPage()
AbstractTextSearchViewPage(int)
protected IDialogSettings getSettings()
getID()
public void setID(String id)
setID
in interface ISearchResultPage
id
- the id for this pagepublic String getID()
setID
.getID
in interface ISearchResultPage
public String getLabel()
getLabel
in interface ISearchResultPage
protected void showMatch(Match match, int currentOffset, int currentLength) throws PartInitException
showMatch(Match, int, int, boolean)
insteadIFileMatchAdapter
, match locations will be tracked and the current
match range will be passed into this method.match
- the match to showcurrentOffset
- the current start offset of the matchcurrentLength
- the current length of the selectionPartInitException
- if an editor can't be openedITextFileBufferManager
,
IFileMatchAdapter
protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException
IFileMatchAdapter
, match
locations will be tracked and the current match range will be passed into
this method.
If the activate
parameter is true
the opened editor
should have be activated. Otherwise the focus should not be changed.match
- the match to showcurrentOffset
- the current start offset of the matchcurrentLength
- the current length of the selectionactivate
- whether to activate the editor.PartInitException
- if an editor can't be openedITextFileBufferManager
,
IFileMatchAdapter
protected final IEditorPart openAndSelect(IWorkbenchPage page, IFile file, int offset, int length, boolean activate) throws PartInitException
If the page already has an editor open on the target object then that editor is brought to
front; otherwise, a new editor is opened. If activate == true
the editor will be
activated.
page
- the workbench page in which the editor will be openedfile
- the file to openoffset
- the offset to select in the editorlength
- the length to select in the editoractivate
- if true
the editor will be activatednull
if an external editor was openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String, boolean)
protected final IEditorPart open(IWorkbenchPage page, IFile file, boolean activate) throws PartInitException
If the page already has an editor open on the target object then that editor is brought to
front; otherwise, a new editor is opened. If activate == true
the editor will be
activated.
page
- the workbench page in which the editor will be openedfile
- the file to openactivate
- if true
the editor will be activatednull
if an external editor was openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String, boolean)
protected abstract void elementsChanged(Object[] objects)
The changed elements are evaluated by evaluateChangedElements(Match[], Set)
.
objects
- array of objects that has to be refreshedprotected abstract void clear()
AbstractSearchResult
. This method is guaranteed to
be called in the UI thread. Note that this notification is asynchronous.
i.e. further changes may have occurred by the time this method is called.
They will be described in a future call.protected abstract void configureTreeViewer(TreeViewer viewer)
FLAG_LAYOUT_TREE
.viewer
- the viewer to be configuredprotected abstract void configureTableViewer(TableViewer viewer)
FLAG_LAYOUT_FLAT
.viewer
- the viewer to be configuredprotected void fillContextMenu(IMenuManager mgr)
mgr
- the menu manager representing the context menuprotected boolean canRemoveMatchesWith(ISelection selection)
selection
- the selection to testtrue
if the elements in the current selection can be removed.public void createControl(Composite parent)
Clients should not call this method (the workbench calls this method when it needs to, which may be never).
createControl
in interface IPage
createControl
in class Page
parent
- the parent controlprotected void postEnsureSelection()
public boolean isLayoutSupported(int layout)
layout
- the layout to test forAbstractTextSearchViewPage(int)
public void setLayout(int layout)
FLAG_LAYOUT_FLAT
or FLAG_LAYOUT_TREE
and
it must be one of the values passed during construction of this search
result page.layout
- the new layoutisLayoutSupported(int)
public int getLayout()
FLAG_LAYOUT_FLAT
,
FLAG_LAYOUT_TREE
protected TreeViewer createTreeViewer(Composite parent)
parent
- the parent widgetTreeViewer
.protected TableViewer createTableViewer(Composite parent)
parent
- the parent widgetTableViewer
public void setFocus()
Page
implementation of this IPage
method
does nothing. Subclasses must implement.public Control getControl()
Page
implementation of this IPage
method returns
null
. Subclasses must reimplement.getControl
in interface IPage
getControl
in class Page
null
if this
page does not have a controlpublic void setInput(ISearchResult newSearch, Object viewState)
uiState
object.setInput
in interface ISearchResultPage
newSearch
- the search result to be shown or null
to clear the page.viewState
- the previously saved UI stateISearchResultPage.getUIState()
public Object getUIState()
setInput()
method when the
currently shown ISearchResult
is shown again.getUIState
in interface ISearchResultPage
protected StructuredViewer getViewer()
null
if none has been
created yet.public AbstractTextSearchResult getInput()
null
setInput(ISearchResult, Object)
public void gotoNextMatch()
public void gotoPreviousMatch()
public Match getCurrentMatch()
null
if none are selectedpublic Match[] getDisplayedMatches(Object element)
AbstractTextSearchResult.getActiveMatchFilters()
is not null, only matches are returned
that are not filtered by the match filters. If AbstractTextSearchResult.getActiveMatchFilters()
is
null all matches of the given element are returned.
Any action operating on the visible matches in the search
result page should use this method to get the matches for a search
result (instead of asking the search result directly).element
- The element to get the matches fornull
, an empty array is returnedAbstractTextSearchResult.getMatches(Object)
public IRegion getCurrentMatchLocation(Match match)
match
- the match to get the position for.public int getDisplayedMatchCount(Object element)
AbstractTextSearchResult.getActiveMatchFilters()
is not null, only matches
are returned that are not filtered by the match filters.
Any action operating on the visible matches in the
search result page should use this method to get the match count for a
search result (instead of asking the search result directly).element
- The element to get the matches fornull
, 0 is
returnedAbstractTextSearchResult.getMatchCount(Object)
public void dispose()
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.public void init(IPageSite pageSite)
Page
implementation of this IPageBookViewPage
method
stores a reference to the supplied site (the site which contains this
page).
Subclasses may extend.
init
in interface IPageBookViewPage
init
in class Page
pageSite
- the page siteprotected void fillToolbar(IToolBarManager tbm)
tbm
- the tool bar manager representing the view's toolbarpublic void setViewPart(ISearchResultViewPart part)
setViewPart
in interface ISearchResultPage
part
- View part to setprotected ISearchResultViewPart getViewPart()
setViewPart(ISearchResultViewPart)
.null
if the view part hasn't been
set yet (or set to null).protected void handleSearchResultChanged(SearchResultEvent e)
e
- the event to handleprotected void evaluateChangedElements(Match[] matches, Set changedElements)
elementsChanged(Object[])
. By default
the element to change are the elements received by (Match.getElement()
). Client implementations
can modify this behavior.matches
- the matches that were added or removedchangedElements
- the set that collects the elements to change. Clients should only add elements to the set.public void restoreState(IMemento memento)
restoreState
in interface ISearchResultPage
memento
- a memento to restore the page state from or null
if no previous state was savedISearchResultPage.setInput(ISearchResult, Object)
public void saveState(IMemento memento)
ISearchResultPage
saveState
in interface ISearchResultPage
memento
- a memento to receive the object stateISearchResultPage.getUIState()
public void internalRemoveSelected()
Removes the currently selected match. Does nothing if no match is selected.
protected void handleOpen(OpenEvent event)
This method is called when the search page gets an 'open' event from its underlying viewer (for example on double click). The default implementation will open the first match on any element that has matches. If the element to be opened is an inner node in the tree layout, the node will be expanded if it's collapsed and vice versa. Subclasses are allowed to override this method.
event
- the event sent for the currently shown viewerIOpenListener
public void setElementLimit(Integer limit)
null
is set, the view page does not support to limit the elements and will not provide
UI to configure it. If a non-null value is set, configuration UI will be provided. The limit value must be a positive
number or -1
to not limit top level element.
If enabled, the element limit has to be enforced by the content provider that is implemented by the client. The view
page just manages the value and configuration.limit
- the element limit. Valid values are:
null
to not limit and not provide configuration UI-1
to not limit and provide configuration UIpositive integer
to limit by the given value and provide configuration UIpublic Integer getElementLimit()
null
means the view page does not limit the elements and will not provide
UI to configure it. If a non-null value is set, configuration UI will be provided. The limit value must be a positive
number or -1
to not limit top level element.null
to not limit and not provide configuration UI (default value)-1
to not limit and provide configuration UIpositive integer
to limit by the given value and provide configuration UI
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.