protected void setContext(
      FormLoader loader,
      Form form,
      ims.framework.interfaces.IAppForm appForm,
      UIFactory factory,
      ims.framework.Context context,
      Boolean skipContextValidation,
      Integer startControlID,
      ims.framework.utils.SizeInfo runtimeSize,
      ims.framework.Control control,
      Integer startTabIndex)
      throws Exception {
    if (loader == null) ; // this is to avoid eclipse warning only.
    if (factory == null) ; // this is to avoid eclipse warning only.
    if (runtimeSize == null) ; // this is to avoid eclipse warning only.
    if (appForm == null) throw new RuntimeException("Invalid application form");
    if (startControlID == null) throw new RuntimeException("Invalid startControlID");
    if (control == null) ; // this is to avoid eclipse warning only.
    if (startTabIndex == null) throw new RuntimeException("Invalid startTabIndex");
    this.context = context;
    this.componentIdentifier = startControlID.toString();
    this.formInfo = form.getFormInfo();
    this.globalContext = new GlobalContext(context);

    if (skipContextValidation == null || !skipContextValidation.booleanValue()) {
      validateContext(context);
      validateMandatoryContext(context);
    }

    super.setContext(form);

    ims.framework.utils.SizeInfo designSize = new ims.framework.utils.SizeInfo(800, 512);
    if (runtimeSize == null) runtimeSize = designSize;
    form.setWidth(runtimeSize.getWidth());
    form.setHeight(runtimeSize.getHeight());
    super.setFormReferences(FormReferencesFlyweightFactory.getInstance().create(Forms.class));
    super.setImageReferences(ImageReferencesFlyweightFactory.getInstance().create(Images.class));
    super.setGlobalContext(
        ContextBridgeFlyweightFactory.getInstance()
            .create(GlobalContextBridge.class, context, false));
    super.setLocalContext(new LocalContext(context, form.getFormInfo(), componentIdentifier));

    // Context Menus
    contextMenus = new ContextMenus();
    contextMenus.RefMan.contextMenuPrescription = factory.createMenu(startControlID.intValue() + 1);
    contextMenus.RefMan.contextMenuPrescriptionNewPrescriptionRecordItem =
        factory.createMenuItem(
            startControlID.intValue() + 1,
            "New Prescription record ",
            true,
            false,
            new Integer(102149),
            true,
            false);
    contextMenus.RefMan.contextMenuPrescription.add(
        contextMenus.RefMan.contextMenuPrescriptionNewPrescriptionRecordItem);
    contextMenus.RefMan.contextMenuPrescriptionAddPrescriptionDrugItem =
        factory.createMenuItem(
            startControlID.intValue() + 2,
            "Add prescription drug ",
            true,
            false,
            new Integer(102179),
            true,
            false);
    contextMenus.RefMan.contextMenuPrescription.add(
        contextMenus.RefMan.contextMenuPrescriptionAddPrescriptionDrugItem);
    contextMenus.RefMan.contextMenuPrescriptionEDIT_PRESCRIPTION_DRUGItem =
        factory.createMenuItem(
            startControlID.intValue() + 3,
            "Edit prescription drug",
            true,
            false,
            new Integer(102150),
            true,
            false);
    if (factory
        .getUIEngine()
        .getLoggedInRole()
        .hasMenuActionRight(appForm, new ims.framework.MenuAction(3250003)))
      contextMenus.RefMan.contextMenuPrescription.add(
          contextMenus.RefMan.contextMenuPrescriptionEDIT_PRESCRIPTION_DRUGItem);
    contextMenus.RefMan.contextMenuPrescriptionRemovePrescriptionDrugItem =
        factory.createMenuItem(
            startControlID.intValue() + 4,
            "Remove prescription drug",
            true,
            false,
            new Integer(102300),
            true,
            false);
    if (factory
        .getUIEngine()
        .getLoggedInRole()
        .hasMenuActionRight(appForm, new ims.framework.MenuAction(3250001)))
      contextMenus.RefMan.contextMenuPrescription.add(
          contextMenus.RefMan.contextMenuPrescriptionRemovePrescriptionDrugItem);
    contextMenus.RefMan.contextMenuPrescriptionRIE_PRESCRIPTION_DRUGItem =
        factory.createMenuItem(
            startControlID.intValue() + 5,
            "RIE prescription drug",
            true,
            false,
            new Integer(102142),
            true,
            false);
    if (factory
        .getUIEngine()
        .getLoggedInRole()
        .hasMenuActionRight(appForm, new ims.framework.MenuAction(3250004)))
      contextMenus.RefMan.contextMenuPrescription.add(
          contextMenus.RefMan.contextMenuPrescriptionRIE_PRESCRIPTION_DRUGItem);
    contextMenus.RefMan.contextMenuPrescriptionRIEItem =
        factory.createMenuItem(
            startControlID.intValue() + 6, "RIE", true, false, new Integer(102142), true, false);
    if (factory
        .getUIEngine()
        .getLoggedInRole()
        .hasMenuActionRight(appForm, new ims.framework.MenuAction(3250002)))
      contextMenus.RefMan.contextMenuPrescription.add(
          contextMenus.RefMan.contextMenuPrescriptionRIEItem);
    form.registerMenu(contextMenus.RefMan.contextMenuPrescription);

    // Button Controls
    RuntimeAnchoring anchoringHelper1 =
        new RuntimeAnchoring(
            designSize,
            runtimeSize,
            640,
            488,
            75,
            23,
            ims.framework.enumerations.ControlAnchoring.TOPRIGHT);
    super.addControl(
        factory.getControl(
            Button.class,
            new Object[] {
              control,
              new Integer(startControlID.intValue() + 1000),
              new Integer(anchoringHelper1.getX()),
              new Integer(anchoringHelper1.getY()),
              new Integer(anchoringHelper1.getWidth()),
              new Integer(anchoringHelper1.getHeight()),
              new Integer(-1),
              ControlState.HIDDEN,
              ControlState.ENABLED,
              ims.framework.enumerations.ControlAnchoring.TOPRIGHT,
              "Save",
              Boolean.FALSE,
              null,
              Boolean.FALSE,
              Boolean.TRUE,
              Boolean.FALSE,
              null,
              ims.framework.utils.Color.Default,
              ims.framework.utils.Color.Default
            }));
    RuntimeAnchoring anchoringHelper2 =
        new RuntimeAnchoring(
            designSize,
            runtimeSize,
            717,
            488,
            75,
            23,
            ims.framework.enumerations.ControlAnchoring.TOPRIGHT);
    super.addControl(
        factory.getControl(
            Button.class,
            new Object[] {
              control,
              new Integer(startControlID.intValue() + 1001),
              new Integer(anchoringHelper2.getX()),
              new Integer(anchoringHelper2.getY()),
              new Integer(anchoringHelper2.getWidth()),
              new Integer(anchoringHelper2.getHeight()),
              new Integer(-1),
              ControlState.HIDDEN,
              ControlState.ENABLED,
              ims.framework.enumerations.ControlAnchoring.TOPRIGHT,
              "Cancel",
              Boolean.FALSE,
              null,
              Boolean.FALSE,
              Boolean.TRUE,
              Boolean.FALSE,
              null,
              ims.framework.utils.Color.Default,
              ims.framework.utils.Color.Default
            }));

    // Dynamic Grid Controls
    RuntimeAnchoring anchoringHelper3 =
        new RuntimeAnchoring(
            designSize,
            runtimeSize,
            8,
            8,
            784,
            472,
            ims.framework.enumerations.ControlAnchoring.TOPLEFTRIGHT);
    super.addControl(
        factory.getControl(
            DynamicGrid.class,
            new Object[] {
              control,
              new Integer(startControlID.intValue() + 1002),
              new Integer(anchoringHelper3.getX()),
              new Integer(anchoringHelper3.getY()),
              new Integer(anchoringHelper3.getWidth()),
              new Integer(anchoringHelper3.getHeight()),
              new Integer(-1),
              ControlState.READONLY,
              ControlState.EDITABLE,
              ims.framework.enumerations.ControlAnchoring.TOPLEFTRIGHT,
              contextMenus.RefMan.contextMenuPrescription,
              Boolean.FALSE,
              Boolean.FALSE,
              Boolean.TRUE
            }));
  }
  protected void setContext(
      FormLoader loader,
      Form form,
      ims.framework.interfaces.IAppForm appForm,
      UIFactory factory,
      ims.framework.Context context,
      Boolean skipContextValidation,
      Integer startControlID,
      ims.framework.utils.SizeInfo runtimeSize,
      ims.framework.Control control,
      Integer startTabIndex)
      throws Exception {
    if (loader == null) ; // this is to avoid eclipse warning only.
    if (factory == null) ; // this is to avoid eclipse warning only.
    if (runtimeSize == null) ; // this is to avoid eclipse warning only.
    if (appForm == null) throw new RuntimeException("Invalid application form");
    if (startControlID == null) throw new RuntimeException("Invalid startControlID");
    if (control == null) ; // this is to avoid eclipse warning only.
    if (startTabIndex == null) throw new RuntimeException("Invalid startTabIndex");
    this.context = context;
    this.componentIdentifier = startControlID.toString();
    this.formInfo = form.getFormInfo();
    this.globalContext = new GlobalContext(context);

    if (skipContextValidation == null || !skipContextValidation.booleanValue()) {
      validateContext(context);
    }

    super.setContext(form);

    ims.framework.utils.SizeInfo designSize = new ims.framework.utils.SizeInfo(864, 576);
    if (runtimeSize == null) runtimeSize = designSize;
    form.setWidth(runtimeSize.getWidth());
    form.setHeight(runtimeSize.getHeight());
    super.setFormReferences(FormReferencesFlyweightFactory.getInstance().create(Forms.class));
    super.setImageReferences(ImageReferencesFlyweightFactory.getInstance().create(Images.class));
    super.setGlobalContext(
        ContextBridgeFlyweightFactory.getInstance()
            .create(GlobalContextBridge.class, context, false));
    super.setLocalContext(new LocalContext(context, form.getFormInfo(), componentIdentifier));

    // Context Menus
    contextMenus = new ContextMenus();
    contextMenus.contextMenuMosLocation = factory.createMenu(startControlID.intValue() + 1);
    contextMenus.contextMenuMosLocationSetPrimaryLocationItem =
        factory.createMenuItem(
            startControlID.intValue() + 1,
            "Set as primary location",
            true,
            false,
            new Integer(103104),
            true,
            false);
    contextMenus.contextMenuMosLocation.add(
        contextMenus.contextMenuMosLocationSetPrimaryLocationItem);
    form.registerMenu(contextMenus.contextMenuMosLocation);

    // Panel Controls
    RuntimeAnchoring anchoringHelper1 =
        new RuntimeAnchoring(
            designSize,
            runtimeSize,
            8,
            8,
            848,
            24,
            ims.framework.enumerations.ControlAnchoring.TOPLEFTRIGHT);
    super.addControl(
        factory.getControl(
            Panel.class,
            new Object[] {
              control,
              new Integer(startControlID.intValue() + 1000),
              new Integer(anchoringHelper1.getX()),
              new Integer(anchoringHelper1.getY()),
              new Integer(anchoringHelper1.getWidth()),
              new Integer(anchoringHelper1.getHeight()),
              ControlState.UNKNOWN,
              ControlState.UNKNOWN,
              ims.framework.enumerations.ControlAnchoring.TOPLEFTRIGHT,
              "Set Organisations/locations",
              new Integer(1),
              ""
            }));

    // Button Controls
    RuntimeAnchoring anchoringHelper2 =
        new RuntimeAnchoring(
            designSize,
            runtimeSize,
            696,
            536,
            75,
            23,
            ims.framework.enumerations.ControlAnchoring.BOTTOMRIGHT);
    super.addControl(
        factory.getControl(
            Button.class,
            new Object[] {
              control,
              new Integer(startControlID.intValue() + 1001),
              new Integer(anchoringHelper2.getX()),
              new Integer(anchoringHelper2.getY()),
              new Integer(anchoringHelper2.getWidth()),
              new Integer(anchoringHelper2.getHeight()),
              new Integer(startTabIndex.intValue() + 2),
              ControlState.HIDDEN,
              ControlState.ENABLED,
              ims.framework.enumerations.ControlAnchoring.BOTTOMRIGHT,
              "Save",
              Boolean.FALSE,
              null,
              Boolean.FALSE,
              Boolean.TRUE,
              Boolean.FALSE,
              null,
              ims.framework.utils.Color.Default,
              ims.framework.utils.Color.Default
            }));
    RuntimeAnchoring anchoringHelper3 =
        new RuntimeAnchoring(
            designSize,
            runtimeSize,
            773,
            536,
            75,
            23,
            ims.framework.enumerations.ControlAnchoring.BOTTOMRIGHT);
    super.addControl(
        factory.getControl(
            Button.class,
            new Object[] {
              control,
              new Integer(startControlID.intValue() + 1002),
              new Integer(anchoringHelper3.getX()),
              new Integer(anchoringHelper3.getY()),
              new Integer(anchoringHelper3.getWidth()),
              new Integer(anchoringHelper3.getHeight()),
              new Integer(startTabIndex.intValue() + 3),
              ControlState.HIDDEN,
              ControlState.ENABLED,
              ims.framework.enumerations.ControlAnchoring.BOTTOMRIGHT,
              "Cancel",
              Boolean.FALSE,
              null,
              Boolean.FALSE,
              Boolean.TRUE,
              Boolean.FALSE,
              null,
              ims.framework.utils.Color.Default,
              ims.framework.utils.Color.Default
            }));

    // Dynamic Grid Controls
    RuntimeAnchoring anchoringHelper4 =
        new RuntimeAnchoring(
            designSize,
            runtimeSize,
            8,
            40,
            840,
            472,
            ims.framework.enumerations.ControlAnchoring.TOPLEFTRIGHT);
    super.addControl(
        factory.getControl(
            DynamicGrid.class,
            new Object[] {
              control,
              new Integer(startControlID.intValue() + 1003),
              new Integer(anchoringHelper4.getX()),
              new Integer(anchoringHelper4.getY()),
              new Integer(anchoringHelper4.getWidth()),
              new Integer(anchoringHelper4.getHeight()),
              new Integer(startTabIndex.intValue() + 1),
              ControlState.READONLY,
              ControlState.EDITABLE,
              ims.framework.enumerations.ControlAnchoring.TOPLEFTRIGHT,
              contextMenus.contextMenuMosLocation,
              Boolean.FALSE,
              Boolean.FALSE,
              Boolean.TRUE
            }));
  }