Class AbstractContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>

java.lang.Object
com.iizix.prop.content.AbstractContentProvider<ITEM,ITEM_CONTENT>
All Implemented Interfaces:
IContentProvider<ITEM,ITEM_CONTENT>, IContentProviderAPI<ITEM,ITEM_CONTENT>
Direct Known Subclasses:
MapMarkerContentProvider, MLContentProvider

public abstract class AbstractContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>> extends Object implements IContentProviderAPI<ITEM,ITEM_CONTENT>
The default content provider.
Author:
Christopher Mindus
  • Field Details Link icon

  • Constructor Details Link icon

    • AbstractContentProvider Link icon

      public AbstractContentProvider(int selectionType, Class<ITEM_CONTENT> itemContentClass)
      Constructor.
      Parameters:
      selectionType - The selection type: 0=none, 1=single, 2=multiple.
      itemContentClass - The class for item content.
  • Method Details Link icon

    • onSelectionTypeChanged Link icon

      public void onSelectionTypeChanged(int selectionType)
      Called when the content provider changes selection type.
      Specified by:
      onSelectionTypeChanged in interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Parameters:
      selectionType - The selection type: 0=none, 1=single, 2=multiple.
    • initialize Link icon

      public void initialize(AbstractContentUIContainer<ITEM,ITEM_CONTENT> cnr)
      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 interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Parameters:
      cnr - The container.
    • getItemsContainer Link icon

      public AbstractContentUIContainer<ITEM,ITEM_CONTENT> getItemsContainer()
      Returns the items container.
      Specified by:
      getItemsContainer in interface IContentProvider<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 Link icon

      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 interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
    • dispose Link icon

      public void dispose()
      Called when the content provider is no longer required by the container.
      Specified by:
      dispose in interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
    • canModifyWithAPI Link icon

      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 interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Returns:
      true if the API methods for modification can be used, false otherwise.
    • getTable Link icon

      public VSTable getTable()
      Gets the VSTable connected.
      Returns:
      The table, or null for none.
    • getColumns Link icon

      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 Link icon

      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 interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
    • commitChanges Link icon

      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 beginChanges() must be followed by a call to this method.

      Specified by:
      commitChanges in interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
    • refreshContent Link icon

      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 Link icon

      public void add(int index, ITEM_CONTENT item)
      Inserts a new item before the specified index. Duplicates are not allowed.
      Specified by:
      add in interface IContentProviderAPI<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 Link icon

      public ITEM_CONTENT remove(int index)
      Removes an item at the specified index.
      Specified by:
      remove in interface IContentProviderAPI<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 Link icon

      public boolean remove(ITEM_CONTENT item)
      Removes an item.
      Specified by:
      remove in interface IContentProviderAPI<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Parameters:
      item - The item to remove.
      Returns:
      true for success, false if not found.
    • removeAll Link icon

      public boolean removeAll()
      Removes all items.
      Specified by:
      removeAll in interface IContentProviderAPI<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Returns:
      true for changed, false when no items were present.
    • get Link icon

      public ITEM_CONTENT get(int index)
      Gets an item at the specified index.
      Specified by:
      get in interface IContentProviderAPI<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 Link icon

      public int indexOf(ITEM_CONTENT item)
      Returns the index of an item.
      Specified by:
      indexOf in interface IContentProviderAPI<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 Link icon

      public int getFirstSelectedIndex()
      Gets the first selected index.
      Specified by:
      getFirstSelectedIndex in interface IContentProviderAPI<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Returns:
      The first index in the current selection, or -1 for none.
    • getSelectedIndicies Link icon

      public int[] getSelectedIndicies()
      Gets the selected indicies.
      Specified by:
      getSelectedIndicies in interface IContentProviderAPI<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 Link icon

      public String setSelection(int index)
      Sets the selection as a single selected item at specified index.
      Specified by:
      setSelection in interface IContentProviderAPI<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 Link icon

      public String setSelection(int[] indicies)
      Sets the selection to the specified indicies.
      Specified by:
      setSelection in interface IContentProviderAPI<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 Link icon

      public String clearSelection()
      Clear the selection.
      Specified by:
      clearSelection in interface IContentProviderAPI<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Returns:
      null for success, otherwise the error message with the reason why it failed.
    • onSelectionChanged Link icon

      public void onSelectionChanged(ITEM_CONTENT item, boolean isSelected)
      Called from the items when they are selected or unselected from their setSelection(boolean) method.

      The method is NOT intended to be called.

      Specified by:
      onSelectionChanged in interface IContentProviderAPI<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Parameters:
      item - The item who's selection changed.
      isSelected - The new selection state.
    • getItemCount Link icon

      public int getItemCount()
      Gets the item count.
      Specified by:
      getItemCount in interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Returns:
      The count of items that will be provided.
    • getAll Link icon

      public ITEM_CONTENT[] getAll()
      Gets the content items.
      Specified by:
      getAll in interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Specified by:
      getAll in interface IContentProviderAPI<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
      Returns:
      The array of content items.
    • updateContents Link icon

      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 interface IContentProvider<ITEM extends IContentItem,ITEM_CONTENT extends IContentData<ITEM>>
    • updateContentsFromVS Link icon

      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 Link icon

      public boolean onAdded(VSRow row, int index)
      Called when a VSRow is added in the connected table.
      Specified by:
      onAdded in interface IContentProvider<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 Link icon

      public boolean onRemoved(VSRow row, int index)
      Called when a VSRow is removed in the connected table.
      Specified by:
      onRemoved in interface IContentProvider<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 Link icon

      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 Link icon

      protected abstract ITEM_CONTENT createContentItem(VSRow row)
      Creates a new content item for a VS row.
      Parameters:
      row - The row.
      Returns:
      The new content item associated with the row.
    • refreshContentItemFromVS Link icon

      protected void refreshContentItemFromVS(ITEM_CONTENT itemData, int[] columns)
      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 Link icon

      protected boolean isVisibleStateSynchronized()
      Returns if the visible state is synchronized with the table.
      Returns:
      true by default, override for other functionality.
    • isEnabledStateSynchronized Link icon

      protected boolean isEnabledStateSynchronized()
      Returns if the enabled state is synchronized with the table.
      Returns:
      true by default, override for other functionality.
    • isReadOnlyStateSynchronized Link icon

      protected boolean isReadOnlyStateSynchronized()
      Returns if the read-only state is synchronized with the table.
      Returns:
      true by default, override for other functionality.