SOURCECODE

How to... define a UIGate


Description:
Gates are a part of SalesProcesses. In contrast to normal Gates, UIGates are made for user interaction and can display FormSheets and MenuSheets. If you need to display something, use UIGates. Use JOptionPanes or JDialogs only to display short user interaction and information, because after serialisation they wonīt be restored.
If you want to incorporate a UIGate not as StartGate, it may be mandatory to affect the view of the UIGate during Process. In this case, you have to use a Transition.
(See also: HowTo..incorporate a SaleProcess, HowTo..define a Gate, HowTo..define a Transition )

ToDo's:
  1. Select SaleProcess where you want to realize user interaction.
  2. Define global instance of the new UIGate.
  3. Define a FormSheetContentCreator to make FormSheetContent serializable.
    You may subclass FormSheetContentCreator, but in most cases, an anonymous class should be adequate.
  4. Incorporate a new FormSheet with the FormSheetContentCreator.
    (Eventually define a MenuSheet for the Gate, if necessary.)
  5. Initialize the UIGate with the FormSheet (and the MenuSheet).

(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:
Gate  UIGate  SaleProcess  Transition  GateChangeTransition  FormSheet  FormSheetContentCreator  SingleTableFormSheet  TwoTableFormSheet  MenuSheet  



SourceCode

// mainly imports
   import sale.Gate;
   import sale.UIGate;
   import sale.GateChangeTransition;
   import sale.FormSheet;
   import sale.FormSheetContentCreator;
   import data.stdforms.SingleTableFormSheet;
   import data.swing.JCatalogTable;
   import data.swing.DefaultCatalogItemTED;

   import javax.swing.JPanel;
   import javax.swing.JScrollPane;
   import javax.swing.JViewport;
   import java.awt.BorderLayout;

 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()
      {
      // the databasket of this process
         final DataBasket dataBasket = getBasket();

      // the catalog with the to be modified videos
         final Catalog videoCatalog = Shop.getTheShop().getCatalog("Video-Catalog");

       3
      // FormSheetContentCreators provide that JComponents in FormSheets are
      // serializable too and the Buttons keep their action after loading
         FormSheetContentCreator startGateFSSC =
            // the ContentCreator as anonymous class
            new FormSheetContentCreator()
            {
               // createFormSheetContent method is to be implemented
               protected void createFormSheetContent(FormSheet fs)
               {
               // new Table showing Video-Catalog
                  JCatalogTable jct = new JCatalogTable(videoCatalog,
                                    dataBasket,
                                       (java.util.Comparator) null,
                                    new DefaultCatalogItemTED());

               // ScrollPane viewing over the CatalogTable
                  JScrollPane startScrollPane = new JScrollPane(jct);

               // Container for the FormSheetContent with BorderLayout
                  JPanel startPanel = new JPanel(new BorderLayout());
                  startPanel.add(startScrollPane, BorderLayout.CENTER);

               // SingleTableFormSheet stfs = SingleTableFormSheet.create("", videoCatalog, null)
               // fs.setComponent(stfs.getComponent)
               // --> would have the same effect but offers more possibilities

               // set the JCatalogTable on the FormSheet
                  fs.setComponent(startScrollPane);

               // Cancel-Button is removed
                  fs.removeButton(FormSheet.BTNID_CANCEL);

               // Ok-Buttonīs Action is redefined
                  fs.getButton(FormSheet.BTNID_OK).
                     setAction(
                                 new sale.Action()
                                 {
                                    public void doAction (SaleProcess p, SalesPoint sp)
                                    {
                                       startGate.setNextTransition(toNextGateTransition);
                                    }
                                 }
                              );
               }
            };

       4
      // FormSheet of the UIGate is initialized with the FormSheetContentCreator
         FormSheet startGateFS = new FormSheet("Start Gate", startGateFSSC, false);

       5
      // UIGate is initialized with the defined FormSheet an with no MenuSheet(null)
         startGate = new UIGate(startGateFS, null);
      }
   }