Class AbstractContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
- All Implemented Interfaces:
IContentProvider<ITEM,
,ITEM_CONTENT> IContentProviderAPI<ITEM,
ITEM_CONTENT>
- Direct Known Subclasses:
MapMarkerContentProvider
,MLContentProvider
- Author:
- Christopher Mindus
Field Summary
Modifier and TypeFieldDescriptionprotected AbstractContentUIContainer
<ITEM, ITEM_CONTENT> The container.Constructor Summary
ConstructorDescriptionAbstractContentProvider
(int selectionType, Class<ITEM_CONTENT> itemContentClass) Constructor.Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, ITEM_CONTENT item) Inserts a new item before the specified index.void
Begins a mass change operation of the content by means of the API.boolean
Returns if API is enabled for this content provider or not.Clear the selection.void
Commits a mass change operation of the content by means of the API.protected abstract ITEM_CONTENT
createContentItem
(VSRow row) Creates a new content item for a VS row.void
dispose()
Called when the content provider is no longer required by the container.get
(int index) Gets an item at the specified index.getAll()
Gets the content items.int[]
Gets the connected table columns indicies.int
Gets the first selected index.int
Gets the item count.Returns the items container.int[]
Gets the selected indicies.getTable()
Gets the VSTable connected.int
indexOf
(ITEM_CONTENT item) Returns the index of an item.void
Called to initialize the content provider for the container instance.protected boolean
Returns if the enabled state is synchronized with the table.protected boolean
Returns if the read-only state is synchronized with the table.protected boolean
Returns if the visible state is synchronized with the table.boolean
Called when a VSRow is added in the connected table.boolean
Called when a VSRow is removed in the connected table.void
onSelectionChanged
(ITEM_CONTENT item, boolean isSelected) Called from the items when they are selected or unselected from theirsetSelection(boolean)
method.void
onSelectionTypeChanged
(int selectionType) Called when the content provider changes selection type.protected void
Refreshes the contents with the container.protected void
refreshContentItemFromVS
(ITEM_CONTENT itemData, int[] columns) Refresh the content item after a potential change in the VirtualSpace with an existing item.void
This method is called when the content provider needs re-initialization due to e.g.remove
(int index) Removes an item at the specified index.boolean
remove
(ITEM_CONTENT item) Removes an item.boolean
Removes all items.setSelection
(int index) Sets the selection as a single selected item at specified index.setSelection
(int[] indicies) Sets the selection to the specified indicies.void
Updates all the items to match the current contents.protected void
updateContentsFromVS
(int[] columns) Called to update the items from the VirtualSpace only if such a connection exists.protected boolean
useVSConnection
(int[] columnIndicies) Called during initialization to determine if content items will need to use the VS row connection or not.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.iizix.prop.content.IContentProviderAPI
add
Field Details
cnr
protected AbstractContentUIContainer<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>> cnrThe container.
Constructor Details
AbstractContentProvider
Constructor.- Parameters:
selectionType
- The selection type: 0=none, 1=single, 2=multiple.itemContentClass
- The class for item content.
Method Details
onSelectionTypeChanged
public void onSelectionTypeChanged(int selectionType) Called when the content provider changes selection type.- Specified by:
onSelectionTypeChanged
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
selectionType
- The selection type: 0=none, 1=single, 2=multiple.
initialize
Called to initialize the content provider for the container instance.The default content provides saves the
cnr
reference and calls
.reinitialize()
- Specified by:
initialize
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
cnr
- The container.
getItemsContainer
Returns the items container.- Specified by:
getItemsContainer
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Returns:
- The container that stores the item properties. This method will return null if not yet initialized.
reinitialize
public void reinitialize()This method is called when the content provider needs re-initialization due to e.g. a change of its properties, e.g. the VSTable or one of the columns.The default content retrieves the VS table and columns and saves them for future reference.
- Specified by:
reinitialize
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>>
dispose
public void dispose()Called when the content provider is no longer required by the container.- Specified by:
dispose
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>>
canModifyWithAPI
public boolean canModifyWithAPI()Returns if API is enabled for this content provider or not. If the content provider is connected to VirtualSpace, this method will return false.- Specified by:
canModifyWithAPI
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Returns:
- true if the API methods for modification can be used, false otherwise.
getTable
Gets the VSTable connected.- Returns:
- The table, or null for none.
getColumns
public int[] getColumns()Gets the connected table columns indicies.- Returns:
- The array of connected table column indicies, null if not VS-connected. A column index in the array may be -1 if it is not referenced or used.
beginChanges
public void beginChanges()Begins a mass change operation of the content by means of the API. Call this method to avoid updates being fired to the client before all changes are committed.A call to this method must be followed by a call to
.commitChanges()
- Specified by:
beginChanges
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>>
commitChanges
public void commitChanges()Commits a mass change operation of the content by means of the API. This method will fire the updates to the client.Each call to
must be followed by a call to this method.beginChanges()
- Specified by:
commitChanges
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>>
refreshContent
protected void refreshContent()Refreshes the contents with the container. If one or more mass change operations are taking place, this method flags changes to be performed when all mass change operations are committed.add
Inserts a new item before the specified index. Duplicates are not allowed.- Specified by:
add
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
index
- The insertion point index, -1 for last.item
- The item to insert.- Throws:
IllegalArgumentException
- If the index is not valid.
remove
Removes an item at the specified index.- Specified by:
remove
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
index
- The item to remove.- Returns:
- The removed item.
- Throws:
IllegalArgumentException
- If the index is not valid.
remove
Removes an item.- Specified by:
remove
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
item
- The item to remove.- Returns:
- true for success, false if not found.
removeAll
public boolean removeAll()Removes all items.- Specified by:
removeAll
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Returns:
- true for changed, false when no items were present.
get
Gets an item at the specified index.- Specified by:
get
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
index
- The index of the item.- Returns:
- The item.
- Throws:
IllegalArgumentException
- If the index is not valid.
indexOf
Returns the index of an item.- Specified by:
indexOf
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
item
- The item to look-up.- Returns:
- The index of the item, or -1 if not found.
getFirstSelectedIndex
public int getFirstSelectedIndex()Gets the first selected index.- Specified by:
getFirstSelectedIndex
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Returns:
- The first index in the current selection, or -1 for none.
getSelectedIndicies
public int[] getSelectedIndicies()Gets the selected indicies.- Specified by:
getSelectedIndicies
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Returns:
- A new array of the selected indices (that may be modified to your liking), or a static zero in length array for no selection.
setSelection
Sets the selection as a single selected item at specified index.- Specified by:
setSelection
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
index
- The single item to select at index, -1 to clear the selection.- Returns:
- null for success, otherwise an error message why the selection failed.
setSelection
Sets the selection to the specified indicies.- Specified by:
setSelection
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
indicies
- The indicies.- Returns:
- null for success, otherwise the error message with the reason why it failed.
clearSelection
Clear the selection.- Specified by:
clearSelection
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Returns:
- null for success, otherwise the error message with the reason why it failed.
onSelectionChanged
Called from the items when they are selected or unselected from theirsetSelection(boolean)
method.The method is NOT intended to be called.
- Specified by:
onSelectionChanged
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
item
- The item who's selection changed.isSelected
- The new selection state.
getItemCount
public int getItemCount()Gets the item count.- Specified by:
getItemCount
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Returns:
- The count of items that will be provided.
getAll
Gets the content items.- Specified by:
getAll
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Specified by:
getAll
in interfaceIContentProviderAPI<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Returns:
- The array of content items.
updateContents
public void updateContents()Updates all the items to match the current contents.This method is not intended to be called, it is used by the framework -- DO NOT CALL THE METHOD!
Override this method to perform specialized processing.
Note: this method is always called from the content updater thread, i.e. the client worker thread.
- Specified by:
updateContents
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>>
updateContentsFromVS
protected void updateContentsFromVS(int[] columns) Called to update the items from the VirtualSpace only if such a connection exists.- Parameters:
columns
- The connected table columns.
onAdded
Called when a VSRow is added in the connected table.- Specified by:
onAdded
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
row
- The row added.index
- The row index added (-1 or table size for last).- Returns:
- true for success, false to cause a refresh of the containers content.
onRemoved
Called when a VSRow is removed in the connected table.- Specified by:
onRemoved
in interfaceIContentProvider<ITEM extends IContentItem,
ITEM_CONTENT extends IContentData<ITEM>> - Parameters:
row
- The row removed.index
- The row index removed.- Returns:
- true for success, false to cause a refresh of the containers content.
useVSConnection
protected boolean useVSConnection(int[] columnIndicies) Called during initialization to determine if content items will need to use the VS row connection or not. By default, VS connection is used only when at least one column is connected to a row.A custom content provider can override this method to return
true
.The default implementation is to return true if at least one column index is larger than -1.
- Parameters:
columnIndicies
- The column indicies, null for none.- Returns:
- true to use a VS connection, false not to use a VS connection.
createContentItem
Creates a new content item for a VS row.- Parameters:
row
- The row.- Returns:
- The new content item associated with the row.
refreshContentItemFromVS
Refresh the content item after a potential change in the VirtualSpace with an existing item.A custom content provider can override this method to provide an alternate refresh method for it's items.
By default, the item's method
refreshFromVS(int [] columns)
is called.- Parameters:
itemData
- The item previously created.columns
- The connected table columns indicies, -1 for none.
isVisibleStateSynchronized
protected boolean isVisibleStateSynchronized()Returns if the visible state is synchronized with the table.- Returns:
- true by default, override for other functionality.
isEnabledStateSynchronized
protected boolean isEnabledStateSynchronized()Returns if the enabled state is synchronized with the table.- Returns:
- true by default, override for other functionality.
isReadOnlyStateSynchronized
protected boolean isReadOnlyStateSynchronized()Returns if the read-only state is synchronized with the table.- Returns:
- true by default, override for other functionality.