Class BCBinder


  • public class BCBinder
    extends Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int SEL_DESELECT
      Direction directive to deselect all
      static int SEL_FIRST
      Direction directive to move selection to the first record
      static int SEL_LAST
      Direction directive to move selection to the last record
      static int SEL_NEXT
      Direction directive to move selection to the next record
      static int SEL_PREVIOUS
      Direction directive to move selection to the previous record
      static int SIGNAL_BLANK
      Signal directive that components should render themselves blank
      static int SIGNAL_DELETE
      Signal directive that delete should occur (on current selection)
      static int SIGNAL_DESTROY
      Signal directive that the program WILL terminate
      static int SIGNAL_DIRTY
      Signal directive that there is dirty (unsaved) data
      static int SIGNAL_ERROR
      Signal directive that an error has occured in the BC
      static int SIGNAL_INITIATE_TERMINATE
      Signal directive that the program wants to terminate
      static int SIGNAL_NEW
      Signal directive that a new record should be added
      static int SIGNAL_SAVE
      Signal directive that data should be saved
      static int SIGNAL_TERMINATE
      Signal directive that the program wants to terminate
    • Constructor Summary

      Constructors 
      Constructor Description
      BCBinder​(BusinessComponent bc)
      Sets the working business component and its attributes record
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Boolean canSetSelection()  
      protected void deleteSelectedRows()
      Called by handleSignal(int signal, Object payload) on SIGNAL_DELETE
      DataRow getAttributesRecord()  
      BusinessComponent getBC()  
      DataRow getDataRowForWrite()
      Called by write()
      int getDebugLevel()  
      ResultSet getRS()  
      List<String> getSelection()  
      protected void handleSignal​(int signal, Object payload)
      This BC binder will handle the different signals after all bound components have had their chance
      void onSetData()
      Invokes the onSetData() of all bound components
      void onSetSelection()
      Invokes the onSetSelection() of all bound components
      void register​(IBCBound component)
      Registers a component with this binder and sets the component's binder to this one
      void retrieve()
      Performs the retrieve of the bound BC, gets the corresponding attributes record that describes what's in the result set, creates indexes in the result set, checks keys in current selection list are in the result set, and invokes the onSetData() of all bound components so they can react.
      void sendSignal​(int signal)
      Send signal without a payload to all bound components
      void sendSignal​(int signal, Object payload)
      Send signal with a payload to all bound components
      void setDebugLevel​(int debugLevel)
      set the debug level of operations done by the BCBinder
      void setSelection​(int direction)
      Moves row pointer in result set based on the passed direction and extracts the row's key, which is then used to set the selection, after asking all bound components if it is ok.
      void setSelection​(String rowKey)
      Sets selection to the given row key, after asking all bound components if it is ok
      void setSelection​(ArrayList<String> sel)
      Sets one or more selections, after asking all bound components if it is ok
      protected void terminate()  
      protected void updateSelection()
      Checks if the items in the selection are still present in the result set and removes them from the selection if not.
      protected void write()
      Called by handleSignal(int signal, Object payload) on SIGNAL_SAVE Writes data from components to the bc.
    • Field Detail

      • SEL_FIRST

        public static final int SEL_FIRST
        Direction directive to move selection to the first record
        See Also:
        Constant Field Values
      • SEL_PREVIOUS

        public static final int SEL_PREVIOUS
        Direction directive to move selection to the previous record
        See Also:
        Constant Field Values
      • SEL_NEXT

        public static final int SEL_NEXT
        Direction directive to move selection to the next record
        See Also:
        Constant Field Values
      • SEL_LAST

        public static final int SEL_LAST
        Direction directive to move selection to the last record
        See Also:
        Constant Field Values
      • SEL_DESELECT

        public static final int SEL_DESELECT
        Direction directive to deselect all
        See Also:
        Constant Field Values
      • SIGNAL_SAVE

        public static final int SIGNAL_SAVE
        Signal directive that data should be saved
        See Also:
        Constant Field Values
      • SIGNAL_NEW

        public static final int SIGNAL_NEW
        Signal directive that a new record should be added
        See Also:
        Constant Field Values
      • SIGNAL_DELETE

        public static final int SIGNAL_DELETE
        Signal directive that delete should occur (on current selection)
        See Also:
        Constant Field Values
      • SIGNAL_BLANK

        public static final int SIGNAL_BLANK
        Signal directive that components should render themselves blank
        See Also:
        Constant Field Values
      • SIGNAL_DIRTY

        public static final int SIGNAL_DIRTY
        Signal directive that there is dirty (unsaved) data
        See Also:
        Constant Field Values
      • SIGNAL_ERROR

        public static final int SIGNAL_ERROR
        Signal directive that an error has occured in the BC
        See Also:
        Constant Field Values
      • SIGNAL_INITIATE_TERMINATE

        public static final int SIGNAL_INITIATE_TERMINATE
        Signal directive that the program wants to terminate
        See Also:
        Constant Field Values
      • SIGNAL_TERMINATE

        public static final int SIGNAL_TERMINATE
        Signal directive that the program wants to terminate
        See Also:
        Constant Field Values
      • SIGNAL_DESTROY

        public static final int SIGNAL_DESTROY
        Signal directive that the program WILL terminate
        See Also:
        Constant Field Values
    • Constructor Detail

      • BCBinder

        public BCBinder​(BusinessComponent bc)
        Sets the working business component and its attributes record
        Parameters:
        bc - Business Component
    • Method Detail

      • getDebugLevel

        public int getDebugLevel()
        Returns:
        the debug level which is currently set
      • setDebugLevel

        public void setDebugLevel​(int debugLevel)
        set the debug level of operations done by the BCBinder
        Parameters:
        debugLevel - : 0=no debug, 1=moderate debug
      • getRS

        public ResultSet getRS()
        Returns:
        working result set
      • getAttributesRecord

        public DataRow getAttributesRecord()
        Returns:
        DataRow containing all attributes
      • register

        public void register​(IBCBound component)
        Registers a component with this binder and sets the component's binder to this one
        Parameters:
        component -
      • retrieve

        public void retrieve()
                      throws Exception
        Performs the retrieve of the bound BC, gets the corresponding attributes record that describes what's in the result set, creates indexes in the result set, checks keys in current selection list are in the result set, and invokes the onSetData() of all bound components so they can react.
        Throws:
        Exception
      • updateSelection

        protected void updateSelection()
        Checks if the items in the selection are still present in the result set and removes them from the selection if not.
      • onSetData

        public void onSetData()
        Invokes the onSetData() of all bound components
      • onSetSelection

        public void onSetSelection()
        Invokes the onSetSelection() of all bound components
      • getSelection

        public List<String> getSelection()
        Returns:
        list of one or more selections
      • setSelection

        public void setSelection​(ArrayList<String> sel)
        Sets one or more selections, after asking all bound components if it is ok
        Parameters:
        sel - a list of row keys for setting one or more selections (any empty list means to deselect all)
      • setSelection

        public void setSelection​(String rowKey)
        Sets selection to the given row key, after asking all bound components if it is ok
        Parameters:
        rowKey - the row key for setting the selection
      • setSelection

        public void setSelection​(int direction)
        Moves row pointer in result set based on the passed direction and extracts the row's key, which is then used to set the selection, after asking all bound components if it is ok. If the direction is set to SEL_DESELECT, then an empty list is used to deselect all.
        Parameters:
        direction - of movement in result set
      • canSetSelection

        public Boolean canSetSelection()
        Returns:
        boolean whether the selection can be set
      • sendSignal

        public void sendSignal​(int signal)
        Send signal without a payload to all bound components
        Parameters:
        signal -
      • sendSignal

        public void sendSignal​(int signal,
                               Object payload)
        Send signal with a payload to all bound components
        Parameters:
        signal -
        payload -
      • handleSignal

        protected void handleSignal​(int signal,
                                    Object payload)
        This BC binder will handle the different signals after all bound components have had their chance
        Parameters:
        signal -
        payload -
        Throws:
        Exception
      • terminate

        protected void terminate()
      • getDataRowForWrite

        public DataRow getDataRowForWrite()
                                   throws Exception
        Called by write()
        Returns:
        DataRow
        Throws:
        Exception
      • write

        protected void write()
                      throws Exception
        Called by handleSignal(int signal, Object payload) on SIGNAL_SAVE Writes data from components to the bc. components provide data with the getDataRowForWrite() method. after that, the new datarow is being integrated into the result set of the binder, either via addition or replacement.
        Throws:
        Exception
      • deleteSelectedRows

        protected void deleteSelectedRows()
                                   throws Exception
        Called by handleSignal(int signal, Object payload) on SIGNAL_DELETE
        Throws:
        Exception - on validation failure or unexpected Exception