3 Replies Latest reply on May 23, 2013 2:53 AM by James_D

    Is it possible to enable/disable table row selection?

      I have a situation where a user can add rows to a "selection" table with a value that is used to perform a query to get a collection of objects associated with that value. Once those objects are available, a second "results" table will be populated with the row(s) returned. When the value is entered in the selection table, a web service call is made to perform the query and return the results. This may take a few moments and I am displaying an indeterminate progress indicator for the selection table row involved to indicate that the data is not yet available - the progress indicator is included as a column in the row; each row has its own indicator. Once the results are received the indicator is hidden to indicate the query for that row has completed. The user may enter as many rows in the selection table as they wish so there is a distinct possibility of multiple queries being executed at a given time. I have also attached a row selection listener to the selection table such that when a given row is selected, the results table will display the corresponding associated row(s).

      What I'd like to be able to do is somehow temporarily disable the selection of any row that has a query in progress, while leaving other rows whose queries have completed be selectable. Once the query completes, the row can then become selectable, thus allowing for the results to be loaded and displayed in the results table. The way it works right now, if the row is selected while the query is still in progress, nothing is displayed (obviously), but then the row has to be re-selected after the query has completed to see the results. This is a viable (though undesirable) solution/workaround if there is at least one other row in the table. However, if the row is the only row in the table and has been selected, it cannot be re-selected (there's no other row to select to allow for re-selection). To boil it down, what I'd like to do is prevent the selection of the row until the query for that row is complete.

      After perusing the JavaFX 2.2 API, I'm not seeing any obvious way to achieve this effect. If anyone has any solutions, suggestions, etc. on how this could be done I'd appreciate it greatly.
        • 1. Re: Is it possible to enable/disable table row selection?
          A few days ago I would have suggested implementing a custom SelectionModel for your table. That's still an approach I'd consider but you might want to read {thread:id=2537109} first. I suspect you may run into similar issues with the TableView as arose with ListView; so you may need to be prepared to work around some strange keyboard navigation implementations.
          • 2. Re: Is it possible to enable/disable table row selection?
            I read the posting suggested and will keep an eye out for the potential issues mentioned.

            I will try to muddle my way through extending the TableViewSelectionModel, but if anyone has an example that would help also.
            • 3. Re: Is it possible to enable/disable table row selection?
              Here's an [url https://github.com/james-d/Conditionally-selectable-table]example. As predicted, keyboard navigation fails if the keyboard presses would result in an unselectable item being selected using the default selection model. The best workaround I can see for this is to register event filters for the appropriate keyboard strokes, as in the previously referenced thread.

              Update: That code won't run in the current (ea b90) release of JavaFX 8.0, and probably a few recent releases; it will however run in the final release (and it runs in JDK 7). See [url https://javafx-jira.kenai.com/browse/RT-30593]RT-30593

              Edited by: James_D on May 22, 2013 7:51 PM
              1 person found this helpful