Class IlxWList
- java.lang.Object
-
- ilog.webui.dhtml.IlxWContainer
-
- ilog.webui.dhtml.IlxWComponent
-
- ilog.webui.dhtml.components.IlxWList
-
- All Implemented Interfaces:
- ilog.webui.dhtml.IlxWConstants, ilog.webui.dhtml.IlxWCSSModelProvider, ilog.webui.dhtml.IlxWDependencyProvider, ilog.webui.dhtml.IlxWJSObject, java.io.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 ofjavax.swing.ListModel
. Its selection state is managed by an instance ofjavax.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 thetoString()
method performed on the cell data. However, you may provide a custom cell renderer through thesetCellRenderer
method. You may either subclass the default cell renderer (IlxWDefaultListCellRenderer
) or implement theIlxWListCellRenderer
interface. The default cell renderer uses anIlxWLabel
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
Fields Modifier and Type Field and Description static java.lang.String
ACTION_PROPERTY
Name of the action property.static java.lang.String
CELL_RENDERER_PROPERTY
Name of the cellRenderer property.static java.lang.String
CSS_RESOURCE_NAME
Resource path to the user-agent CSS.static java.lang.String
MODEL_PROPERTY
Name of the model property.static java.lang.String
SELECTION_MODEL_PROPERTY
Name of the selectionModel property.static java.lang.String
UI_PROPERTY
Name of the UI property.-
Fields inherited from class ilog.webui.dhtml.IlxWContainer
listenerList
-
-
Constructor Summary
Constructors Constructor and Description IlxWList()
Constructs anIlxWList
with an empty model.IlxWList(javax.swing.ListModel model)
Constructs anIlxWList
that displays the elements in the specified, non-null model.IlxWList(java.lang.Object[] listData)
Constructs anIlxWList
that displays the elements in the specified array.
-
Method Summary
Methods Modifier and Type Method and Description void
addListSelectionListener(javax.swing.event.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 methodisSelectionEmpty
will return true.protected javax.swing.ListSelectionModel
createSelectionModel()
Returns an instance ofDefaultListSelectionModel
.protected void
fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
NotifiesIlxWList
ListSelectionListener
s 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 recentaddSelectionModel
orsetSelectionInterval
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 recentaddSelectionInterval
orsetSelectionInterval
call.javax.swing.event.ListSelectionListener[]
getListSelectionListeners()
int
getMaxSelectionIndex()
Returns the largest selected cell index.int
getMinSelectionIndex()
Returns the smallest selected cell index.javax.swing.ListModel
getModel()
Returns the data model that holds the list of items displayed by theIlxWList
component.int
getRowHeight()
Returns the height of the component.int
getSelectedIndex()
Returns the first selected index.java.lang.Object
getSelectedValue()
Returns the first selected value, ornull
if the selection is empty.int
getSelectionMode()
Returns whether single-item or multiple-item selections are allowed.javax.swing.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(javax.swing.event.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(java.lang.Object[] listData)
Constructs aListModel
from an array of objects and then appliessetModel
to it.void
setModel(javax.swing.ListModel model)
Sets the model that represents the contents or "value" of the list and clears the list selection after notifyingPropertyChangeListeners
.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(java.lang.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(javax.swing.ListSelectionModel selectionModel)
Sets theselectionModel
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
-
-
-
-
Field Detail
-
MODEL_PROPERTY
public static final java.lang.String MODEL_PROPERTY
Name of the model property.- See Also:
- Constant Field Values
-
SELECTION_MODEL_PROPERTY
public static final java.lang.String SELECTION_MODEL_PROPERTY
Name of the selectionModel property.- See Also:
- Constant Field Values
-
CELL_RENDERER_PROPERTY
public static final java.lang.String CELL_RENDERER_PROPERTY
Name of the cellRenderer property.- See Also:
- Constant Field Values
-
ACTION_PROPERTY
public static final java.lang.String ACTION_PROPERTY
Name of the action property.- See Also:
- Constant Field Values
-
UI_PROPERTY
public static final java.lang.String UI_PROPERTY
Name of the UI property.- See Also:
- Constant Field Values
-
CSS_RESOURCE_NAME
public static final java.lang.String CSS_RESOURCE_NAME
Resource path to the user-agent CSS.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IlxWList
public IlxWList(javax.swing.ListModel model)
Constructs anIlxWList
that displays the elements in the specified, non-null model.All
IlxWList
constructors delegate to this one.- Throws:
java.lang.IllegalArgumentException
- IfdataModel
isnull
- Parameters:
model
- The data model for this list.
-
IlxWList
public IlxWList(java.lang.Object[] listData)
Constructs anIlxWList
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 anIlxWList
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
- TheIlxWListCellRenderer
that renders list cells.- See Also:
getCellRenderer()
-
getModel
public javax.swing.ListModel getModel()
Returns the data model that holds the list of items displayed by theIlxWList
component.- Returns:
- The list model that provides the displayed list of items.
- See Also:
setModel(javax.swing.ListModel)
-
setModel
public void setModel(javax.swing.ListModel model)
Sets the model that represents the contents or "value" of the list and clears the list selection after notifyingPropertyChangeListeners
.- Throws:
java.lang.IllegalArgumentException
- Ifmodel
isnull
.- Parameters:
model
- TheListModel
that provides the list of items for display.- See Also:
getModel()
-
setListData
public void setListData(java.lang.Object[] listData)
Constructs aListModel
from an array of objects and then appliessetModel
to it.- Parameters:
listData
- An array of Objects containing the items to display in the list.- See Also:
setModel(javax.swing.ListModel)
-
createSelectionModel
protected javax.swing.ListSelectionModel createSelectionModel()
Returns an instance ofDefaultListSelectionModel
.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 javax.swing.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)
NotifiesIlxWList
ListSelectionListener
s that the selection model has changed.It is used to forward
ListSelectionEvents
from theselectionModel
to theListSelectionListener
s added directly to theIlxWList
.- 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 javax.swing.event.ListSelectionListener[] getListSelectionListeners()
-
addListSelectionListener
public void addListSelectionListener(javax.swing.event.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 theirListSelectionEvent.getSource() == this IlxWList
(instead of theListSelectionModel
).- Parameters:
listener
- TheListSelectionListener
to add.- See Also:
getSelectionModel()
-
removeListSelectionListener
public void removeListSelectionListener(javax.swing.event.ListSelectionListener listener)
Removes a listener from the list that is notified each time a change to the selection occurs.- Parameters:
listener
- TheListSelectionListener
to remove.- See Also:
addListSelectionListener(javax.swing.event.ListSelectionListener)
,getSelectionModel()
-
setSelectionModel
public void setSelectionModel(javax.swing.ListSelectionModel selectionModel)
Sets theselectionModel
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:
java.lang.IllegalArgumentException
- IfselectionModel
isnull
.- Parameters:
selectionModel
- TheListSelectionModel
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:-
SINGLE_SELECTION
Only one list index can be selected at a time. In this mode thesetSelectionInterval
andaddSelectionInterval
methods are equivalent, and only the second index argument is used. -
SINGLE_INTERVAL_SELECTION
One contiguous index interval can be selected at a time. In this modesetSelectionInterval
andaddSelectionInterval
are equivalent. -
MULTIPLE_INTERVAL_SELECTION
In this mode, there is no restriction as to what can be selected. This is the default value.
- 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 recentaddSelectionModel
orsetSelectionInterval
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 recentaddSelectionInterval
orsetSelectionInterval
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 methodisSelectionEmpty
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 java.lang.Object getSelectedValue()
Returns the first selected value, ornull
if the selection is empty.- Returns:
- The first selected value.
- See Also:
getMinSelectionIndex()
,getModel()
,addListSelectionListener(javax.swing.event.ListSelectionListener)
-
setSelectedValue
public void setSelectedValue(java.lang.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 theperform
method callssetSelectedIndex
on the list.If the given action is a Java action (
IlxWJavaAction
), or a JavaScript action (IlxWJSAction
), the argument array passed to theperform
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 thesetAuthorRules
method.This method returns
null
by default but is intended to be redefined by subclasses.- Overrides:
getUserAgentRules
in classIlxWContainer
- Returns:
- a CSS ruleset.
- See Also:
IlxWContainer.setAuthorRules(ilog.webui.dhtml.IlxWCSSRuleset)
-
printComponent
protected void printComponent(IlxWPort port) throws java.io.IOException
Description copied from class:IlxWComponent
Prints the HTML code that will display the graphical representation of this component. This method is called by theIlxWComponent.print(ilog.webui.dhtml.IlxWPort)
method.- Specified by:
printComponent
in classIlxWComponent
- Throws:
java.io.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 byIlxWListCellRenderer.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 interfaceilog.webui.dhtml.IlxWDependencyProvider
- Overrides:
notifyDependencies
in classIlxWComponent
-
-