org.eclipse.mat.query.results
Class ListResult

java.lang.Object
  extended by org.eclipse.mat.query.results.ListResult
All Implemented Interfaces:
IIconProvider, IResult, IResultTable, IStructuredResult

public class ListResult
extends Object
implements IResultTable, IIconProvider

A list of items such as properties as a result table. Compare to PropertyResult which extracts and displays from a single object. Example:

 
    int[] objectIds = myClass.getObjectIds();
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
     
    // loop over all instances and take the value of the field name and the field value
    for (int id : objectIds)
    {
        IObject myObject = snapshot.getObject(id);
        String name = ((IObject) myObject.resolveValue("name")).getClassSpecificName();
        String value = ((IObject) myObject.resolveValue("value")).getClassSpecificName();

        pairs.add(new NameValuePair(name, value));
    }
    
    // the NameValuePair is a bean with two properties - name and value
    // the returned result will be a table with two columns - one for each of these properties
    return new ListResult(NameValuePair.class, pairs, "name", "value")
 
 
The column names are derived from the property names. If the names are required to be internationalized then a BeanInfo can be provided for the type which provides a display name for the property descriptor.


Nested Class Summary
static interface ListResult.ValueProvider
          Converts a row to the needed value from the row
 
Field Summary
 
Fields inherited from interface org.eclipse.mat.query.IIconProvider
EMPTY
 
Constructor Summary
ListResult(Class<? extends L> type, List<L> subjects, String... properties)
          Construct a displayable list from a List.
 
Method Summary
 void addColumn(Column column, ListResult.ValueProvider valueProvider)
           
 Column[] getColumns()
          The columns of the tree or table.
 Object getColumnValue(Object row, int columnIndex)
          Returns the (unformatted) value of a table/tree cell.
 IContextObject getContext(Object row)
          The default context of the row which is used to display information in the object inspector.
 URL getIcon(Object row)
           
 ResultMetaData getResultMetaData()
          (Optionally) Return meta data of the result needed to fine-tune the display of the result.
 Object getRow(int rowId)
          Returns the object of the row with the given row number.
 int getRowCount()
          Returns the number of rows in the result table.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListResult

public ListResult(Class<? extends L> type,
                  List<L> subjects,
                  String... properties)
Construct a displayable list from a List.

Type Parameters:
L - type name of items in the list
Parameters:
type - class of items in the list
subjects - the list
properties - the field names (or Java Bean properties) to be extracted from the list entries
Method Detail

addColumn

public void addColumn(Column column,
                      ListResult.ValueProvider valueProvider)

getResultMetaData

public ResultMetaData getResultMetaData()
Description copied from interface: IResult
(Optionally) Return meta data of the result needed to fine-tune the display of the result. This could include an additional context, an additional query to run on selected data from the result , additional calculated columns, or an indication that the results are already presorted.

Specified by:
getResultMetaData in interface IResult

getColumns

public final Column[] getColumns()
Description copied from interface: IStructuredResult
The columns of the tree or table.

Specified by:
getColumns in interface IStructuredResult

getRowCount

public final int getRowCount()
Description copied from interface: IResultTable
Returns the number of rows in the result table.

Specified by:
getRowCount in interface IResultTable

getRow

public final Object getRow(int rowId)
Description copied from interface: IResultTable
Returns the object of the row with the given row number.

Specified by:
getRow in interface IResultTable
Parameters:
rowId - The row number.
Returns:
The row object, which can be passed to IStructuredResult.getContext(Object) or IStructuredResult.getColumnValue(Object, int).

getColumnValue

public final Object getColumnValue(Object row,
                                   int columnIndex)
Description copied from interface: IStructuredResult
Returns the (unformatted) value of a table/tree cell.

Specified by:
getColumnValue in interface IStructuredResult
Parameters:
row - The row object as returned by the IResultTable.getRow(int) or IResultTree.getElements() or IResultTree.getChildren(Object) methods
columnIndex - The index of the column.

getIcon

public URL getIcon(Object row)
Specified by:
getIcon in interface IIconProvider

getContext

public IContextObject getContext(Object row)
Description copied from interface: IStructuredResult
The default context of the row which is used to display information in the object inspector. Unless no context provider is given via the ResultMetaData, it is also used for the context menu on a row.

Specified by:
getContext in interface IStructuredResult
Parameters:
row - The row object as returned by the IResultTable.getRow(int) or IResultTree.getElements() or IResultTree.getChildren(Object) methods.