You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Vicente de Rivera III <th...@gmail.com> on 2009/10/01 08:25:53 UTC

Re: Validation in TableViewEditor

although not much of a big deal, when a user would create a new record/row
in the TableView, all the TextInput which should not be empty will all be
colored red.

I tried doing a simple boolean firstTimeInputFlag trick in the validator but
failed.

Any solution to this? thanks

On Wed, Sep 30, 2009 at 8:43 PM, Todd Volkert <tv...@gmail.com> wrote:

> Why not just attach the appropriate validators to your text inputs?  Then,
> when they're invalid, they'll paint themselves to look invalid, which should
> save you the burden of alerting the user as to why the edit is being
> denied.  Then your previewSaveChanges() method becomes a simple deny vs.
> approve decision and gets trimmed down to one line.
>
> -T
>
>
> On Wed, Sep 30, 2009 at 7:19 AM, Vicente de Rivera III <
> thirdy.derivera@gmail.com> wrote:
>
>> I'm using TableViewEditor a lot and I noticed in my code that for all
>> TableViewEditor, I have
>>    tableViewRowEditor.getRowEditorListeners().add(new
>> TableView.RowEditorListener.Adapter() {
>>             private boolean shown = false;
>>             private boolean invalid = false;
>>             @Override
>>             public Vote previewSaveChanges(RowEditor rowEditor, TableView
>> tableView, int rowIndex, int columnIndex, Dictionary<String, Object>
>> changes) {
>>                 invalid = usernameTI.getText().isEmpty() ||
>> passwordTI.getText().isEmpty();
>>                 String errorMsg = (usernameTI.getText().isEmpty() ?
>> "Username" : "") +
>>                                   (passwordTI.getText().isEmpty() ?
>> "Password" : "") +
>>                                   " cannot be empty";
>>                 if (invalid) {
>>                     if (!shown) {
>>                         Prompt.prompt(MessageType.ERROR, errorMsg, null,
>> main.getWindow(),
>>                                 new SheetCloseListener() {
>>
>>                                     public void sheetClosed(Sheet sheet) {
>>                                         shown = false;
>>                                     }
>>                                 });
>>                         shown = true;
>>                     }
>>                     return Vote.DENY;
>>                 }
>>                 return Vote.APPROVE;
>>             }});
>>
>> I'm thinking maybe I could just add validation to TableViewEditor.
>> Something like
>>       tableViewRowEditor.getValidators().add(
>> org.apache.pivot.wtk.text.validation.Validator )
>>
>
>

Re: Validation in TableViewEditor

Posted by Vicente de Rivera III <th...@gmail.com>.
My mistake, thought it was working with amountTextInput.getWindow(). For now
I'll leave it to my flag solution

Re: Validation in TableViewEditor

Posted by Todd Volkert <tv...@gmail.com>.
Nope - the prompt is showing over it's owner window, which is the editor
popup.  I'm still trying to think about how to get it to show up over the
main window but work properly...

On Sat, Oct 3, 2009 at 12:00 AM, Vicente de Rivera III <
thirdy.derivera@gmail.com> wrote:

> AWESOME! The Prompt even showed @ the TextInput. Works great now.To
> improve it more, can I get the Prompt to show below the TextInput? Currently
> it shows over the TextInput
>
> thanks Todd
>

Re: Validation in TableViewEditor

Posted by Vicente de Rivera III <th...@gmail.com>.
AWESOME! The Prompt even showed @ the TextInput. Works great now.To improve
it more, can I get the Prompt to show below the TextInput? Currently it
shows over the TextInput

thanks Todd

Re: Validation in TableViewEditor

Posted by Todd Volkert <tv...@gmail.com>.
Out of curiosity Vicente, what happens if you open the prompt with the
editor popup as its owner?  Instead of passing 'window' as the owner, pass
'amountTextInput.getWindow()'.  My guess is that this will work, but I'm not
at a terminal in which I can test this.
-T

On Fri, Oct 2, 2009 at 6:04 PM, Todd Volkert <tv...@gmail.com> wrote:

> Just looked into this.  The issue isn't so much that previewSaveChanges is
> being called too many times, but that clicking the OK button in the prompt
> to dismiss the prompt is causing the row editor to try to save its changes
> *again* (and again, ...).  You can see this by hitting ENTER or SPACE to
> dismiss the prompt instead.
>
> I'll let you know when a fix is in :)
>
> Cheers,
> -T
>
>
> On Thu, Oct 1, 2009 at 9:42 PM, Vicente de Rivera III <
> thirdy.derivera@gmail.com> wrote:
>
>> yeah you're right mr.Todd, haha sorry.btw, I think this is a bug with the
>> TableRowEditor. I tried it with the tableroweditor demo, added a validation
>> that will prompt if the amount text input is empty
>>         tableViewRowEditor.getRowEditorListeners().add(new
>> TableView.RowEditorListener.Adapter() {
>>
>>             @Override
>>             public Vote previewSaveChanges(RowEditor rowEditor, TableView
>> tableView, int rowIndex, int columnIndex,
>>                     Dictionary<String, Object> changes) {
>>                 if (amountTextInput.getText().isEmpty()) {
>>                     Prompt.prompt(MessageType.ERROR, "amt empty", null,
>> window);
>>                      return Vote.DENY;
>>                 }
>>                 return Vote.APPROVE;
>>             }
>>           });
>>
>> while in edit mode and amountTextInput is empty, clicking any other row
>> will call previewSaveChanges a lot
>>
>
>

Re: Validation in TableViewEditor

Posted by Todd Volkert <tv...@gmail.com>.
Just looked into this.  The issue isn't so much that previewSaveChanges is
being called too many times, but that clicking the OK button in the prompt
to dismiss the prompt is causing the row editor to try to save its changes
*again* (and again, ...).  You can see this by hitting ENTER or SPACE to
dismiss the prompt instead.

I'll let you know when a fix is in :)

Cheers,
-T

On Thu, Oct 1, 2009 at 9:42 PM, Vicente de Rivera III <
thirdy.derivera@gmail.com> wrote:

> yeah you're right mr.Todd, haha sorry.btw, I think this is a bug with the
> TableRowEditor. I tried it with the tableroweditor demo, added a validation
> that will prompt if the amount text input is empty
>         tableViewRowEditor.getRowEditorListeners().add(new
> TableView.RowEditorListener.Adapter() {
>
>             @Override
>             public Vote previewSaveChanges(RowEditor rowEditor, TableView
> tableView, int rowIndex, int columnIndex,
>                     Dictionary<String, Object> changes) {
>                 if (amountTextInput.getText().isEmpty()) {
>                     Prompt.prompt(MessageType.ERROR, "amt empty", null,
> window);
>                     return Vote.DENY;
>                 }
>                 return Vote.APPROVE;
>             }
>           });
>
> while in edit mode and amountTextInput is empty, clicking any other row
> will call previewSaveChanges a lot
>

Re: Validation in TableViewEditor

Posted by Vicente de Rivera III <th...@gmail.com>.
yeah you're right mr.Todd, haha sorry.btw, I think this is a bug with the
TableRowEditor. I tried it with the tableroweditor demo, added a validation
that will prompt if the amount text input is empty
        tableViewRowEditor.getRowEditorListeners().add(new
TableView.RowEditorListener.Adapter() {

            @Override
            public Vote previewSaveChanges(RowEditor rowEditor, TableView
tableView, int rowIndex, int columnIndex,
                    Dictionary<String, Object> changes) {
                if (amountTextInput.getText().isEmpty()) {
                    Prompt.prompt(MessageType.ERROR, "amt empty", null,
window);
                    return Vote.DENY;
                }
                return Vote.APPROVE;
            }
          });

while in edit mode and amountTextInput is empty, clicking any other row will
call previewSaveChanges a lot

Re: Validation in TableViewEditor

Posted by Todd Volkert <tv...@gmail.com>.
That's really what the preview event is for though.  We wouldn't want to
code the alert or any error message into the validator, because it's too
app-specific.  So if we had a changes validator, it'd look exactly like the
preview event does (where it passes you the changes, and you return ALLOW or
DENY).  I think this may be best handled by refactoring your code to put the
validation logic in a common method that can be called from all of your
preview event methods.
-T

On Thu, Oct 1, 2009 at 4:11 AM, Vicente de Rivera III <
thirdy.derivera@gmail.com> wrote:

>
> I guess that's why I did a Prompt error message solution.
>>
>
> How about tableViewEditor.setChangesValidator(
> TableViewEditorChangesValidator );
> where the isValid method of TableViewEditorChangesValidator accepts the
> object/row from the TableData
>

Re: Validation in TableViewEditor

Posted by Vicente de Rivera III <th...@gmail.com>.
> I guess that's why I did a Prompt error message solution.
>

How about tableViewEditor.setChangesValidator(
TableViewEditorChangesValidator );
where the isValid method of TableViewEditorChangesValidator accepts the
object/row from the TableData

Re: Validation in TableViewEditor

Posted by Vicente de Rivera III <th...@gmail.com>.
I guess that's why I did a Prompt error message solution.

btw, ButtonPressListenter.buttonPressed attribute is really cleaning a lot
of my code, really cool