Sonntag, 12. Mai 2019

confirmation button

new control variant for BBj - the confirmation button - the anatomy of the confirmation button is to click twice in order to trigger the final click event - The difference to a doubleclick behavior is the changing button text after the first click asking the user if he is really sure. - With the leave of the button control is the text gonna be resetted and the inner confirmation state is null again.
    This kind of button was the first time introduced by Ralf van den Heuvel in 2008. It was required in for the deletion of a single workshop planning appointment. The workshop planning was a html/javascript application and was asking again to be sure to delete the workshop appointment after clicking once on it.
     In the meantime - when googling for such button behavior - you will find also implementations for jquery/javascript by others.

Here comes the code implementation of the confirmation button in BBJ:

REM /**
REM  * BBjButtonExt.bbj
REM  * @author Ralf van den Heuvel
REM  * Click behavior extension
REM  */
class public BBjButtonExt

    field protected BBjButton parentCtrl!
    field protected CustomObject parentClassObject!
    field protected BBjString parentClassName!
    field private BBjString parentMethodNameOnButtonPush$
    field private BBjString parentButtonTextDefault$
    field private BBjString parentButtonTextCurrent$
    field private BBjString parentButtonTextConfirm$

    REM /**
    REM  * constructor of the extended BBjButton ctrl
    REM  * @param BBjButton control object to be extended
    REM  * @param BBjString of the full qualified parent class name like '::myClass.bbj::myClass'
    REM  * @param CustomObject of the parent class handled over like #this! 
    REM  * @param BBjString of the binded button push method within the parent class 
    REM  * @param BBjString of the interim button confirmation text. If the button is clicked once, the button text will swap to this confirmation text. If the button is clicked twice or the mouse leaves the button control, the text will be reset.
    REM  */
    method public BBjButtonExt(BBjButton parentCtrl!,BBjString parentClassName!,CustomObject parentClassObject!,BBjString parentMethodNameOnButtonPush$,BBjString confirmQuestion$)
        #parentClassName!=parentClassName!; REM like '::myClass.bbj::myClass'
        #parentClassObject!=parentClassObject!; REM mostly #this! in the parent class +++ java.lang.Class +++ ?#class!.getClass().getName() 
        if #parentButtonTextConfirm$>""
    REM /**
    REM  * button clicked - Analyse state - show confirmation question or trigger the button push method of the parent class
    REM  * @param BBjButtonPushEvent according to control.
    REM  */
    method public void OnButtonPush(BBjButtonPushEvent pe!)
        if #parentButtonTextCurrent$=#parentButtonTextConfirm$

    REM /**
    REM  * mouse exists control - analyze state - reset button text
    REM  * @param BBjButtonPushEvent according to control.
    REM  */
    method public void OnMouseExit(BBjMouseExitEvent pe!)
        if #parentButtonTextCurrent$=#parentButtonTextConfirm$
    REM /**
    REM  * control looses focus - analyze state - reset buttom text
    REM  * @param BBjButtonPushEvent according to control.
    REM  */
    method public void OnLostFocus(BBjLostFocusEvent pe!)
        if #parentButtonTextCurrent$=#parentButtonTextConfirm$


REM /**
REM  * demo - focus on #abtn!
REM  */
class public demo

    field protected BBjButtonExt abtn!
    field protected BBjButton btn!

    method public demo()
       sysgui = unt
       open (sysgui)"X0"
       sysgui! = bbjapi().getSysGui()
       window! = sysgui!.addWindow(25,25,200,275,"BBjButton",$00090003$)
       #btn! = cast(BBjButton,window!.addButton(2,25,75,150,25,"delete all foo - click me",$$))
       #abtn!=new BBjButtonExt(#btn!,"::BBjButtonExt.bbj::demo",#this!,"parentOnButtonPush","sure?"); REM btn ctrl, classname, this class, btn push event name, alternative confirmation text

    method public void parentOnButtonPush(BBjButtonPushEvent pe!)
        declare BBjButton ctrl!
ctrl!.setText("foo works")
void=msgbox("parent class push method",0,"",tim=2)

method public static void run()
declare demo d!
d!=new demo()


PREFIX cast(BBjString,pgm(-2)).replace("BBjButtonExt.bbj","") + " " + PFX

Mittwoch, 8. Mai 2019

xml node replacement variant (schematic)

schema - xmlsuit is decoration only - Document object required - REPLACEMENT variant

use org.w3c.dom.Document
use org.w3c.dom.NodeList
use org.w3c.dom.Node
use org.w3c.dom.NamedNodeMap
use org.w3c.dom.Element
declare auto Document d!
declare auto NodeList nl!
declare auto Node n!
declare auto Node c!
declare Element e!
declare xmlsuit xml!declare auto Node newHeaderNode!
markup$="<?xml version=""1.0"" encoding=""UTF-8""?><MESSAGE DTD=""XMLMSG"" VERSION=""1.0""><HEADER><FROM>.....</DATA></REQUEST></COMMAND></MESSAGE>"
xml!=new xmlsuit(markup$)d!=xml!.getDocument()
n!=xml!.getDocument().getFirstChild(); REM MESSAGE
c!=n!.getFirstChild(); REM HEADER
REM nl!.item(0).getParentNode().insertBefore(newHeaderNode!,nl!.item(0))nl!.item(0).getParentNode().insertBefore(e!,nl!.item(0))