Yep - this type of behavior is supported via the TableView.RowEditor
interface.  There are two stock editors available for you to use, or you can
implement your own.  The two stock ones are
org.apache.pivot.wtk.content.TableViewRowEditor and
org.apache.pivot.wtk.content.TableViewCellEditor.

This isn't covered in the tutorials yet, so I'll do my best to describe how
it works here...

You set a row editor on a table view using TableView.setRowEditor().  When a
row editor has been set, the table view's skin will respond to "edit
gestures" by invoking the edit() method of the editor.  Right now, the skin
responds to a double-click on the row.  Once the editor has been called to
edit, it is responsible for knowing when it should save() or cancel().  Note
that you can register key press listeners on the table view and call into
the editor yourself if you want keyboard gestures to invoke the editor as
well.

Now as to what the editor does behind the scenes...

The table view isn't a container, so it can't contain list buttons or the
like -- and renderer's don't receive input.  So generally, editors will open
a popup over an individual cell or the entire row that makes it look like
the content of the row changed to input components.  Then when the user
finishes their edit, the editor closes the popup and updates the model of
the table view (tableView.getTableData().update(...)).

The stock TableViewRowEditor opens a popup over the entire row in which the
user can edit all the cells before saving.  Each cell's editor component is
configurable (you can use a ListButton in one, a Spinner in another, etc.).
In fact, you can even set up some cells to use Labels (or disabled
TextInputs) if you don't want them to be editable.  You can see an example
of this editor in action by running the table view row editor demo
(org.apache.pivot.demos.roweditor.RowEditorDemo).

The stock TableViewCellEditor opens a popup over an individual cell, and
that popup always contains a TextInput.  It's not as versatile as
TableViewRowEditor, but it's lighter and satisfies the common use case of
simple TextInput-based edits.

If neither of these satisfied your needs and you had to write your own, I'd
study the two stock editors, because a lot of what you'd have to do would be
copy/paste from them :)

Let me know if you have any more questions,
-T

On Mon, Sep 7, 2009 at 8:37 PM, Scott Lanham <[email protected]> wrote:

> Hi,
>
> I am getting a little lost in how to do in place editing in a TableView.
> When
> a row is selected I need a ListButton to appear in some of the cells in
> place
> of the text that was being displayed. The ListButton is used to edit the
> cell.
> Is this possible?
>
> Thanks,
>
> Scott.
>

Reply via email to