Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » CellEditorValidator's returned error message
CellEditorValidator's returned error message [message #447746] Thu, 16 December 2004 23:02 Go to next message
Steve Lewis is currently offline Steve LewisFriend
Messages: 2
Registered: July 2009
Junior Member
All of the snippets, javadoc, and examples I can find for using a
CellEditor are well constructed and helped me get this far.
Unfortunately, they are fairly trivial and do not demonstrate all of
the available features.

I have a TableViewer up and working, with CellEditors in place where I
want them. The TableView has a number of columns that use
TextCellEditors. In many columns I have a validator in place, as
appropriate to the column.

My problem is that I am having a difficult time determining how to
best collect the error messages that result from invalid inputs. I
haven't seen an example of a CellEditor with an ICellModifier and
ICellValidator that captures the CellEditor.errorMessage for the user.

One solution: I could attach another object (implementing
ICellEditorListener) to each and every editable column, and when an
edit occurs check that column's CellEditor's errorMessage; that
doesn't /feel/ right.

Second solution: Though this behavior is undocumented, and therefore I
consider it unstable, when the ICellEditorValidator returns a non-null
&& non-empty-string error message, the associated modify() method of
the attached ICellModifier is called with a null parameter. I can
detect this behavior, and check the associated CellEditor's error
message, advancing an appropriate user error. I have tested this and
it is working for now, but I don't know what will happen in future
JFace/SWT libs.

Is there a better pattern for listening for and collecting a
CellEditor.errorMessage? What was /intended/ here?

FWIW, below is a snippet of the TableView construction code I am using.

// set up the table and columns

// set up the table viewer
TableViewer viewer = new TableViewer(table);
viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));

// set up the cell editors and cell modifiers
CellEditor[] editors = new CellEditor[table.getColumnCount()];
editors[COLUMN_DISTANCE] = new TextCellEditor(table);
editors[COLUMN_DISTANCE].setValidator(
new ICellEditorValidator()
{
public String isValid( Object value )
{
boolean isValid = false;
int dist = StringConverter.asInt( value.toString(), -1);
if (dist >= 1 && dist <= 30)
isValid = true;

return (isValid) ? null : DISTANCE_VALUES_ALLOWED_MESSAGE;
}
});

// define the other CellEditors, attach the rest of the validators
// define the viewer's label provider and content provider

tia,
--
Steve Lewis
Re: CellEditorValidator's returned error message [message #447920 is a reply to message #447746] Tue, 21 December 2004 23:10 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Steve, you may get more response if you ask this on the eclipse.platform
newsgroup since that is where jface lives.

Grant

"Steve Lewis" <nepolon@worlddomination.net> wrote in message
news:cpt45j$n62$1@www.eclipse.org...
> All of the snippets, javadoc, and examples I can find for using a
> CellEditor are well constructed and helped me get this far.
> Unfortunately, they are fairly trivial and do not demonstrate all of
> the available features.
>
> I have a TableViewer up and working, with CellEditors in place where I
> want them. The TableView has a number of columns that use
> TextCellEditors. In many columns I have a validator in place, as
> appropriate to the column.
>
> My problem is that I am having a difficult time determining how to
> best collect the error messages that result from invalid inputs. I
> haven't seen an example of a CellEditor with an ICellModifier and
> ICellValidator that captures the CellEditor.errorMessage for the user.
>
> One solution: I could attach another object (implementing
> ICellEditorListener) to each and every editable column, and when an
> edit occurs check that column's CellEditor's errorMessage; that
> doesn't /feel/ right.
>
> Second solution: Though this behavior is undocumented, and therefore I
> consider it unstable, when the ICellEditorValidator returns a non-null
> && non-empty-string error message, the associated modify() method of
> the attached ICellModifier is called with a null parameter. I can
> detect this behavior, and check the associated CellEditor's error
> message, advancing an appropriate user error. I have tested this and
> it is working for now, but I don't know what will happen in future
> JFace/SWT libs.
>
> Is there a better pattern for listening for and collecting a
> CellEditor.errorMessage? What was /intended/ here?
>
> FWIW, below is a snippet of the TableView construction code I am using.
>
> // set up the table and columns
>
> // set up the table viewer
> TableViewer viewer = new TableViewer(table);
> viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
>
> // set up the cell editors and cell modifiers
> CellEditor[] editors = new CellEditor[table.getColumnCount()];
> editors[COLUMN_DISTANCE] = new TextCellEditor(table);
> editors[COLUMN_DISTANCE].setValidator(
> new ICellEditorValidator()
> {
> public String isValid( Object value )
> {
> boolean isValid = false;
> int dist = StringConverter.asInt( value.toString(), -1);
> if (dist >= 1 && dist <= 30)
> isValid = true;
>
> return (isValid) ? null : DISTANCE_VALUES_ALLOWED_MESSAGE;
> }
> });
>
> // define the other CellEditors, attach the rest of the validators
> // define the viewer's label provider and content provider
>
> tia,
> --
> Steve Lewis
Previous Topic:Buildin personal SWT
Next Topic:TableTreeViewer and its Model
Goto Forum:
  


Current Time: Wed Oct 21 02:40:56 GMT 2020

Powered by FUDForum. Page generated in 0.02157 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top