Extension SDK

oracle.javatools.editor.insight
Class ListDataItemListModel

java.lang.Object
  extended byoracle.javatools.editor.insight.ListDataItemListModel
All Implemented Interfaces:
javax.swing.ListModel

public class ListDataItemListModel
extends java.lang.Object
implements javax.swing.ListModel

The ListDataItemListModel is a basic implementation of an immutable ListModel which just takes an array of ListDataItem objects (or its subclasses) and can be used as the ListModel for a JList. This class makes a copy of the array (but not the objects) passed to it in case the array is modified.


Field Summary
static ListDataItem[] EMPTY_LIST
          Singleton empty list.
 
Constructor Summary
ListDataItemListModel(ListDataItem[] data)
          Constructs a new ListDataItemListModel using the data elements specified.
 
Method Summary
 void addListDataListener(javax.swing.event.ListDataListener listener)
          Add a listener to the list that's notified each time a change to the data model occurs.
 ListDataItem findClosestDataItem(java.lang.String name)
          Utility routine to find the ListDataItem with display name, as returned by getName() that is closest to the provided name.
 java.lang.String findCommonPrefix(java.lang.String name)
          Utility routine to find the common prefix of ListDataItems the data list that begin with the specified name.
 java.lang.Object getElementAt(int index)
          Returns the value at the specified index.
 ListDataItem[] getMatchingData(java.lang.String prefix)
          Utility routine which fetches the subset of data items in this list model that starts with the given prefix specified.
 java.lang.Object getPrototypeCellValue()
          Fetch a cell value that can be used as a prototype, or example, or data in the list model so that the width of the list can be sized properly.
 int getSize()
          Returns the length of the list.
 void removeListDataListener(javax.swing.event.ListDataListener listener)
          Remove a listener from the list that's notified each time a change to the data model occurs.
protected  void sortData(ListDataItem[] dataList)
          Utility routine to perform an in-place sort of ListDataItems in the provided array.
static boolean startsWithIgnoreCase(java.lang.String name1, java.lang.String name2)
          Utility routine to check whether the first name starts with the second name, using case-insensitive comparison rules ("AA" == 'aa').
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_LIST

public static final ListDataItem[] EMPTY_LIST
Singleton empty list.

Constructor Detail

ListDataItemListModel

public ListDataItemListModel(ListDataItem[] data)
Constructs a new ListDataItemListModel using the data elements specified. A copy of the array will be made in case the original array is changed. This will by default, sort the data passed in through the list.

Parameters:
data - the array of ListDataItem's to make up the model
Method Detail

sortData

protected void sortData(ListDataItem[] dataList)
Utility routine to perform an in-place sort of ListDataItems in the provided array. This sort is performed on the input to the list model. To prevent the sort from occurring, override this method to make it a NOP routine.

Parameters:
dataList - the array to sort in-place

findClosestDataItem

public ListDataItem findClosestDataItem(java.lang.String name)
Utility routine to find the ListDataItem with display name, as returned by getName() that is closest to the provided name. For example, suppose the user had the following items in the list:

If the passed in name is "equalsFoo()", the data item returned will be "equalsIgnoreCase()". If the passed in name is "regionMatches()", the data item returned will be "substring()".

This utility routine can be used by clients to help locate the closest data item that should be selected in an insight list so that the list tracks what the user is typing.

Parameters:
name - the display name to find the closest data item for
Returns:
the data item with display name closest to the one passed in, or if not found, one that follows where the display name would sort into

findCommonPrefix

public java.lang.String findCommonPrefix(java.lang.String name)
Utility routine to find the common prefix of ListDataItems the data list that begin with the specified name. As with findClosestDataItem(), the name of the ListDataItem used is what is returned by getName() Note that a case-insensitive comparison is used for determining the common prefix. Also, of the data items that start with the specified name, the common prefix is taken from the first data item. So for example, if the specified name is "eq", and the following data items are in the list:

  • doesNotEqual()
  • EQUALS_SOMETHING
  • equals()
  • equalsIgnoreCase()
  • maybeEquals()

Then the common prefix is "equals", and since the first data item is "EQUALS_SOMETHING", the common prefix returned will be "EQUALS".

If there are no items that start with the specified name, an empty (zero-length) String will be returned.


getMatchingData

public ListDataItem[] getMatchingData(java.lang.String prefix)
Utility routine which fetches the subset of data items in this list model that starts with the given prefix specified. Note that a case-insensitive comparison is used for determining if the prefix matches.

For example, suppose the data list contains the following:

  • doesNotEqual()
  • EQUALS_SOMETHING
  • equals()
  • equalsIgnoreCase()
  • maybeEquals()

Then there are 3 items which match the prefix "eq", and this routine will return an array of those 3 items. Note that if the prefix is an empty string, "", then all items will be returned. If there are no items that start with the specified prefix, an empty array will be returned.

Parameters:
prefix - the prefix to search for matching items
Returns:
an array of items that each start with the specified prefix

getPrototypeCellValue

public java.lang.Object getPrototypeCellValue()
Fetch a cell value that can be used as a prototype, or example, or data in the list model so that the width of the list can be sized properly.

Returns:
a prototype cell value for width sizing purposes

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String name1,
                                           java.lang.String name2)
Utility routine to check whether the first name starts with the second name, using case-insensitive comparison rules ("AA" == 'aa'). For this.startsWith(that), name1 is this, and name2 is that.

Parameters:
name1 - the name to see if it starts with name2
name2 - the name to see if name1 starts with
Returns:
true if name1 starts with name2

getSize

public int getSize()
Returns the length of the list.

Specified by:
getSize in interface javax.swing.ListModel
Returns:
the length of the list

getElementAt

public java.lang.Object getElementAt(int index)
Returns the value at the specified index.

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
index - the index of the value to get
Returns:
the value at the specified index

addListDataListener

public void addListDataListener(javax.swing.event.ListDataListener listener)
Add a listener to the list that's notified each time a change to the data model occurs.

Specified by:
addListDataListener in interface javax.swing.ListModel
Parameters:
listener - the ListDataListener

removeListDataListener

public void removeListDataListener(javax.swing.event.ListDataListener listener)
Remove a listener from the list that's notified each time a change to the data model occurs.

Specified by:
removeListDataListener in interface javax.swing.ListModel
Parameters:
listener - the ListDataListener

Extension SDK

 

Copyright ©1997, 2003, Oracle. All rights reserved.