4 Replies Latest reply: Feb 14, 2013 8:46 AM by edward17 RSS

    Looking for design help

      Looking for some design help with this scenario

      A user can double click on a non-editable listview and a dialog will pop up. the enter some data and the list view is populated. when they exit the dialogue, a task is started to update the database, which results in the dialog box closing and the parent listview being redrawn.

      what I am finding is that if the user works fast, they can double click again and restart the process BEFORE the parent listview is redrawn. Everything looks OK, but for several reasons the subsequent database update fails.

      So, how to disable the double click action until the task is complete? The challenge is there are multiple of these listview boxes, and non should be actionable until the database update is complete and the boxes are redrawn.

      Obviously I could loop thru each listview box before opening the dialogue, removing the doubleclick event handler. then I could have the task reinstall the doubelclick event handler after the screen redraw is complete (can't I?)

      I was hoping for something more graceful...
        • 1. Re: Looking for design help
          To me, the simplest solution would be to make the dialog modal, and not to dismiss it until the database update is complete. This would prevent them going back to the main window at all. You can do fun stuff like binding the disable property of any "OK" and "Cancel" type buttons to the running property of the task that updates the database.

          But perhaps this is too restrictive; for example, do you want the user to be able to interact with other parts of the UI while the update is progressing?
          • 2. Re: Looking for design help
            Honestly I just hadn't thought of something that simple.

            If I did that would there be any real reason to use a background task, since I want the task to complete anyway?
            • 3. Re: Looking for design help
              I wondered that after I'd posted it.

              I guess I still think it's good practice to put the database update in a background task. It's easy enough to do so, you get all the nice semantics of task.setOnSucceeded(...) and task.setOnFailed(...) that nicely encapsulate the fact that you're waiting for a process to do something, and you'd be properly set up if you decided to add any other functionality in there. Also, if you're blocking the FX Application thread, you'll likely get strange results if you cover and then uncover your application with a different window (your application might not get the opportunity to repaint).
              • 4. Re: Looking for design help
                I went with your suggestion and it works fine now, Thanks!