public class DeferredListContentProvider extends Object implements IStructuredContentProvider, ISelectionChangedListener
AbstractListViewer
s or
AbstractTableViewer
s that uses a background job to add content to the
viewer.
This content provider can be used for list viewers when fetching content for the viewer is a long running operation, but provides partial results. Elements are added to the list as they come. Until the fetching process is finished, a placeholder object is appended to the list to signify that we're still fetching.
To use, your viewer's input
must adapt to a IDeferredWorkbenchAdapter
(or implement this
interface). This content provider will call your input's
IDeferredWorkbenchAdapter.fetchDeferredChildren(Object, IElementCollector, IProgressMonitor)
method in a background thread to do the actual fetching. Your
LabelProvider
should label the PendingUpdateAdapter
as
something like “Pending ...”.
DeferredTreeContentManager
Modifier and Type | Class and Description |
---|---|
static interface |
DeferredListContentProvider.IDoneListener |
Constructor and Description |
---|
DeferredListContentProvider() |
DeferredListContentProvider(Class<?> targetClass)
Creates a new
DeferredListContentProvider . |
Modifier and Type | Method and Description |
---|---|
void |
addDoneListener(DeferredListContentProvider.IDoneListener listener)
The given listener will be notified when the loading has finished and the
PendingUpdateAdapter has been removed. |
protected void |
addElements(Object[] elements,
IProgressMonitor monitor)
Starts an
UIJob to insert the given elements into the viewer. |
protected IElementCollector |
createElementCollector(Object inputElement,
PendingUpdateAdapter placeholder)
Creates the
IElementCollector which transfers the objects from
the IDeferredWorkbenchAdapter to the AbstractListViewer . |
void |
dispose() |
protected IDeferredWorkbenchAdapter |
getAdapter(Object element)
Tries desperately to convert the element to an
IDeferredWorkbenchAdapter . |
Object[] |
getElements(Object inputElement)
Returns an initial list of elements (containing the
PendingUpdateAdapter ) and initiates the background fetching of
the actual elements. |
Class<?> |
getTargetClass() |
void |
inputChanged(Viewer viewer,
Object oldInput,
Object newInput) |
boolean |
isRestoreSelection()
Due to the nature of the deferred content provider
StructuredViewer 's standard way of preserving the selection
during a StructuredViewer.refresh() doesn't work. |
protected void |
notifyDoneListeners() |
void |
removeDoneListener(DeferredListContentProvider.IDoneListener listener) |
protected void |
runDoneJob(PendingUpdateAdapter placeholder)
Starts the
UIJob that removes the placeholder from the
listviewer. |
void |
selectionChanged(SelectionChangedEvent event) |
void |
setRestoreSelection(boolean restoreSelection) |
protected void |
startFetchingChildren(Object inputElement,
PendingUpdateAdapter placeholder)
Starts the actual fetch job.
|
public DeferredListContentProvider()
public DeferredListContentProvider(Class<?> targetClass)
DeferredListContentProvider
.targetClass
- if != null
, all results are adapted to the target
class before they are added to the viewer. If an object cannot
be adapted to targetClass (i.e.
returns null
,
the object is not added.public boolean isRestoreSelection()
StructuredViewer
's standard way of preserving the selection
during a StructuredViewer.refresh() doesn't work. Thus, this
class offers an alternative mechanism which can be activated by calling
setRestoreSelection(true)
. If you do so, we install
a selection listener on the viewer which will remember the last
non-empty selection of the viewer, and which will restore that
after loading has been finished.public void setRestoreSelection(boolean restoreSelection)
public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
inputChanged
in interface IContentProvider
public Object[] getElements(Object inputElement)
PendingUpdateAdapter
) and initiates the background fetching of
the actual elements.protected void startFetchingChildren(Object inputElement, PendingUpdateAdapter placeholder)
inputElement
- placeholder
- IllegalArgumentException
- if the inputElement cannot be adapted to an
IDeferredWorkbenchAdapter
.protected IElementCollector createElementCollector(Object inputElement, PendingUpdateAdapter placeholder)
IElementCollector
which transfers the objects from
the IDeferredWorkbenchAdapter
to the AbstractListViewer
.inputElement
- placeholder
- protected void addElements(Object[] elements, IProgressMonitor monitor)
UIJob
to insert the given elements into the viewer.
Called by the IElementCollector
. This may be called from a non-UI
thread.elements
- The elements to add.monitor
- protected void runDoneJob(PendingUpdateAdapter placeholder)
UIJob
that removes the placeholder from the
listviewer. This method may be called from a non-UI thread.placeholder
- protected IDeferredWorkbenchAdapter getAdapter(Object element)
IDeferredWorkbenchAdapter
.element
- The element to convert.IDeferredWorkbenchAdapter
for element or
null if none could be found.public void dispose()
dispose
in interface IContentProvider
public void addDoneListener(DeferredListContentProvider.IDoneListener listener)
PendingUpdateAdapter
has been removed.listener
- public void removeDoneListener(DeferredListContentProvider.IDoneListener listener)
protected void notifyDoneListeners()
public Class<?> getTargetClass()
public void selectionChanged(SelectionChangedEvent event)
selectionChanged
in interface ISelectionChangedListener