SOURCECODE

How to... run a Process in the shopframe


Description:
In SalesPoint Framework 3.0 new SalesPoints open their own DisplayFrame in which the sale action takes place. Additionally a new StatusDisplay named as the SalesPoint is added to the JTabbedPane in the Shop´s frame. It is possible to let the SalesPoint´s actions taking place in this StatusDisplay although it is not provided by the designers.
(See also: HowTo..incorporate a SaleProcess and HowTo..incorporate a Shop )
In the following we will learn to modify the VideoMachine application in order to make the SalesPoints and there Processes usable in the StatusDisplays.

ToDo's:
  1. Implement public FormSheet getDefaultStatusFormSheet() and if necessarypublic MenuSheet getDefaultStatusMenuSheet() method in order to initialize your SalesPoint´s StatusDisplay.
  2. Alter the button actions of the FormSheet in order to start the Processes at the Shop and on the SalesPoint´s StatusDisplay.
  3. Implement public MultiWindowHandle getSelectedDisplay() method in your shopclass because the Shop´s method getShopFrame() has protected access.
  4. Implement protected void onFinished() method in your Processes in order to refresh DefaultStatusDisplay after Process has finished.

(The following steps are very close to VideoMachine application and not always neccessary:
  1. Alter StockChangeAdapter and TimerListener to force refeshing StatusDisplay after rent, giveback or advance time.
  2. Implement public MultiWindow getShopMultiWindow() to enable access to the Shop´s frame.
  3. Alter sale.action which performs displaying logfile (not documented).
)

Uses:
Shop  SaleProcess  MultiWindowHandle  MultiWindow  

Example:
video.zip


SourceCode


public class Counter extends SalesPoint
{

...

   1

  // method is to be implemented
  public FormSheet getDefaultStatusFormSheet()
  {
    return new FormSheet("Menu", new DefaultCounterFormCreator(), false);
  }
}



public class DefaultCounterFormCreator extends FormSheetContentCreator
{
...

  public void createFormSheetContent(FormSheet map)
  {
  ...

   2

  // action is to be altered
  map.addButton ("rent", 1,
      new sale.Action()
        {
          public void doAction(SaleProcess p, SalesPoint s)
          {
            // getting StatusDisplay of the SalesPoint in the Shop´s frame
            Display display = ((VideoMachine)Shop.getTheShop()).getSelectedDisplay();
            // starting Process at the Shop on the SalesPoint´s StatusDisplay
            Shop.getTheShop().runProcess(new RentProcess(), display, null, new DataBasketImpl());
          }
        }
    );

    ...
}



// imports to add
import sale.multiwindow.MultiWindowHandle;
import sale.multiwindow.MultiWindow;

public class VideoMachine extends Shop
{

 ...

   3

  // method is to be implemented
  public MultiWindowHandle getSelectedDisplay()
  {
    return (MultiWindowHandle) ((MultiWindow)
             ((VideoMachine)Shop.getTheShop()).getShopFrame()).getSelectedDisplay();
  }

   6

  // method may have to be implemented
  public MultiWindow getShopMultiWindow()
  {
    return (MultiWindow) getShopFrame();
  }
}



public class RentProcess extends SaleProcess
{

 ...

   4

  protected void onFinished()
  {
    // get active display which is to be refreshed after Process had finished
    Display display = ((VideoMachine)Shop.getTheShop()).getSelectedDisplay();

    try
    {
      // setting the DefaultFormSheet
      display.setFormSheet( new FormSheet("Menu", new DefaultCounterFormCreator(), false) );
    }
    catch (java.lang.InterruptedException ie)
    { System.err.println("Unable to set FormSheet"); }
  }
}



public class Office extends SalesPoint
{

 ...

  public Office(String name)
  {
    super(name);

    // neuen StockChangeListener am Geldbestand des Automaten anmelden
    ((MoneyBagImpl)Shop.getTheShop().getStock("coin slot")).
      addStockChangeListener(

         5

        new StockChangeAdapter()
        {
          public void commitAddStockItems (StockChangeEvent sce)
          {
            refreshOfficeDisplay();
           }

          public void commitRemoveStockItems (StockChangeEvent sce)
          {
             refreshOfficeDisplay();
          }
        }
      );

    // neuen TimerListener am Timer des Automaten anmelden
    Shop.getTheShop().getTimer().addTimerListener(
      new TimerAdapter()
      {
        public void onGoneAhead (TimerEvent trEvt)
        {
           refreshOfficeDisplay();
        }
      }
    );
  }

  protected void refreshOfficeDisplay()
  {
    MultiWindowHandle mwh = null;
    Display display = null;

    for( java.util.Iterator it = ((VideoMachine)Shop.getTheShop()).getShopMultiWindow().iterator();
           it.hasNext() ; )
     {
       mwh = (MultiWindowHandle) it.next();
       if ( mwh.getDisplayCaption().equals("Office") )
         display = mwh;
     }
     Office office = new Office("");

     try
    {
      // setting the DefaultFormSheet and MenuSheet
      display.setFormSheet( office.getDefaultStatusFormSheet() );
      display.setMenuSheet( office.getDefaultStatusMenuSheet() );
    }
    catch (java.lang.InterruptedException ie)
    { System.err.println("Unable to set FormSheet"); }
  }