SOURCECODE

How to... alter a Shop´s MenuSheet during runtime


Description:
Sometimes there are reasons to change a Shop´s MenuSheet during runtime. But in the class Shop a method setMenuSheet(MenuSheet ms) like the one class SalesPoint doesn´t exists. This makes it a little more complicate.
It is necessary to get the shop´s frame, which is actually a MultiWindow. The class MultiWindow provides the necessary
methode public void setMenuSheet(MenuSheet newMenuSheet).
Like this it is possible to change the MenuSheet, whenever wanted.

ToDo's:
  1. Get the shop´s frame, while casting it as a MultiWindow ( ex.: MultiWindow mw = (MultiWindow) Shop.getTheShop().getShopFrame() ).
  2. Create the new MenuSheet for the shop (See also: HowTo..define a MenuSheet)
  3. Set the new MenuSheet on the MultiWindow ( mw.setMenuSheet(MenuSheet newMenuSheet) ).


Uses:
MenuSheet  MenuSheetItem  MultiWindow  



SourceCode

// mainly imports
   import sale.multiwindow.MultiWindow;
   import sale.MenuSheet;
   import sale.MenuSheetItem;

// Main Class
   public class MyShop extends Shop
   {
   // Constructor
      public MyShop()
      {
         super();
      }

   // Main Method
      public static void main (String[] noArgs)
      {
      // the singleton instance of the shop
         MyShop myshop = new MyShop();

       1
      // getting the shop´s frame
         MultiWindow mw = (MultiWindow) myshop.getShopFrame();

       2
      // create new MenuSheet
         MenuSheet shopMS = myshop.createShopMenuSheet();

      // get first menubar
         MenuSheet menuBar = (MenuSheet) shopMS.getTaggedItem(SHOP_MENU_TAG, false);

      // create new MenuSheetItem
         MenuSheetItem msNewItem = new MenuSheetItem("Important", "Important_TAG",
                              new sale.Action()
                              {
                                 public void doAction (SaleProcess p, SalesPoint sp)
                                 {
                                    System.out.println("very important action!");
                                 }
                              });
      // add it to the MenuSheet
         menuBar.add(msNewItem);

       3
      // set changed MenuSheet
         mw.setMenuSheet(shopMS);
      }
   }