Decision Center API

ilog.webui.dhtml.components
Class IlxWList

java.lang.Object
  extended by ilog.webui.dhtml.IlxWContainer
      extended by ilog.webui.dhtml.IlxWComponent
          extended by ilog.webui.dhtml.components.IlxWList
All Implemented Interfaces:
ilog.webui.dhtml.IlxWConstants, ilog.webui.dhtml.IlxWCSSModelProvider, ilog.webui.dhtml.IlxWDependencyProvider, ilog.webui.dhtml.IlxWJSObject, Serializable

public class IlxWList
extends IlxWComponent

A component that allows the user to select one or more objects from a list.

The IlxWList data model is an instance of javax.swing.ListModel. Its selection state is managed by an instance of javax.swing.ListSelectionModel.

By default, the IlxWList is rendered on the browser as a <select> HTML element. Its cells are rendered as <option> elements whose values are the result of the toString() method performed on the cell data. However, you may provide a custom cell renderer through the setCellRenderer method. You may either subclass the default cell renderer (IlxWDefaultListCellRenderer) or implement the IlxWListCellRenderer interface. The default cell renderer uses an IlxWLabel component to render the string value of each component. You can substitute your own cell renderer, using code like this:

  // Display an icon and a string for each object in the list.

 
 class MyCellRenderer extends IlxWLabel implements IlxWListCellRenderer {
     public IlxWComponent getListCellRendererComponent(
         IlxWList list,
         Object value,
         int index,
         boolean isSelected)
     {
         setText(value.toString());
         if (isSelected) {
           getStyle().set("backgroundColor", "red");
           getStyle().set("color", "white");
         } else {
           getStyle().set("backgroundColor", "white");
           getStyle().set("color", "black");
         }
         return this;
     }
 }
 String[] data = {"one", "two", "three", "four"};
 IlxWList dataList = new IlxWList(data);
 dataList.setCellRenderer(new MyCellRenderer());
 
 

, IlxWListCellRenderer, IlxWDefaultListCellRenderer, Serialized Form


Nested Class Summary
 
Nested classes/interfaces inherited from class ilog.webui.dhtml.IlxWComponent
IlxWComponent.DynamicStyleMap
 
Field Summary
static String ACTION_PROPERTY
          Name of the action property.
static String CELL_RENDERER_PROPERTY
          Name of the cellRenderer property.
static String CSS_RESOURCE_NAME
          Resource path to the user-agent CSS.
static String MODEL_PROPERTY
          Name of the model property.
static String SELECTION_MODEL_PROPERTY
          Name of the selectionModel property.
static String UI_PROPERTY
          Name of the UI property.
 
Fields inherited from class ilog.webui.dhtml.IlxWContainer
listenerList
 
Constructor Summary
IlxWList()
          Constructs an IlxWList with an empty model.
IlxWList(ListModel model)
          Constructs an IlxWList that displays the elements in the specified, non-null model.
IlxWList(Object[] listData)
          Constructs an IlxWList that displays the elements in the specified array.
 
Method Summary
 void addListSelectionListener(ListSelectionListener listener)
          Adds a listener to the list that's notified each time a change to the selection occurs.
 void addSelectionInterval(int anchor, int lead)
          Sets the selection to be the union of the specified interval with current selection.
 void clearSelection()
          Clears the selection - after calling this method isSelectionEmpty will return true.
protected  ListSelectionModel createSelectionModel()
          Returns an instance of DefaultListSelectionModel.
protected  void fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
          Notifies IlxWList ListSelectionListeners that the selection model has changed.
 IlxWAction getAction()
          Gets the action that will be called when the user selects an item in the list.
 int getAnchorSelectionIndex()
          Returns the first index argument from the most recent addSelectionModel or setSelectionInterval call.
 IlxWComponent getCellAt(int index)
          Gets the component representing the cell at the given index.
 IlxWListCellRenderer getCellRenderer()
          Returns the object that renders the list items.
 int getColumnWidth()
          Returns the width of the component in pixels.
 int getLeadSelectionIndex()
          Returns the second index argument from the most recent addSelectionInterval or setSelectionInterval call.
 ListSelectionListener[] getListSelectionListeners()
           
 int getMaxSelectionIndex()
          Returns the largest selected cell index.
 int getMinSelectionIndex()
          Returns the smallest selected cell index.
 ListModel getModel()
          Returns the data model that holds the list of items displayed by the IlxWList component.
 int getRowHeight()
          Returns the height of the component.
 int getSelectedIndex()
          Returns the first selected index.
 Object getSelectedValue()
          Returns the first selected value, or null if the selection is empty.
 int getSelectionMode()
          Returns whether single-item or multiple-item selections are allowed.
 ListSelectionModel getSelectionModel()
          Returns the value of the current selection model.
protected  IlxWCSSRuleset getUserAgentRules()
          Gets the "user-agent" CSS rules.
 boolean isEnabled()
          Determines whether this component is enabled.
 boolean isSelectedIndex(int index)
          Returns true if the specified index is selected.
 boolean isSelectionEmpty()
          Returns true if nothing is selected.
 void notifyDependencies(IlxWPort port)
           
protected  void printComponent(IlxWPort port)
          Prints the HTML code that will display the graphical representation of this component.
 void removeListSelectionListener(ListSelectionListener listener)
          Removes a listener from the list that is notified each time a change to the selection occurs.
 void removeSelectionInterval(int index0, int index1)
          Sets the selection to be the set difference of the specified interval and the current selection.
 void setAction(IlxWAction action)
          Sets the action which will be called when the user selects an item in the list.
 void setCellRenderer(IlxWListCellRenderer cellRenderer)
          Sets the delegate used to render each cell in the list.
 void setColumnWidth(int columnWidth)
          Sets the width of the component in pixels.
 void setEnabled(boolean enabled)
          Enables or disables this component.
 void setListData(Object[] listData)
          Constructs a ListModel from an array of objects and then applies setModel to it.
 void setModel(ListModel model)
          Sets the model that represents the contents or "value" of the list and clears the list selection after notifying PropertyChangeListeners.
 void setRowHeight(int rowHeight)
          Sets the height of the component, that is, the number of items displayed in the drop-down list without scrolling.
 void setSelectedIndex(int index)
          Selects a single cell.
 void setSelectedValue(Object element)
          Selects the specified object from the list.
 void setSelectionInterval(int anchor, int lead)
          Selects the specified interval.
 void setSelectionMode(int selectionMode)
          Determines whether single-item or multiple-item selections are allowed.
 void setSelectionModel(ListSelectionModel selectionModel)
          Sets the selectionModel for the list to a non-null ListSelectionModel implementation.
 
Methods inherited from class ilog.webui.dhtml.IlxWComponent
addPropertyChangeListener, addPropertyChangeListener, detach, doPrint, firePropertyChange, firePropertyChange, getName, getRealHtmlTagName, getStyle, invalidate, isInvalidated, print, removePropertyChangeListener, removePropertyChangeListener, setName, validate
 
Methods inherited from class ilog.webui.dhtml.IlxWContainer
add, add, getAttribute, getAttributeNames, getComponent, getComponentCount, getComponentNamed, getComponents, getManager, getParent, indexOf, isAncestorOf, remove, remove, removeAll, removeAttribute, setAttribute, setAuthorRules, setFinalizer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODEL_PROPERTY

public static final String MODEL_PROPERTY
Name of the model property.

See Also:
Constant Field Values

SELECTION_MODEL_PROPERTY

public static final String SELECTION_MODEL_PROPERTY
Name of the selectionModel property.

See Also:
Constant Field Values

CELL_RENDERER_PROPERTY

public static final String CELL_RENDERER_PROPERTY
Name of the cellRenderer property.

See Also:
Constant Field Values

ACTION_PROPERTY

public static final String ACTION_PROPERTY
Name of the action property.

See Also:
Constant Field Values

UI_PROPERTY

public static final String UI_PROPERTY
Name of the UI property.

See Also:
Constant Field Values

CSS_RESOURCE_NAME

public static final String CSS_RESOURCE_NAME
Resource path to the user-agent CSS.

See Also:
Constant Field Values
Constructor Detail

IlxWList

public IlxWList(ListModel model)
Constructs an IlxWList that displays the elements in the specified, non-null model.

All IlxWList constructors delegate to this one.

Throws:
IllegalArgumentException - If dataModel is null
Parameters:
model - The data model for this list.

IlxWList

public IlxWList(Object[] listData)
Constructs an IlxWList that displays the elements in the specified array.

This constructor simply delegates to the ListModel constructor.

Parameters:
listData - The array of Objects to be loaded into the data model.

IlxWList

public IlxWList()
Constructs an IlxWList with an empty model.

Method Detail

getColumnWidth

public int getColumnWidth()
Returns the width of the component in pixels.


setColumnWidth

public void setColumnWidth(int columnWidth)
Sets the width of the component in pixels.

Parameters:
columnWidth - The width of the component in pixels.

getRowHeight

public int getRowHeight()
Returns the height of the component. This corresponds to the number of items displayed in the drop-down list without scrolling.


setRowHeight

public void setRowHeight(int rowHeight)
Sets the height of the component, that is, the number of items displayed in the drop-down list without scrolling.

Parameters:
rowHeight - The height of the component in list items.

getCellRenderer

public IlxWListCellRenderer getCellRenderer()
Returns the object that renders the list items.

Returns:
The IlxWListCellRenderer.
See Also:
setCellRenderer(ilog.webui.dhtml.components.IlxWListCellRenderer)

setCellRenderer

public void setCellRenderer(IlxWListCellRenderer cellRenderer)
Sets the delegate used to render each cell in the list.

By default this property is null and the list is rendered as a <select> HTML element where cells are representing by an <option> element whose values are the string values of the data model. To see an example which sets the cell renderer, see the class description above.

Parameters:
cellRenderer - The IlxWListCellRenderer that renders list cells.
See Also:
getCellRenderer()

getModel

public ListModel getModel()
Returns the data model that holds the list of items displayed by the IlxWList component.

Returns:
The list model that provides the displayed list of items.
See Also:
setModel(javax.swing.ListModel)

setModel

public void setModel(ListModel model)
Sets the model that represents the contents or "value" of the list and clears the list selection after notifying PropertyChangeListeners.

Throws:
IllegalArgumentException - If model is null.
Parameters:
model - The ListModel that provides the list of items for display.
See Also:
getModel()

setListData

public void setListData(Object[] listData)
Constructs a ListModel from an array of objects and then applies setModel to it.

Parameters:
listData - An array of Objects containing the items to display in the list.
See Also:
setModel(javax.swing.ListModel)

createSelectionModel

protected ListSelectionModel createSelectionModel()
Returns an instance of DefaultListSelectionModel.

This method is used by the constructor to initialize the selectionModel property.

Returns:
The ListSelectionModel used by this list.
See Also:
setSelectionModel(javax.swing.ListSelectionModel), DefaultListSelectionModel

getSelectionModel

public ListSelectionModel getSelectionModel()
Returns the value of the current selection model.

The selection model handles the task of making single selections, selections of contiguous ranges, and non-contiguous selections.

Returns:
The selection model that implements list selections.
See Also:
setSelectionModel(javax.swing.ListSelectionModel), ListSelectionModel

fireSelectionValueChanged

protected void fireSelectionValueChanged(int firstIndex,
                                         int lastIndex,
                                         boolean isAdjusting)
Notifies IlxWList ListSelectionListeners that the selection model has changed.

It is used to forward ListSelectionEvents from the selectionModel to the ListSelectionListeners added directly to the IlxWList.

Parameters:
firstIndex - The first selected index.
lastIndex - The last selected index.
isAdjusting - True if multiple changes are being made.
See Also:
addListSelectionListener(javax.swing.event.ListSelectionListener), removeListSelectionListener(javax.swing.event.ListSelectionListener)

getListSelectionListeners

public ListSelectionListener[] getListSelectionListeners()

addListSelectionListener

public void addListSelectionListener(ListSelectionListener listener)
Adds a listener to the list that's notified each time a change to the selection occurs.

Listeners added directly to the IlxWList will have their ListSelectionEvent.getSource() == this IlxWList (instead of the ListSelectionModel).

Parameters:
listener - The ListSelectionListener to add.
See Also:
getSelectionModel()

removeListSelectionListener

public void removeListSelectionListener(ListSelectionListener listener)
Removes a listener from the list that is notified each time a change to the selection occurs.

Parameters:
listener - The ListSelectionListener to remove.
See Also:
addListSelectionListener(javax.swing.event.ListSelectionListener), getSelectionModel()

setSelectionModel

public void setSelectionModel(ListSelectionModel selectionModel)
Sets the selectionModel for the list to a non-null ListSelectionModel implementation.

The selection model handles the task of making single selections, selections of contiguous ranges, and non-contiguous selections.

Throws:
IllegalArgumentException - If selectionModel is null.
Parameters:
selectionModel - The ListSelectionModel that implements the selections.
See Also:
getSelectionModel()

setSelectionMode

public void setSelectionMode(int selectionMode)
Determines whether single-item or multiple-item selections are allowed.

The following selectionMode values are allowed:

Parameters:
selectionMode - An integer specifying the type of selections that are permissible.
See Also:
getSelectionMode()

getSelectionMode

public int getSelectionMode()
Returns whether single-item or multiple-item selections are allowed.

Returns:
The value of the selection mode.
See Also:
setSelectionMode(int)

getAnchorSelectionIndex

public int getAnchorSelectionIndex()
Returns the first index argument from the most recent addSelectionModel or setSelectionInterval call.

This is a convenience method that just delegates to the selectionModel.

Returns:
The index that most recently anchored an interval selection.
See Also:
ListSelectionModel.getAnchorSelectionIndex(), addSelectionInterval(int, int), setSelectionInterval(int, int), addListSelectionListener(javax.swing.event.ListSelectionListener)

getLeadSelectionIndex

public int getLeadSelectionIndex()
Returns the second index argument from the most recent addSelectionInterval or setSelectionInterval call.

This is a convenience method that just delegates to the selectionModel.

Returns:
The index that most recently ended an interval selection.
See Also:
ListSelectionModel.getLeadSelectionIndex(), addSelectionInterval(int, int), setSelectionInterval(int, int), addListSelectionListener(javax.swing.event.ListSelectionListener)

getMinSelectionIndex

public int getMinSelectionIndex()
Returns the smallest selected cell index.

This is a convenience method that just delegates to the selectionModel.

Returns:
The smallest selected cell index.
See Also:
ListSelectionModel.getMinSelectionIndex(), addListSelectionListener(javax.swing.event.ListSelectionListener)

getMaxSelectionIndex

public int getMaxSelectionIndex()
Returns the largest selected cell index.

This is a convenience method that just delegates to the selectionModel.

Returns:
The largest selected cell index.
See Also:
ListSelectionModel.getMaxSelectionIndex(), addListSelectionListener(javax.swing.event.ListSelectionListener)

isSelectedIndex

public boolean isSelectedIndex(int index)
Returns true if the specified index is selected.

This is a convenience method that just delegates to the selectionModel.

Parameters:
index - Index to be queried for selection state.
Returns:
True if the specified index is selected.
See Also:
ListSelectionModel.isSelectedIndex(int), setSelectedIndex(int), addListSelectionListener(javax.swing.event.ListSelectionListener)

isSelectionEmpty

public boolean isSelectionEmpty()
Returns true if nothing is selected.

This is a convenience method that just delegates to the selectionModel.

Returns:
true if nothing is selected.
See Also:
ListSelectionModel.isSelectionEmpty(), clearSelection(), addListSelectionListener(javax.swing.event.ListSelectionListener)

clearSelection

public void clearSelection()
Clears the selection - after calling this method isSelectionEmpty will return true.

This is a convenience method that just delegates to the selectionModel.

See Also:
ListSelectionModel.clearSelection(), isSelectionEmpty(), addListSelectionListener(javax.swing.event.ListSelectionListener)

setSelectionInterval

public void setSelectionInterval(int anchor,
                                 int lead)
Selects the specified interval. Both the anchor and lead indices are included.

It is not necessary for anchor to be less than lead. This is a convenience method that just delegates to the selectionModel.

Parameters:
anchor - The first index to select.
lead - The last index to select.
See Also:
ListSelectionModel.setSelectionInterval(int, int), addSelectionInterval(int, int), removeSelectionInterval(int, int), addListSelectionListener(javax.swing.event.ListSelectionListener)

addSelectionInterval

public void addSelectionInterval(int anchor,
                                 int lead)
Sets the selection to be the union of the specified interval with current selection.

Both the anchor and lead indices are included. It is not necessary for anchor to be less than lead. This is a convenience method that just delegates to the selectionModel.

Parameters:
anchor - The first index to add to the selection.
lead - The last index to add to the selection.
See Also:
ListSelectionModel.addSelectionInterval(int, int), setSelectionInterval(int, int), removeSelectionInterval(int, int), addListSelectionListener(javax.swing.event.ListSelectionListener)

removeSelectionInterval

public void removeSelectionInterval(int index0,
                                    int index1)
Sets the selection to be the set difference of the specified interval and the current selection.

Both the anchor and lead indices are removed. It is not necessary for anchor to be less than lead. This is a convenience method that just delegates to the selectionModel.

Parameters:
index0 - The first index to remove from the selection.
index1 - The last index to remove from the selection.
See Also:
ListSelectionModel.removeSelectionInterval(int, int), setSelectionInterval(int, int), addSelectionInterval(int, int), addListSelectionListener(javax.swing.event.ListSelectionListener)

setSelectedIndex

public void setSelectedIndex(int index)
Selects a single cell.

Parameters:
index - The index of the one cell to select.
See Also:
ListSelectionModel.setSelectionInterval(int, int), isSelectedIndex(int), addListSelectionListener(javax.swing.event.ListSelectionListener)

getSelectedIndex

public int getSelectedIndex()
Returns the first selected index.

Returns -1 if there is no selected item.

Returns:
The value of getMinSelectionIndex.
See Also:
getMinSelectionIndex(), addListSelectionListener(javax.swing.event.ListSelectionListener)

getSelectedValue

public Object getSelectedValue()
Returns the first selected value, or null if the selection is empty.

Returns:
The first selected value.
See Also:
getMinSelectionIndex(), getModel(), addListSelectionListener(javax.swing.event.ListSelectionListener)

setSelectedValue

public void setSelectedValue(Object element)
Selects the specified object from the list.

The list will scroll to display the selected object.

Parameters:
element - The object to select.

isEnabled

public boolean isEnabled()
Determines whether this component is enabled.

Returns:
true if the component is enabled; false otherwise.
See Also:
setEnabled(boolean)

setEnabled

public void setEnabled(boolean enabled)
Enables or disables this component.

Parameters:
enabled - If true, this component is enabled; otherwise this component is disabled.
See Also:
isEnabled()

getAction

public IlxWAction getAction()
Gets the action that will be called when the user selects an item in the list.

By default, this action is a Java action (IlxWJavaAction) of which the perform method calls setSelectedIndex on the list.

If the given action is a Java action (IlxWJavaAction), or a JavaScript action (IlxWJSAction), the argument array passed to the perform method is a 1-length array containing the string representation of the selected index.

Returns:
The action to perform when the user selects an item from the list.
See Also:
setAction(ilog.webui.dhtml.components.IlxWAction)

setAction

public void setAction(IlxWAction action)
Sets the action which will be called when the user selects an item in the list.

Parameters:
action - The action to perform when the user selects an item from the list.
See Also:
getAction()

getUserAgentRules

protected IlxWCSSRuleset getUserAgentRules()
Description copied from class: IlxWContainer
Gets the "user-agent" CSS rules.
User agent rules are a set of CSS rules which will apply by default to each instance of this container. They may be completed or overridden by the author rules, set via the setAuthorRules method.

This method returns null by default but is intended to be redefined by subclasses.

Overrides:
getUserAgentRules in class IlxWContainer
Returns:
a CSS ruleset.
See Also:
IlxWContainer.setAuthorRules(ilog.webui.dhtml.IlxWCSSRuleset)

printComponent

protected void printComponent(IlxWPort port)
                       throws IOException
Description copied from class: IlxWComponent
Prints the HTML code that will display the graphical representation of this component. This method is called by the IlxWComponent.print(ilog.webui.dhtml.IlxWPort) method.

Specified by:
printComponent in class IlxWComponent
Throws:
IOException
Parameters:
port - The port on which the component will be printed.
See Also:
IlxWComponent.print(ilog.webui.dhtml.IlxWPort)

getCellAt

public IlxWComponent getCellAt(int index)
Gets the component representing the cell at the given index. This component wraps the component returned by IlxWListCellRenderer.getListCellComponent.

Under certain circumstances you may actually need to access the cell component, in order, for instance, to dynamically set the background-color of the whole cell.

This component is not persistent and can be deleted/created at any time during the rendering phase. Consequently you should call this method only from the scope of IlxWListCellRenderer.getListCellComponent, and never keep a reference on the returned component outside this scope.


notifyDependencies

public void notifyDependencies(IlxWPort port)
Specified by:
notifyDependencies in interface ilog.webui.dhtml.IlxWDependencyProvider
Overrides:
notifyDependencies in class IlxWComponent

Decision Center API

© Copyright IBM Corp. 1987, 2013