<?xml version="1.0" encoding="UTF-8"?>
<process xmlns:blue="http://www.e-marson.com/bluelemon">

  <descriptor>
    <name>com/emarson/lemonade/examples/mobank/MainScreen</name>
    <version>1.0</version>
    <description>
      Shows the main screen with the options read from the 
      dataset kept in the "permanent" location in the node
      'com/emarson/lemonade/examples/mobank/MenuOptions', adding
      'Update...' at the bottom.
    </description>
    <vendor>E-MARSON</vendor>
  </descriptor>

  <path>

    <!-- ASSOCIATIONS --->

    <!-- association to exit from MIDlet --->
    <subprocess name="action for 'Exit'">
      <source>com/emarson/lemonade/templates/ExitFromApplication</source>
      <resultTo>actionForExit</resultTo>
    </subprocess>
    
    <!-- association to Update --->
    <subprocess name="action for 'Update'">
      <source>com/emarson/lemonade/examples/mobank/Update</source>
      <resultTo>actionForUpdate</resultTo>
    </subprocess>


    <!-- INSTRUCTION --->

    <action name="main menu">
      <type>general/bluelemon/code</type>
      <definition resultTo="mainMenu">

        <!-- from the permanent location try to get a dataset with menu options --->
        <blue:get node="com/emarson/lemonade/examples/mobank/MenuOptions"
                  location="permanent" toVariable="menuOptions"/>


        <!-- prepare the last row - 'Update...' --->
        <blue:call manager="UtilsManager" method="this" toVariable="lastRow">
          <blue:argument type="dataset">
            <blue:descriptor>
              <blue:field type="String"/>
              <blue:field type="byteArr"/>
            </blue:descriptor>
            <blue:row>
              <blue:field value="Update..."/>
              <blue:field contextKey="actionForUpdate"/>
            </blue:row>
          </blue:argument>
        </blue:call>

        <!-- append the last row to the end of the menu options --->
        <blue:call manager="UtilsManager" method="appendLast"
                   toVariable="menuOptions">

          <blue:argument type="variable" name="menuOptions"/>
          <blue:argument type="variable" name="lastRow"/>
        </blue:call>

        <!-- create the choice factory instance --->
        <blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/ChoiceFactory"
                          toVariable="choiceFactory"/>

                          
        <!-- create the list of type IMPLICIT --->
        <blue:call object="choiceFactory" method="createList"
                   toVariable="list">

          <blue:argument type="byte" value="List.IMPLICIT"/>
        </blue:call>

        <!-- initialize it --->
        <blue:call object="list" method="initialize">
          <blue:argument type="String" value="moBank"/>
          <blue:argument type="variable" name="menuOptions"/>
        </blue:call>

        <!-- add a command to exit from the application --->
        <blue:call manager="UtilsManager" method="getActionCommand"
                   toVariable="command">

          <blue:argument type="String" value="Exit"/>
          <blue:argument type="byte" value="ActionCommand.EXIT"/>
          <blue:argument type="byte" value="0"/>
          <blue:argument type="byteArr" contextKey="actionForExit"/>
        </blue:call>

        <blue:call object="list" method="addCommand">
          <blue:argument type="variable" name="command"/>
        </blue:call>

        <!-- and show the list --->
        <blue:call manager="GeneralManager" method="setCurrent">
          <blue:argument type="variable" name="list"/>
        </blue:call>

      </definition>
    </action>

    <!-- return the result --->
    <finish name="done">
      <return>mainMenu</return>
    </finish>

  </path>

</process>