SOURCECODE

How to... define a Transition


Description:
Transitions main task is to prepare Gates while application is running. The idea is to manipulate the view of a Gate in order to react to user interaction or collected data of the past. It is possible to prepare normal Gates and UIGates as well.
(See also: HowTo..incorporate a SaleProcess, HowTo..define a Gate, HowTo..define a UIGate )

ToDo's:
  1. Select SaleProcess where you want to realize a Transition.
  2. Define global instance of the new UIGate and the Transition leading to it.
    (One Gate may have more than one Transition leading to it.)
  3. Instanciate the Transition, therefore implement public Gate perform(SaleProcess pOwner, User usr) method.
    (It is also possible to subclass Transition and use the constuctor instead of an anonymous class, but unnecessary in most cases.)
  4. Initialize new UIGate.
  5. Initialize your FormSheet, you want to be displayed.
  6. Use a FormSheetContentCreator to make buttons and swing components serializable.
  7. Return the single instance of the Gate, you want to prepare with this Transition.

(In practical use, often you have to permute the statements to reach your goals. It depends on what FormSheet you want to realize and how it has to be manipulated.)

Uses:
Transition  GateChangeTransition  SaleProcess  Gate  UIGate  FormSheet  FormSheetContentCreator  SingleTableFormSheet  TwoTableFormSheet  MenuSheet  



SourceCode

// mainly imports
   import sale.Gate;
   import sale.Transition;
   import sale.UIGate;
   import sale.GateChangeTransition;
   import sale.FormSheet;
   import sale.FormSheetContentCreator;
   import data.stdforms.TwoTableFormSheet;

   import sale.SaleProcess;
   import users.User;

 1
// Main Class
   public class RentProcess extends SaleProcess
   {

    2
   // global instance of the StartGate
      protected UIGate startGate;

   // global instance of the Transition to the "next" Gate
      protected Transition toNextGateTransition;
   // and the Gate
      protected UIGate nextGate;

   // Main Method
      protected void setupMachine()
      {

       3
      // The transition to prepare the Gate "nextGate"
         toNextGateTransition =
               // the Transition as anonymous class
               new Transition()
               {
                  // perform method is to be implemented
                  public Gate perform(SaleProcess pOwner, User usr)
                  {
                   4
                  // the Gate is initialized, the FormSheet follows
                     nextGate = new UIGate(null,null);

                   5
                  // FormSheet to display at the Gate
                  // The TTFS is initialized with the UIGate "NextGate", so it has not to be set later
                     TwoTableFormSheet ttfs =
                     TwoTableFormSheet.create("Next Gate", // Caption
                                       videoCatalog, // Catalog
                                       dataBasket, // Databasket
                                       nextGate); // UIGate

                   6
                  // redefine the TTFS´ buttons within a FormSheetContentCreator
                     ttfs.
                        addContentCreator(
                                            new FormSheetContentCreator()
                                            {
                                               protected void createFormSheetContent(FormSheet fs)
                                               {
                                               // remove Cancel-Button
                                                  fs.removeButton(FormSheet.BTNID_CANCEL);

                                                // redefine action of OK-Button
                                                  fs.getButton(FormSheet.BTNID_OK).
                                                     setAction(
                                                                 new sale.Action()
                                                                 {
                                                                    public void doAction (SaleProcess p, SalesPoint sp)
                                                                    {
                                                                       startGate.
                                                                          setNextTransition(
                                                                                           new GateChangeTransition
                                                                                              (startGate)
                                                                                           );
                                                                    }
                                                                 }
                                                              );
                                               }
                                            }
                                         );

                   7
                  // the prepared Gate
                     return nextGate;
                  }
               };
      }
   }