Class AbstractTextSearchViewPage
- All Implemented Interfaces:
ISearchResultPage,IPage,IPageBookViewPage
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. Changes in the search result are handled by updating the viewer in the
elementsChanged() and clear() methods.- Since:
- 3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Match[]An empty array.static final intFlag (value 1) denoting flat list layout.static final intFlag (value 2) denoting tree layout. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs this page with the default layout flags.protectedAbstractTextSearchViewPage(int supportedLayouts) This constructor must be passed a combination of layout flags combined with bitwise or. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanRemoveMatchesWith(ISelection selection) Determines whether the provided selection can be used to remove matches from the result.protected abstract voidclear()This method is called whenever all elements have been removed from the shownAbstractSearchResult.protected abstract voidconfigureTableViewer(TableViewer viewer) Configures the given viewer.protected abstract voidconfigureTreeViewer(TreeViewer viewer) Configures the given viewer.voidcreateControl(Composite parent) Creates the SWT control for this page under the given parent control.protected TableViewercreateTableViewer(Composite parent) Creates the table viewer to be shown on this page.protected TreeViewercreateTreeViewer(Composite parent) Creates the tree viewer to be shown on this page.voiddispose()ThePageimplementation of thisIPagemethod disposes of this page's control (if it has one and it has not already been disposed).protected abstract voidelementsChanged(Object[] objects) This method is called whenever the set of matches for the given elements changes.protected voidevaluateChangedElements(Match[] matches, Set<Object> changedElements) Evaluates the elements to that are later passed toelementsChanged(Object[]).protected voidFills the context menu for this page.protected voidFills the toolbar contribution for this page.ThePageimplementation of thisIPagemethod returnsnull.Returns the currently selected match.getCurrentMatchLocation(Match match) Returns the current location of the match.intgetDisplayedMatchCount(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.Gets the maximal number of top level elements to be shown in a viewer.getID()Returns the id set viasetID.getInput()Returns the currently shown result.getLabel()Returns a user readable label for this search result page.intReturn the layout this page is currently using.protected IDialogSettingsReturns a dialog settings object for this search result page.Returns an object representing the current user interface state of the page.protected StructuredViewerReturns the viewer currently used in this page.protected ISearchResultViewPartReturns the view part set withsetViewPart(ISearchResultViewPart).voidSelects the element corresponding to the next match and shows the match in an editor.voidSelects the element corresponding to the previous match and shows the match in an editor.protected voidhandleOpen(OpenEvent event) This method is called when the search page gets an 'open' event from its underlying viewer (for example on double click).protected voidHandles a search result event for the current search result.voidThePageimplementation of thisIPageBookViewPagemethod stores a reference to the supplied site (the site which contains this page).voidNote: this is internal API and should not be called from clients outside of the search plug-in.booleanisLayoutSupported(int layout) Determines whether a certain layout is supported by this search result page.protected final IEditorPartopen(IWorkbenchPage page, IFile file, boolean activate) Opens an editor on the given file resource.protected final IEditorPartopenAndSelect(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 voidPosts a UI update to make sure an element is selected.voidrestoreState(IMemento memento) Restores the page state.voidSaves the page state in a memento.voidsetElementLimit(Integer limit) Sets the maximal number of top level elements to be shown in a viewer.voidsetFocus()ThePageimplementation of thisIPagemethod does nothing.voidSets the id for this page.voidsetInput(ISearchResult newSearch, Object viewState) Sets the search result to be shown in this search results page.voidsetLayout(int layout) Sets the layout of this search result page.voidSets the view partprotected voidDeprecated.protected voidOpens an editor on the given element and selects the given range of text.Methods inherited from class org.eclipse.ui.part.Page
getSite, makeContributions, setActionBarsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.ui.part.IPage
setActionBarsMethods inherited from interface org.eclipse.ui.part.IPageBookViewPage
getSite
-
Field Details
-
EMPTY_MATCH_ARRAY
An empty array. -
FLAG_LAYOUT_FLAT
public static final int FLAG_LAYOUT_FLATFlag (value 1) denoting flat list layout.- See Also:
-
FLAG_LAYOUT_TREE
public static final int FLAG_LAYOUT_TREEFlag (value 2) denoting tree layout.- See Also:
-
-
Constructor Details
-
AbstractTextSearchViewPage
protected AbstractTextSearchViewPage(int supportedLayouts) This constructor must be passed a combination of layout flags combined with bitwise or. At least one flag must be passed in (i.e. 0 is not a permitted value).- Parameters:
supportedLayouts- flags determining which layout options this page supports. Must not be 0- See Also:
-
AbstractTextSearchViewPage
protected AbstractTextSearchViewPage()Constructs this page with the default layout flags.- See Also:
-
-
Method Details
-
getSettings
Returns a dialog settings object for this search result page. There will be one dialog settings object per search result page id.- Returns:
- the dialog settings for this search result page
- See Also:
-
setID
Description copied from interface:ISearchResultPageSets the id for this page. This method will be called before any other initialization is done.- Specified by:
setIDin interfaceISearchResultPage- Parameters:
id- the id for this page
-
getID
Description copied from interface:ISearchResultPageReturns the id set viasetID.- Specified by:
getIDin interfaceISearchResultPage- Returns:
- the id of this page
-
getLabel
Description copied from interface:ISearchResultPageReturns a user readable label for this search result page. The label will be used to describe the contents for the page to the user (for example it will be displayed in the search view title bar). To take an example from file search, a label might read like this: 'test' - 896 matches in workspace.- Specified by:
getLabelin interfaceISearchResultPage- Returns:
- the user readable label for this search result page
-
showMatch
@Deprecated protected void showMatch(Match match, int currentOffset, int currentLength) throws PartInitException Deprecated.UseshowMatch(Match, int, int, boolean)insteadOpens an editor on the given element and selects the given range of text. If a search results implements aIFileMatchAdapter, match locations will be tracked and the current match range will be passed into this method.- Parameters:
match- the match to showcurrentOffset- the current start offset of the matchcurrentLength- the current length of the selection- Throws:
PartInitException- if an editor can't be opened- See Also:
-
showMatch
protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException Opens an editor on the given element and selects the given range of text. If a search results implements aIFileMatchAdapter, match locations will be tracked and the current match range will be passed into this method. If theactivateparameter istruethe opened editor should have be activated. Otherwise the focus should not be changed.- Parameters:
match- the match to showcurrentOffset- the current start offset of the matchcurrentLength- the current length of the selectionactivate- whether to activate the editor.- Throws:
PartInitException- if an editor can't be opened- See Also:
-
openAndSelect
protected final IEditorPart openAndSelect(IWorkbenchPage page, IFile file, int offset, int length, boolean activate) throws PartInitException Opens an editor on the given file resource and tries to select the given offset and length.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 == truethe editor will be activated.- Parameters:
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- iftruethe editor will be activated- Returns:
- an open editor or
nullif an external editor was opened - Throws:
PartInitException- if the editor could not be initialized- Since:
- 3.6
- See Also:
-
open
protected final IEditorPart open(IWorkbenchPage page, IFile file, boolean activate) throws PartInitException Opens an editor on the given file resource.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 == truethe editor will be activated.- Parameters:
page- the workbench page in which the editor will be openedfile- the file to openactivate- iftruethe editor will be activated- Returns:
- an open editor or
nullif an external editor was opened - Throws:
PartInitException- if the editor could not be initialized- Since:
- 3.6
- See Also:
-
elementsChanged
This method is called whenever the set of matches for the given elements changes. 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.The changed elements are evaluated by
evaluateChangedElements(Match[], Set).- Parameters:
objects- array of objects that has to be refreshed
-
clear
protected abstract void clear()This method is called whenever all elements have been removed from the shownAbstractSearchResult. 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. -
configureTreeViewer
Configures the given viewer. Implementers have to set at least a content provider and a label provider. This method may be called if the page was constructed with the flagFLAG_LAYOUT_TREE.- Parameters:
viewer- the viewer to be configured
-
configureTableViewer
Configures the given viewer. Implementers have to set at least a content provider and a label provider. This method may be called if the page was constructed with the flagFLAG_LAYOUT_FLAT.- Parameters:
viewer- the viewer to be configured
-
fillContextMenu
Fills the context menu for this page. Subclasses may override this method.- Parameters:
mgr- the menu manager representing the context menu
-
canRemoveMatchesWith
Determines whether the provided selection can be used to remove matches from the result.- Parameters:
selection- the selection to test- Returns:
- returns
trueif the elements in the current selection can be removed. - Since:
- 3.2
-
createControl
Description copied from interface:IPageCreates 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:
createControlin interfaceIPage- Specified by:
createControlin classPage- Parameters:
parent- the parent control
-
postEnsureSelection
protected void postEnsureSelection()Posts a UI update to make sure an element is selected.- Since:
- 3.2
-
isLayoutSupported
public boolean isLayoutSupported(int layout) Determines whether a certain layout is supported by this search result page.- Parameters:
layout- the layout to test for- Returns:
- whether the given layout is supported or not
- See Also:
-
setLayout
public void setLayout(int layout) Sets the layout of this search result page. The layout must be on ofFLAG_LAYOUT_FLATorFLAG_LAYOUT_TREEand it must be one of the values passed during construction of this search result page.- Parameters:
layout- the new layout- See Also:
-
getLayout
public int getLayout()Return the layout this page is currently using.- Returns:
- the layout this page is currently using
- See Also:
-
createTreeViewer
Creates the tree viewer to be shown on this page. Clients may override this method.- Parameters:
parent- the parent widget- Returns:
- returns a newly created
TreeViewer.
-
createTableViewer
Creates the table viewer to be shown on this page. Clients may override this method.- Parameters:
parent- the parent widget- Returns:
- returns a newly created
TableViewer
-
setFocus
public void setFocus()Description copied from class:PageThePageimplementation of thisIPagemethod does nothing. Subclasses must implement. -
getControl
Description copied from class:PageThePageimplementation of thisIPagemethod returnsnull. Subclasses must reimplement.- Specified by:
getControlin interfaceIPage- Specified by:
getControlin classPage- Returns:
- the SWT control for this page, or
nullif this page does not have a control
-
setInput
Description copied from interface:ISearchResultPageSets the search result to be shown in this search results page. Implementers should restore UI state (e.g. selection) from the previously saveduiStateobject.- Specified by:
setInputin interfaceISearchResultPage- Parameters:
newSearch- the search result to be shown ornullto clear the page.viewState- the previously saved UI state- See Also:
-
getUIState
Description copied from interface:ISearchResultPageReturns an object representing the current user interface state of the page. For example, the current selection in a viewer. The UI state will be later passed into thesetInput()method when the currently shownISearchResultis shown again.- Specified by:
getUIStatein interfaceISearchResultPage- Returns:
- an object representing the UI state of this page
-
getViewer
Returns the viewer currently used in this page.- Returns:
- the currently used viewer or
nullif none has been created yet.
-
getInput
Returns the currently shown result.- Returns:
- the previously set result or
null - See Also:
-
gotoNextMatch
public void gotoNextMatch()Selects the element corresponding to the next match and shows the match in an editor. Note that this will cycle back to the first match after the last match. -
gotoPreviousMatch
public void gotoPreviousMatch()Selects the element corresponding to the previous match and shows the match in an editor. Note that this will cycle back to the last match after the first match. -
getCurrentMatch
Returns the currently selected match.- Returns:
- the selected match or
nullif none are selected
-
getDisplayedMatches
Returns the matches that are currently displayed for the given element. IfAbstractTextSearchResult.getActiveMatchFilters()is not null, only matches are returned that are not filtered by the match filters. IfAbstractTextSearchResult.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).- Parameters:
element- The element to get the matches for- Returns:
- The matches displayed for the given element. If the current input
of this page is
null, an empty array is returned - See Also:
-
getCurrentMatchLocation
Returns the current location of the match. This takes possible modifications of the file into account. Therefore the result may differ from the position information that can be obtained directly off the match.- Parameters:
match- the match to get the position for.- Returns:
- the current position of the match.
- Since:
- 3.2
-
getDisplayedMatchCount
Returns the number of matches that are currently displayed for the given element. IfAbstractTextSearchResult.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).- Parameters:
element- The element to get the matches for- Returns:
- The number of matches displayed for the given element. If the
current input of this page is
null, 0 is returned - See Also:
-
dispose
public void dispose()Description copied from class:PageThePageimplementation of thisIPagemethod disposes of this page's control (if it has one and it has not already been disposed). Subclasses may extend. -
init
Description copied from class:PageThePageimplementation of thisIPageBookViewPagemethod stores a reference to the supplied site (the site which contains this page).Subclasses may extend.
- Specified by:
initin interfaceIPageBookViewPage- Overrides:
initin classPage- Parameters:
pageSite- the page site
-
fillToolbar
Fills the toolbar contribution for this page. Subclasses may override this method.- Parameters:
tbm- the tool bar manager representing the view's toolbar
-
setViewPart
Sets the view part- Specified by:
setViewPartin interfaceISearchResultPage- Parameters:
part- View part to set
-
getViewPart
Returns the view part set withsetViewPart(ISearchResultViewPart).- Returns:
- The view part or
nullif the view part hasn't been set yet (or set to null).
-
handleSearchResultChanged
Handles a search result event for the current search result.- Parameters:
e- the event to handle- Since:
- 3.2
-
evaluateChangedElements
Evaluates the elements to that are later passed toelementsChanged(Object[]). By default the element to change are the elements received by (Match.getElement()). Client implementations can modify this behavior.- Parameters:
matches- the matches that were added or removedchangedElements- the set that collects the elements to change. Clients should only add elements to the set.- Since:
- 3.4
-
restoreState
Restores the page state. Note that this applies only to state that is saved across sessions. Subclasses may extend this method.- Specified by:
restoreStatein interfaceISearchResultPage- Parameters:
memento- a memento to restore the page state from ornullif no previous state was saved- See Also:
-
saveState
Description copied from interface:ISearchResultPageSaves the page state in a memento. Note that this applies to state that should persist across sessions.- Specified by:
saveStatein interfaceISearchResultPage- Parameters:
memento- a memento to receive the object state- See Also:
-
internalRemoveSelected
public void internalRemoveSelected()Note: this is internal API and should not be called from clients outside of the search plug-in.Removes the currently selected match. Does nothing if no match is selected.
- Restriction:
- This method is not intended to be referenced by clients.
-
handleOpen
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.
- Parameters:
event- the event sent for the currently shown viewer- See Also:
-
setElementLimit
Sets the maximal number of top level elements to be shown in a viewer. Ifnullis 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-1to 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.- Parameters:
limit- the element limit. Valid values are:nullto not limit and not provide configuration UI-1to not limit and provide configuration UIpositive integerto limit by the given value and provide configuration UI
- Since:
- 3.3
-
getElementLimit
Gets the maximal number of top level elements to be shown in a viewer.nullmeans 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-1to not limit top level element.- Returns:
- returns the element limit. Valid values are:
nullto not limit and not provide configuration UI (default value)-1to not limit and provide configuration UIpositive integerto limit by the given value and provide configuration UI
- Since:
- 3.3
-
showMatch(Match, int, int, boolean)instead