Package com._1c.g5.lwt.controls
Class LightList<T>
- java.lang.Object
-
- com._1c.g5.lwt.AbstractLightControl
-
- com._1c.g5.lwt.controls.AbstractScrollableControl
-
- com._1c.g5.lwt.controls.LightList<T>
-
- Type Parameters:
T
- - class of data in list items.
- All Implemented Interfaces:
ILightControl
public class LightList<T> extends AbstractScrollableControl
Instance of this class represents list. List contains collection of items. Each list item has text and image. (text can be empty and image can be
null
)List can have no scrolls, horizontal scroll, vertical scroll, or horizontal and vertical scrolls.
List can have single or multi selection style.
List can be drawn with or without border.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addItem(LightListItem<T> item)
Adds item to list.void
addItem(LightListItem<T> item, int position)
Inserts item to list at given position.void
addItems(Collection<LightListItem<T>> items)
Adds items to list.void
addItems(Collection<LightListItem<T>> items, int position)
Adds items to list.void
addSelectionListener(ISelectionChangedListener<T> selectionListener)
Adds light list selection listener.void
clearItems()
Removes all items from list.org.eclipse.swt.graphics.Point
computeSize(org.eclipse.swt.graphics.GC gc, int width, int height, boolean flushCache)
Computes the size of this control.void
deselectAll()
Deselects all list items.void
deselectItem(int index)
Deselects item with given index.void
deselectItem(LightListItem<T> item)
Deselects given item.void
deselectItems(Collection<LightListItem<T>> items)
Deselects given items.void
deselectItemsByIndexes(Collection<Integer> indexes)
Deselects items with given indexes.org.eclipse.swt.graphics.Color
getBackgroundColor()
Returns list background color.protected org.eclipse.swt.graphics.Point
getContentSize()
Returns size of control content.LightListItem<T>
getFocusedItem()
Returns focused item.List<LightListItem<T>>
getItems()
Returns list items.int
getItemsCount()
Return list items count.int
getLineHeight()
Returns line height.org.eclipse.swt.widgets.Menu
getMenu()
Returns list menu.Collection<LightListItem<T>>
getSelectedItems()
Returns selected items.Collection<Integer>
getSelection()
Returns indexes of selected items.protected void
handleTranslatedEvent(org.eclipse.swt.widgets.Event event)
Process event with translated coordinates.void
invalidate(LightListItem<T> item)
Invalidates given list item.boolean
isSelected(int index)
Returnstrue
if item with given index is selected.boolean
isSelected(LightListItem<T> item)
Returnstrue
if given item is selected.void
paint(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rectangle)
Paints the given rectangle of this control.protected void
recalculateScrollRange()
Recalculates scroll range.void
removeItem(int index)
Removes item with given index from list.void
removeItem(LightListItem<T> item)
Removes item from list.void
removeItems(Collection<LightListItem<T>> items)
Removes given items from list.void
removeItemsByIndexes(Collection<Integer> indexes)
Removes items with given indexes from list.void
removeSelectionListener(ISelectionChangedListener<T> selectionListener)
Removes light list selection listener.void
scrollToSelection()
Scrolls to first selected item.void
selectItem(int index)
Select item with given index.void
selectItem(LightListItem<T> item)
Selects given item.void
selectItems(Collection<LightListItem<T>> items)
Selects given items.void
selectItemsByIndexes(Collection<Integer> indexes)
Selects items with given indexes.void
setBackgroundColor(org.eclipse.swt.graphics.Color backgroundColor)
Sets list background color.void
setFocusedItem(int index)
Sets focused item index.void
setFocusedItem(LightListItem<T> item)
Sets focused item.void
setItem(int index, LightListItem<T> item)
Replaces item with given index.void
setItems(List<LightListItem<T>> items)
Sets list items.void
setMenu(org.eclipse.swt.widgets.Menu menu)
Sets list menu.-
Methods inherited from class com._1c.g5.lwt.controls.AbstractScrollableControl
getClientArea, getScrollPosition, getScrollRange, getScrollsStyle, getViewportBounds, handleEvent, scrollBy, scrollHorizontallyBy, scrollHorizontallyTo, scrollTo, scrollVerticallyBy, scrollVerticallyTo, setBounds, setScrollRange
-
Methods inherited from class com._1c.g5.lwt.AbstractLightControl
addControlListener, dispose, getBounds, getCursor, getData, getLayoutData, getOverlay, getParent, getTooltip, getVisibleBounds, invalidate, invalidate, isDisposed, isEnabled, isFocused, isVisible, removeControlListener, setCursor, setData, setEnabled, setFocus, setFocusable, setLayoutData, setOverlay, setParent, setTooltip, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com._1c.g5.lwt.ILightControl
initialize
-
-
-
-
Constructor Detail
-
LightList
public LightList()
Constructs light list withSWT.MULTI
selection style,SWT.VERTICAL
scroll bars style and border.
-
LightList
public LightList(int style)
Constructor.- Parameters:
style
- - list style (selection can beSWT.SINGLE
orSWT.MULTI
, scrolls style can beSWT.VERTICAL
andSWT.HORIZONTAL
, one of them or none, to draw border passSWT.BORDER
.- See Also:
SWT.SINGLE
,SWT.MULTI
,SWT.VERTICAL
,SWT.HORIZONTAL
,SWT.BORDER
-
-
Method Detail
-
addSelectionListener
public void addSelectionListener(ISelectionChangedListener<T> selectionListener)
Adds light list selection listener.- Parameters:
selectionListener
- - listener to add. Cannot benull
.
-
removeSelectionListener
public void removeSelectionListener(ISelectionChangedListener<T> selectionListener)
Removes light list selection listener.- Parameters:
selectionListener
- - listener to remove. Cannot benull
.
-
addItem
public void addItem(LightListItem<T> item)
Adds item to list.- Parameters:
item
- - item to add. Cannot benull
.
-
addItem
public void addItem(LightListItem<T> item, int position)
Inserts item to list at given position.- Parameters:
item
- - item to insert. Cannot benull
.position
- - position to insert to. Should be non negative and less then items count.
-
addItems
public void addItems(Collection<LightListItem<T>> items)
Adds items to list.- Parameters:
items
- - items to add. Cannot benull
.
-
addItems
public void addItems(Collection<LightListItem<T>> items, int position)
Adds items to list.- Parameters:
items
- - items to add. Cannot benull
.position
- - position to insert to. Should be non negative and less then items count.
-
setItem
public void setItem(int index, LightListItem<T> item)
Replaces item with given index.- Parameters:
index
- - index of item to replace. Should be non negative and less then items count.item
- - item to set. Cannot benull
.
-
setItems
public void setItems(List<LightListItem<T>> items)
Sets list items.- Parameters:
items
- - items to set. Cannot benull
.
-
removeItem
public void removeItem(LightListItem<T> item)
Removes item from list.- Parameters:
item
- - item to remove. Cannot benull
.
-
removeItems
public void removeItems(Collection<LightListItem<T>> items)
Removes given items from list.- Parameters:
items
- - items to remove. Cannot benull
.
-
removeItem
public void removeItem(int index)
Removes item with given index from list.- Parameters:
index
- - index of item to remove. Should be non negative and less then items count.
-
removeItemsByIndexes
public void removeItemsByIndexes(Collection<Integer> indexes)
Removes items with given indexes from list.- Parameters:
indexes
- - indexes of items to remove. Cannot benull
.
-
clearItems
public void clearItems()
Removes all items from list.
-
getItems
public List<LightListItem<T>> getItems()
Returns list items.- Returns:
- list items. Cannot return
null
.
-
getItemsCount
public int getItemsCount()
Return list items count.- Returns:
- list items count.
-
getSelectedItems
public Collection<LightListItem<T>> getSelectedItems()
Returns selected items.- Returns:
- selected items. Cannot return
null
.
-
getSelection
public Collection<Integer> getSelection()
Returns indexes of selected items.- Returns:
- indexes of selected items. Cannot return
null
.
-
setBackgroundColor
public void setBackgroundColor(org.eclipse.swt.graphics.Color backgroundColor)
Sets list background color.- Parameters:
backgroundColor
- - background color. Cannot benull
.
-
getBackgroundColor
public org.eclipse.swt.graphics.Color getBackgroundColor()
Returns list background color.- Returns:
- list background color. Cannot return
null
.
-
selectItem
public void selectItem(LightListItem<T> item)
Selects given item.- Parameters:
item
- - item to select. Cannot benull
.
-
selectItem
public void selectItem(int index)
Select item with given index.- Parameters:
index
- - index of item to select. Index should be non negative and less then items count.
-
selectItems
public void selectItems(Collection<LightListItem<T>> items)
Selects given items. Selects only first item if style isSWT.SINGLE
.- Parameters:
items
- - items to select. Cannot benull
.
-
selectItemsByIndexes
public void selectItemsByIndexes(Collection<Integer> indexes)
Selects items with given indexes. Selects only first item if style isSWT.SINGLE
.- Parameters:
indexes
- - indexes of items to select. Each index should be non negative and less then items count. Cannot benull
.
-
deselectItem
public void deselectItem(LightListItem<T> item)
Deselects given item.- Parameters:
item
- - item to deselect. Cannot benull
.
-
deselectItem
public void deselectItem(int index)
Deselects item with given index.- Parameters:
index
- - index of item to deselect. Index should be non negative and less then items count.
-
deselectItems
public void deselectItems(Collection<LightListItem<T>> items)
Deselects given items.- Parameters:
items
- - items to deselect. Cannot benull
.
-
deselectItemsByIndexes
public void deselectItemsByIndexes(Collection<Integer> indexes)
Deselects items with given indexes.- Parameters:
indexes
- - indexes of items to deselect. Each index should be non negative and less then items count. Cannot benull
.
-
deselectAll
public void deselectAll()
Deselects all list items.
-
isSelected
public boolean isSelected(LightListItem<T> item)
Returnstrue
if given item is selected.- Parameters:
item
- - item to check. Cannot benull
.- Returns:
true
if given item is selected.
-
isSelected
public boolean isSelected(int index)
Returnstrue
if item with given index is selected.- Parameters:
index
- - index to check.- Returns:
true
if item with given index is selected.
-
scrollToSelection
public void scrollToSelection()
Scrolls to first selected item. If there is no selected item does nothing.
-
invalidate
public void invalidate(LightListItem<T> item)
Invalidates given list item.- Parameters:
item
- - item to invalidate. Cannot benull
.
-
getLineHeight
public int getLineHeight()
Returns line height.- Returns:
- line height.
-
setMenu
public void setMenu(org.eclipse.swt.widgets.Menu menu)
Sets list menu.- Parameters:
menu
- - menu to set. Can benull
.
-
getMenu
public org.eclipse.swt.widgets.Menu getMenu()
Returns list menu.- Returns:
- menu. Can return
null
.
-
setFocusedItem
public void setFocusedItem(int index)
Sets focused item index. Index should be non negative and less then items count.- Parameters:
index
- - index of item to set focused.
-
setFocusedItem
public void setFocusedItem(LightListItem<T> item)
Sets focused item.- Parameters:
item
- - item to set focused. Can benull
.
-
getFocusedItem
public LightListItem<T> getFocusedItem()
Returns focused item.- Returns:
- focused item. Can return
null
.
-
computeSize
public org.eclipse.swt.graphics.Point computeSize(org.eclipse.swt.graphics.GC gc, int width, int height, boolean flushCache)
Description copied from interface:ILightControl
Computes the size of this control.- Specified by:
computeSize
in interfaceILightControl
- Overrides:
computeSize
in classAbstractLightControl
- Parameters:
gc
- the GC to do measurements with.width
- the width hint,SWT.DEFAULT
to compute the preferred width.height
- the height hint,SWT.DEFAULT
to compute the preferred height.flushCache
- the flush cache flag, instructs the associated layout to reset all its caches, if any.- Returns:
- the computed size.
-
paint
public void paint(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rectangle)
Description copied from interface:ILightControl
Paints the given rectangle of this control.- Specified by:
paint
in interfaceILightControl
- Overrides:
paint
in classAbstractScrollableControl
- Parameters:
gc
- theGC
to paint on.rectangle
- the rectangle to paint.
-
handleTranslatedEvent
protected void handleTranslatedEvent(org.eclipse.swt.widgets.Event event)
Description copied from class:AbstractScrollableControl
Process event with translated coordinates.- Specified by:
handleTranslatedEvent
in classAbstractScrollableControl
- Parameters:
event
- - event to process. Cannot benull
.
-
getContentSize
protected org.eclipse.swt.graphics.Point getContentSize()
Description copied from class:AbstractScrollableControl
Returns size of control content.- Specified by:
getContentSize
in classAbstractScrollableControl
- Returns:
- size of control content. Cannot return
null
.
-
recalculateScrollRange
protected void recalculateScrollRange()
Description copied from class:AbstractScrollableControl
Recalculates scroll range.- Overrides:
recalculateScrollRange
in classAbstractScrollableControl
-
-