Class VSTable

    • Field Detail

      • EMPTY_LISTENERS

        public static final IVSTableListener[] EMPTY_LISTENERS
        Empty list of listeners.
      • header

        protected VSRow header
        The header property.
      • rows

        protected VSRows rows
        The rows property.
    • Constructor Detail

      • VSTable

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

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

      • getPredefinedProps

        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

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

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

        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

        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

        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

        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

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

        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

        protected VSRows createRows()
        Creates the rows property container.
      • getRowCount

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

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

        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

        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

        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

        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

        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

        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

        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

        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

        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

        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

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

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

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

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

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

        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

        public VSColumnHeader getColumnHeader​(java.lang.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

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

        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

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

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

        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

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

        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

        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

        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

        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

        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

        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

        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

        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

        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:
        java.lang.NullPointerException - If the listener is null.
      • removeListener

        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

        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

        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.