IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

dialog to let user reorder a listI'm using DominoBlog to author this blog. Naturally, like any piece of software I use, I've developed a wish list of things I'd like to change about it. This is why the email volume of Steve Castledine, the author and maintainer of the template, has approximately doubled recently.

One of my suggestions was to do make reordering links easier. Right now there's an Order field on a the link form where you can put in a number, but knowing what number to put in requires knowing what all the other link documents have in there, and if you didn't leave space between the numbers, inserting one in the middle is a pain. I'm sure this is a common issue in applications where you have a list whose order the user can control.

So, I created an agent in my own copy of the blog database that displays a dialog that lets the user reorder a list. Then the agent takes the reordered list and uses that to assign numbers to fields in a corresponding set of documents to make them sort in the specified order. It then occurred to me that this would make a nice example of object-oriented design. Of course, most of the logic is in the dialog form; it just takes a few lines of code to launch the dialog and pull the results out after the user closes it. So this application doesn't demand the use of a class; I could've done it with a subroutine that takes arguments of the window title, prompt text, and list of choices, similar to many built-in functions in Notes. But when you're doing examples, it's best to choose a simple task.

I've divided the example into two parts:

  • Letting the user reorder a list.
  • Creating the list from a sorted view of documents and updating the documents with the new sequence numbers.
Today, I'm just going to address the first part. Where you can split things out like this, it usually makes sense to do so. The functionality of letting a user reorder a list is useful in other contexts than sorting documents, so I can make something that might be reusable in other situations.

To start with, here's the dialog form and a LotusScript class that controls it (see attachment below). The form attachment is DXL; look at earlier blog entries for code to import DXL design elements into your application.

Option Public
Option Declare  
' always use Option Declare
Class ListReorderDialog
     Public choices As Variant
     Public defaultSelected As Variant
     Public windowTitle As String
     Public promptText As String
     
     Sub New(choices)
             Me.choices = choices
             defaultSelected = ""
             windowTitle = "Use WindowTitle property to assign this text"
             promptText = "Use the promptText property to assign this text."
     End Sub
     
     Function Ask( ) As Boolean
             Dim wksp As New NotesUIWorkspace
             Dim session As New NotesSession
             Dim db As NotesDatabase
             Set db = session.CurrentDatabase
             Dim docDialog As NotesDocument
             Set docDialog = db.CreateDocument
             docDialog.ReplaceItemValue "SortedList", choices
             docDialog.ReplaceItemValue "Prompt", promptText
             docDialog.ReplaceItemValue "Selection", defaultSelected
             Ask = wksp.DialogBox("DialogReorderList", True, True, False, False, False, False, windowTitle, docDialog, True, False, True)
             If Ask Then choices  docDialog.GetItemValue("SortedList")
     End Function
End Class

To use the class, you would Dim a new ListReorderDialog object, assign its choices, windowTitle and promptText properties, and call the Ask method. The defaultSelected property lets you highlight a particular element of the list. You would do this for a new element that you think the user will want to position relative to the other, previously existing elements -- it doesn't prevent them from selecting and reordering other elements if they like, just saves them the trouble of spotting the new thing in the list and selecting it.

Sub Initialize
     Dim LD As New ListReorderDialog("")
     LD.choices = Split("nine,just,sat,mother,my,very,porcupines,elegant,upon", ",")

      LD.promptText = "Please use the buttons to reorder the list into your desired sequence."
     LD.windowtitle = "Dialog test"
     LD.defaultSelected = LD.choices(0)
' optional: select the first entry by default, just to show how it's done.
     If LD.Ask( ) Then
             Msgbox "New order: " & Join(LD.choices, {, })
     End If
End Sub

NOTE: Added zipped .nsf as an alternative for people not able to import the DXL file because of wrong version. I hope you are seeing the new zip attachment below.

Attachments: DialogReorderList.dxl
reorder dialog.zip

Andre Guirard | 9 April 2007 08:38:23 AM ET | Plymouth, MN, US | Comments (3)


 Comments

1) Reordering items in a list
Charles Robinson | 4/9/2007 3:39:16 PM

Good stuff. I did something similar a while back using nothing but formula. It would be really nice if Notes had some UI widgets that allowed drag and drop reordering. :-) Maybe that will be possible in Notes 8 with the Expeditor framework.

By the way, you have one small typo:

If Ask Then choices docDialog.GetItemValue("SortedList")

... should be...

If Ask Then choices = docDialog.GetItemValue("SortedList")

2) re: typo
Andre Guirard | 4/10/2007 8:58:08 AM

Curious. In Notes I can see the =. I'm going to have to speak with Mr. Castledine about this.

3) Attachment links are broken
erhard weitner | 4/9/2010 7:35:01 AM

The attachment links are broken.

4) Reordering items in a list
Andre Guirard | 4/21/2010 1:26:38 PM

@erhard, see my latest post for an alternate download location. It seems to have vanished from here.

 Add a Comment
Subject:
   
Name:
Comment:  (No HTML - Links will be converted if prefixed http://)
 
Remember Me?     Cancel

Search this blog 

Disclaimer 

    About IBM Privacy Contact