com.ibm.commons.swt.viewers
Class AbstractDeferredContentProvider

java.lang.Object
  extended by com.ibm.commons.swt.viewers.AbstractDeferredContentProvider
All Implemented Interfaces:
org.eclipse.jface.viewers.IContentProvider, org.eclipse.jface.viewers.IStructuredContentProvider

public abstract class AbstractDeferredContentProvider
extends java.lang.Object
implements org.eclipse.jface.viewers.IStructuredContentProvider

A content provider that can be used in conjunction with any viewer (that supports org.eclipse.jface.viewers.IStructuredContentProvider). This content provider is best used for operations that require long running operations, such as network operations. When the viewer calls getElements(Object) a DeferredDataObject is returned by default. At the same time a Job is scheduled to perform the work required to populate the contents of the viewer.
The Job to perform the work will call the abstract method doWork(Object, DeferredElements). Subclasses must implement doWork(Object, DeferredElements). Viewers that use this ContentProvider must implement com.ibm.commons.swt.viewers.JobCompletedCallback preferrably they should extendcom.ibm.commons.swt.viewers.AbstractDeferredContentProvider.

Once the work has been completed to provide the content, the viewer's com.ibm.commons.swt.viewers.JobCompletedCallback.jobCompleted(Object) method to refresh the viewer in order to display the new content.


Nested Class Summary
 class AbstractDeferredContentProvider.DeferredElements
          Data structure to return the results of a job to the caller.
 
Constructor Summary
AbstractDeferredContentProvider()
           
 
Method Summary
 void dispose()
          Cancels any jobs that are running.
abstract  org.eclipse.core.runtime.IStatus doWork(java.lang.Object input, AbstractDeferredContentProvider.DeferredElements output)
          Do the work in getElements() by getting the elements and putting the results in the output parameter by calling the the setElemnts() method on output.

Example:
Object[] results = ....
 java.lang.Object[] getElements(java.lang.Object inputElement)
          Returns a DeferredElements object by default.
abstract  java.lang.String getJobDisplayName(java.lang.Object input)
           
 void inputChanged(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object oldInput, java.lang.Object newInput)
          Format of input: String[0] = server name String[1] = database name String[2] = design element name String[3] = design element type (see defines)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDeferredContentProvider

public AbstractDeferredContentProvider()
Method Detail

getJobDisplayName

public abstract java.lang.String getJobDisplayName(java.lang.Object input)
Parameters:
input - - input passed to getElements().
Returns:
The display name of the job, does not have to be unique but may not be null.

doWork

public abstract org.eclipse.core.runtime.IStatus doWork(java.lang.Object input,
                                                        AbstractDeferredContentProvider.DeferredElements output)
Do the work in getElements() by getting the elements and putting the results in the output parameter by calling the the setElemnts() method on output.

Example:
Object[] results = .... (code to retrieve results)
output.setElements(results);


This method is called on a background thread in a job created by getElements() and is free to make calls that may block for a long period of time.

Parameters:
input - - input passed to getElements();
output - - update this reference with the results of the fetch by calling its setElements() method.
Returns:
IStatus Returns the status of the operation once complete. If the status is an 'OK' then the contents set in the DeferredElements object will be displayed in the viewer. If the status is an Error status then the error will be displayed in the viewer.

getElements

public java.lang.Object[] getElements(java.lang.Object inputElement)
Returns a DeferredElements object by default. This method also schedules a job which will call the doWork(Object, DeferredElements) method. Once the job is complete com.ibm.commons.swt.viewers.JobCompletedCallback.jobCompleted(Object) will be called to notify the viewer that the fetched contents are available.

Specified by:
getElements in interface org.eclipse.jface.viewers.IStructuredContentProvider

dispose

public void dispose()
Cancels any jobs that are running.

Specified by:
dispose in interface org.eclipse.jface.viewers.IContentProvider

inputChanged

public void inputChanged(org.eclipse.jface.viewers.Viewer viewer,
                         java.lang.Object oldInput,
                         java.lang.Object newInput)
Format of input: String[0] = server name String[1] = database name String[2] = design element name String[3] = design element type (see defines)

Specified by:
inputChanged in interface org.eclipse.jface.viewers.IContentProvider