Class VSTable

All Implemented Interfaces:
EventListener, IFocusComp, IMessageBox, ICustomDataProvider, IGProp<GProp<?>[]>, IPropCnr, IVSComponent, IVSComponentListener, IVSComponentState, IVSMessageComponent, Cloneable
Direct Known Subclasses:
EditorVSTable

public class VSTable extends VSComponent implements IVSMessageComponent
The VirtualSpace Table property class holds the property name, value and optionally has a parent and/or property listener(s).

It is used to hold a table with a column count with a variable number of rows. It has an optional header row.

Author:
Christopher Mindus
  • Field Details Link icon

    • EMPTY_LISTENERS Link icon

      public static final IVSTableListener[] EMPTY_LISTENERS
      Empty list of listeners.
    • rows Link icon

      protected VSRows rows
      The rows property.
  • Constructor Details Link icon

    • VSTable Link icon

      public VSTable()
      Creates a VirtualSpace Table property with the specified name with a null value.
    • VSTable Link icon

      public VSTable(Atom propertyAtom)
      Creates a VirtualSpace Table property with the specified name with a null value.
      Parameters:
      propertyAtom - the property atom.
  • Method Details Link icon

    • clone Link icon

      public VSTable clone()
      Clones the VirtualSpace Table.
      Overrides:
      clone in class VSComponent
    • addPredefinedProps Link icon

      protected void addPredefinedProps() throws PropException
      Adds the predefined containers for identifications, fields and actions.
      Overrides:
      addPredefinedProps in class PropCnr
      Throws:
      PropException - for property exceptions.
    • getPredefinedProps Link icon

      protected void getPredefinedProps()
      Adds the predefined containers for identifications, fields and actions. This method is overridden fully by the Editor versions of the class.
      Overrides:
      getPredefinedProps in class PropCnr
    • getComponentIsHidden Link icon

      public String getComponentIsHidden()
      Gets the focus message for "Component is hidden" but for the component in question.
      Specified by:
      getComponentIsHidden in class VSComponent
    • getComponentIsDisabled Link icon

      public String getComponentIsDisabled()
      Gets the focus message for "Component is disabled" but for the component in question.
      Specified by:
      getComponentIsDisabled in class VSComponent
    • invokeOnVSCreateTree Link icon

      protected final void invokeOnVSCreateTree(VirtualSpace vs)
      Invokes the onVSCreate method for the component if a VirtualSpace is present. This method should only be invoked when a component is resolved during the post-resolve virtualization process, or when a component is added into an already virtualized VS component tree.

      The OnVSCreate method is called first for the table, then the column headers, then for all rows.

      Overrides:
      invokeOnVSCreateTree in class VSComponent
      Parameters:
      vs - The VirtualSpace instance.
      Throws:
      NullPointerException - If the vs is null.
    • onEventSelf Link icon

      public void onEventSelf(GEvent event)
      Checks for state change events and fires it to listeners.
      Specified by:
      onEventSelf in interface IGProp<GProp<?>[]>
      Overrides:
      onEventSelf in class VSComponent
      Parameters:
      event - The property event.
    • onParentStateChanged Link icon

      public void onParentStateChanged(IVSComponent parent, IVSComponentState.State state, boolean stateValue)
      Invokes the parent state notification function for the component.
      Specified by:
      onParentStateChanged in interface IVSComponentListener
      Parameters:
      parent - The parent who's state was changed.
      state - The state that changed.
      stateValue - The new state value.
    • addListener Link icon

      public boolean addListener(IVSTableListener listener)
      Adds a new listener to the VS table.
      Parameters:
      listener - The listener for VS table events.
      Returns:
      true for success, false if the listener already is added.
    • removeListener Link icon

      public boolean removeListener(IVSTableListener listener)
      Removes a listener from the VS table.
      Parameters:
      listener - The existing listener for VS table events.
      Returns:
      true for success, false if the listener has not been added.
    • onListenerChanged Link icon

      protected void onListenerChanged(IVSTableListener listener)
      Called when a listener is added or removed. This method is overridden by the Designer to update connections.
    • getTableListeners Link icon

      public IVSTableListener[] getTableListeners()
      Gets the listeners of the VS table events.
      Returns:
      A cached array of listeners for the value, retrieved without synchronization if possible.
    • createRows Link icon

      protected VSRows createRows()
      Creates the rows property container.
    • createRow Link icon

      protected VSRow createRow(Atom a, VSColumnHeader[] columns) throws PropException
      Creates a row property with column headers.
      Throws:
      PropException - For creation error.
    • createRow Link icon

      protected VSRow createRow(Atom a, VSField[] fields) throws PropException
      Creates a row property with fields.
      Throws:
      PropException - For creation error.
    • createRow Link icon

      protected VSRow createRow(Atom a, Value[] values) throws PropException
      Creates a row property with values.
      Throws:
      PropException - For creation error.
    • getRowCount Link icon

      public int getRowCount()
      Gets the row count.
    • getRows Link icon

      public VSRow[] getRows()
      Gets the rows in this table.
      Returns:
      The array of rows.
    • getRow Link icon

      public VSRow getRow(int row)
      Gets the row of a certain index.

      Note: a warning message is logged if the operation fails.

      Parameters:
      row - The row index to get, must be zero to count of rows - 1 inclusive.
      Returns:
      The VSRowProp of VSFields, null if row is invalid.
    • getRowFields Link icon

      public VSField[] getRowFields(int row)
      Gets the fields for a row of a certain index.
      Parameters:
      row - The row index to get, must be zero to count of rows - 1 inclusive.
      Returns:
      The array of VSFields, null if row is invalid.
    • getRowValues Link icon

      public Value[] getRowValues(int row)
      Gets the values for a row of a certain index.
      Parameters:
      row - The row index to get, must be zero to count of rows - 1 inclusive.
      Returns:
      The array of VSFields, null if row is invalid.
    • addRow Link icon

      public VSRow addRow(VSField[] fields)
      Adds a row of VSField's.

      Note: a warning message is logged if the operation fails.

      Note 2: the operation will fail if any of the fields in the array are not new instances from a "new" or "clone" operation. This means that they cannot have been attached to a VS container previously.

      Parameters:
      fields - The row of fields to add as an array.
      Returns:
      The VSRow inserted if successful, null for failure.
    • addRow Link icon

      public VSRow addRow(Value[] values)
      Adds a row of Value's.

      Note: a warning message is logged if the operation fails.

      Note 2: the operation will fail if the values do not correspond to the column header field settings, i.e. null allowed and the value type of the column.

      Parameters:
      values - The row of values to add as an array.
      Returns:
      The VSRow inserted if successful, null for failure.
    • insertRow Link icon

      public VSRow insertRow(VSField[] fields, int before)
      Inserts a row of VSField's.

      A selection event is not fired, even if the selection changes, e.g. if the row inserted caused the selection index or indicies to change. If you need to fire a selection change, you may do so by calling the method fireRowSelection().

      Note: a warning message is logged if the operation fails.

      Note 2: the operation will fail if any of the fields in the array are not new instances from a "new" or "clone" operation. This means that they cannot have been attached to a VS container previously.

      Parameters:
      fields - The row of fields to add as an array.
      before - The row index that will these fields will be inserted before, -1 to add last in table.
      Returns:
      The VSRow inserted if successful, null for failure.
    • insertRow Link icon

      public VSRow insertRow(Value[] values, int before)
      Inserts a row of Value's.

      A selection event is not fired, even if the selection changes, e.g. if the row inserted caused the selection index or indicies to change. If you need to fire a selection change, you may do so by calling the method fireRowSelection().

      Note: a warning message is logged if the operation fails.

      Note 2: the operation will fail if the values do not correspond to the column header field settings, i.e. null allowed and the value type of the column.

      Parameters:
      values - The row of values to add as an array.
      before - The row index that will these fields will be inserted before, -1 to add last in table.
      Returns:
      The VSRow inserted if successful, null for failure.
    • setRow Link icon

      public boolean setRow(VSField[] fields, int row)
      Sets a row's all fields without affecting the state of the row.

      Note: a warning message is logged if the operation fails.

      Parameters:
      fields - The row of fields to set as an array.
      row - The row index to set, must be zero to count of rows - 1 inclusive.
      Returns:
      true if this changed successfully the table, false otherwise.
    • removeRow Link icon

      public boolean removeRow(int row)
      Removes a row.

      A selection event is not fired, even if the selection changes, e.g. if the row deleted was selected. If you need to fire a selection change, you may do so by calling the method fireRowSelection().

      Note: a warning message is logged if the operation fails.

      Parameters:
      row - The row index to remove, must be zero to count of rows - 1 inclusive.
      Returns:
      true if this changed successfully the table, false otherwise.
    • clear Link icon

      public boolean clear()
      Clears the table, i.e. removes all rows.

      A selection event is not fired. If you need to fire a selection change, you may do so by calling the method fireRowSelection().

      Note: a warning message is logged if the operation fails.

      Returns:
      true if this changed successfully the table, false otherwise.
    • getRowsContainer Link icon

      public VSRows getRowsContainer()
      Gets the rows property container.
      Returns:
      The VSRows container.
    • invokeVSChange Link icon

      public void invokeVSChange(GProp<?> trigger)
      Invokes the VSChange method on the table.
      Parameters:
      trigger - The trigger property, e.g. row added, etc.
    • createHeader Link icon

      protected VSRow createHeader()
      Creates the header property container.
    • getHeader Link icon

      public VSRow getHeader()
      Gets the header.
      Returns:
      The row of VSColumnHeader properties of the header.
    • getColumnHeaders Link icon

      public VSColumnHeader[] getColumnHeaders()
      Gets the headers columns for the table.
      Returns:
      The array of VSColumnHeader for the table.
    • getColumnHeader Link icon

      public VSColumnHeader getColumnHeader(int columnIndex)
      Gets the headers columns for the row.
      Parameters:
      columnIndex - The index of the column.
      Returns:
      The column of requested index, null if the column index is out of range.
    • getColumnHeader Link icon

      public VSColumnHeader getColumnHeader(String columnName)
      Gets the header column by name.
      Parameters:
      columnName - The column name.
      Returns:
      The column header, or null if the column name is not found.
    • getColumnCount Link icon

      public int getColumnCount()
      Gets the column count.
      Returns:
      The count of columns.
    • setHeader Link icon

      public boolean setHeader(VSColumnHeader[] columns)
      Sets the header.

      Note: a warning message is logged if the operation fails.

      Parameters:
      columns - The header columns to set as an array.
      Returns:
      true if this changed successfully the table, false otherwise.
    • getSelectionType Link icon

      public int getSelectionType()
      Gets the selection type.
      Returns:
      The table selection type: 0=none, 1=single (default), 2=multiple.
    • isSelectionRequired Link icon

      public boolean isSelectionRequired()
      Returns the selection required flag.
      Returns:
      true if selection is required, false otherwise (default).
    • getFirstSelectedRow Link icon

      public VSRow getFirstSelectedRow()
      Gets the first selected row in the table if the selection type is single or multiple.
      Returns:
      The selected row, null for none.
    • getSelectedRows Link icon

      public VSRow[] getSelectedRows()
      Gets the rows that are selected.
      Returns:
      An array with the selected rows, never null.
    • getSelectedIndex Link icon

      public int getSelectedIndex()
      Gets the first selected row index in the table if the selection type is single or multiple.
      Returns:
      The selected row index, or -1 for none.
    • getSelectedIndicies Link icon

      public int[] getSelectedIndicies()
      Gets the selected row indicies in the table if the selection type is single or multiple.
      Returns:
      An array of the selected row indicies, or an empty array for no selection present.
    • clearSelection Link icon

      public boolean clearSelection()
      Clears the selection without trigger component.
      Returns:
      true for success, false if the table is not of single or multiple selection type. In case of false return code, no unselection is performed.
    • clearSelection Link icon

      public boolean clearSelection(IGProp<?> trigger)
      Clears the selection with optional trigger component.
      Parameters:
      trigger - The trigger of the selection, null for none.
      Returns:
      true for success, false if the table is not of single or multiple selection type. In case of false return code, no unselection is performed.
    • setSelection Link icon

      public boolean setSelection(int index)
      Sets the single selection index without trigger component.

      Selection processing is done in the following way:
      - select the new row index,
      - unselect the other rows, starting with the first to last row.

      This makes it possible to know if there are no selections remaining at an "unselection event".

      Parameters:
      index - The selected row index, or any negative value (e.g. -1) to clear the selection.
      Returns:
      true for success, false if the table is not of single or multiple selection type. In case of false return code, no selection or unselection is performed.
    • setSelection Link icon

      public boolean setSelection(int index, IGProp<?> trigger)
      Sets the single selection index with optional trigger component.

      Selection processing is done in the following way:
      - select the new row index,
      - unselect the other rows, starting with the first to last row.

      This makes it possible to know if there are no selections remaining at an "unselection event".

      Parameters:
      index - The selected row index, or any negative value (e.g. -1) to clear the selection.
      trigger - The trigger of the selection, null for none.
      Returns:
      true for success, false if the table is not of single or multiple selection type. In case of false return code, no selection or unselection is performed.
    • setSelection Link icon

      public boolean setSelection(int[] indicies)
      Sets the selection indicies without trigger component.

      Selection processing is done in the following way:
      - select the new row indicies,
      - unselect the other rows, starting with the first to last row.

      This makes it possible to know if there are no selections remaining at an "unselection event".

      Parameters:
      indicies - The selected row indicies.
      Returns:
      true for success, false if the table is not of single or multiple selection type. false is also returned if the length of the indicies is longer than one and the table is of single selection type (regardless if the same index is specified twice). In case of false return code, no selection or unselection is performed.
    • setSelection Link icon

      public boolean setSelection(int[] indicies, IGProp<?> trigger)
      Sets the selection indicies with optional trigger component.

      Selection processing is done in the following way:
      - select the new row indicies,
      - unselect the other rows, starting with the first to last row.

      This makes it possible to know if there are no selections remaining at an "unselection event".

      Parameters:
      indicies - The selected row indicies.
      trigger - The trigger of the selection, null for none.
      Returns:
      true for success, false if the table is not of single or multiple selection type. false is also returned if the length of the indicies is longer than one and the table is of single selection type (regardless if the same index is specified twice). In case of false return code, no selection or unselection is performed.
    • addListener Link icon

      public boolean addListener(IVSTableRowSelectionListener listener)
      Adds a new table row selection listener. Calling this method multiple times with the same listener will have no effect (but to return false).
      Parameters:
      listener - The listener to add.
      Returns:
      true if the listener was added, false otherwise.
      Throws:
      NullPointerException - If the listener is null.
    • removeListener Link icon

      public boolean removeListener(IVSTableRowSelectionListener listener)
      Removes a table row selection listener.
      Parameters:
      listener - The listener to remove.
      Returns:
      true if listener is successfully removed, false otherwise.
    • fireRowSelection Link icon

      public void fireRowSelection()
      Fires the current row selection to listeners if the table is of single or multiple selection. If no change of selection is present, nothing will be done.
    • refreshContentProviders Link icon

      public int refreshContentProviders()
      Refreshes all connected content providers. Use this method typically when a content provider that is connected to the VS table needs to be refreshed because it e.g. would produce a different result due to values or states outside of the VS table scope or that there are items not connected to VS fields or rows in the table.

      The method fires the onStateChanged(this,State.CONTENT_PROVIDER_REFRESH,false) event to all table listeners.

      Returns:
      The number of table listeners that have been notified.