user list order form

Discussion in 'Cadence' started by anandganesan, Dec 17, 2004.

  1. anandganesan

    anandganesan Guest

    hi
    i have a list and i want to display it on a form and let the user
    rearrange it in his suitable manner. finally the form needs to be
    closed with the reordered list. does anyone already have a code for
    this or can you suggest the simplest way of doing this?

    thanks.

    anand.
     
    anandganesan, Dec 17, 2004
    #1
  2. anandganesan

    S. Badel Guest

    here is a bit of code. it supposes your list is a list of integers. it's
    important because it uses a report field. could however be tweaked
    easily for other data type or even for list of lists.
    usage: OLReorderList( mylist ) => reordered_list

    OLListField = hiCreateReportField(
    ?name 'list
    ?title "List"
    ?titleAlignment 'left
    ?headers '( ("Item" 300 left int nil ) )
    ?choices nil
    )

    OLUpButton = hiCreateButton(
    ?name 'upBtn
    ?buttonText "Up"
    ?callback "OLUpCB(hiGetCurrentForm())"
    )

    OLDownButton = hiCreateButton(
    ?name 'downBtn
    ?buttonText "Down"
    ?callback "OLDownCB(hiGetCurrentForm())"
    )

    OLForm = hiCreateAppForm(
    ?name 'adeTxtOutSetupForm
    ?formTitle "Order List"
    ?buttonLayout '(OKCancel)
    ?buttonDisabled '( Help )
    ?dialogStyle 'modal
    ?fields list(
    list( OLListField 10:10 400:200 100 )
    list( OLUpButton 450:66 50:30 )
    list( OLDownButton 450:122 50:30 )
    )
    ?initialSize 520:250
    ?minSize 520:250
    ?maxSize 520:250
    ) ; hiCreateAppForm

    ; procedure to swap two adjacent items in a list
    procedure( OLSwapItems(l a b)
    let( ( (x min(a b)) (y max(a b)) )
    if( x==1 then
    cons( cadr(l) cons( car(l) cddr(l) ) )
    else
    cons( car(l) swapItems(cdr(l) x-1 y-1) )
    ) ; if
    ) ; let
    ) ; procedure

    procedure( OLUpCB(form)
    ; process each item from the selection
    let( (selection)
    selection = form~>list~>value
    foreach( item form~>list~>value
    ; exchange the item and it's predecessor
    when( item
    form~>list~>choices = OLSwapItems(form~>list~>choices item item+1)
    )
    ) ; foreach
    form~>list~>value=mapcar(lambda( (x) x=x-1 ) selection )
    ) ; let
    ) ; procedure

    procedure( OLDownCB(form)
    ; process each item from the selection
    let( (selection)
    selection = form~>list~>value
    foreach( item reverse(selection)
    ; exchange the item and it's predecessor
    when( item+1!=length(form~>list~>choices)
    form~>list~>choices = OLSwapItems(form~>list~>choices item+1 item+2)
    )
    ) ; foreach
    form~>list~>value=mapcar(lambda( (x) x=x+1 ) selection )
    ) ; let
    ) ; procedure

    procedure( OLReorderList( l )
    OLForm~>list~>choices = mapcar( 'list l )
    if( hiDisplayForm(OLForm) mapcar( 'car OLForm~>list~>choices ) l )
    ) ; procedure
     
    S. Badel, Dec 17, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.