Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Node name validation at creation time. Lock focus on an editpart?
Node name validation at creation time. Lock focus on an editpart? [message #163600] Sun, 02 December 2007 11:03 Go to next message
Eclipse UserFriend
Originally posted by: arvinderbirdi.sbcglobal.net

We have normal nodes with name editparts which contains the node name.

I'm attempting to change the generated code to:

1) check for validity of the name of a new node when it is entered

2) create a popup when it is invalid

3) return the name editpart to the editing state when an invalid name
is entered

I have derived MyDirectEditmanager from
" org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManag er " and used
it in the generated XYZNameEditPart



MyDirectEditmanager:

1) Initially gets the cell editor and sets a Validator.

2) When keys are pressed: the validator calls my validation routine and then
sets the error message string when an validation error occurs.

3) Overrides commit() -

It first checks if the cellEditor's error message string is set.

IF NOT SET

calls super.commit()

ELSE

It pops an error dialog and attempts to return the cell editor to the
edit state via:

getCellEditor().activate();

getCellEditor().getControl().setVisible(true);

getCellEditor().getControl().setFocus();

A complication is that the pop up dialog creates a loss of focus event
which causes commit to be called again. I have a flag to check for this.



Problems:

1) When the valid name is entered after an invalid name the editing box
still shows up as part of the node figure. I'm assuming DirectEditManager's
showingFeedback flag gets out of sync with what I'm doing.

2) I think this approach would also require me to lock focus on the editpart
to prevent the user from selecting another node while the current node has
an invalid name. Can this be done?

Are there better alternatives?

Thanks in advance,

Arvinder Birdi
Re: Node name validation at creation time. Lock focus on an editpart? [message #163905 is a reply to message #163600] Mon, 03 December 2007 12:37 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I think this needs to be done on command creation or command execution
time. There is a DirectEditPolicy#getDirectEditCommand() method where the
command is created. So, if typed in value is generally invalid for all
node names you could validation at the command creation time. Otherwise, I
would move this to the model validation level, i.e. command execution
time. If an invalid value is being assigned to a model element you would
throw an exception for example and the UI would look at the exception and
show the appropriate popup message.
Hope this helps.

Cheers,
Alex
Re: Node name validation at creation time. Lock focus on an editpart? [message #163926 is a reply to message #163905] Mon, 03 December 2007 22:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: arvinderbirdi.sbcglobal.net

Thanks. I understand the first approach using editpolcy, not the second.

Also I'm using GMF/EMF. I'm new to java exceptions (used c#/C++). I tried
to change one of the generated EMF model IMPL classes to throw an exception
but it looked like I had to declare "throws" in the signature all the way up
to the caller!

Where should I digg around for:

UI looking at the exception: I'm assuimg this would be the editor. Is there
some configurable exception catcher?

Command execution: The EMF command SET is being executed to set the name of
the model element. I wonder if I can extend the SET command and return some
error value.

thanks again,
Arvinder

"Alex Boyko" <aboyko@ca.ibm.com> wrote in message
news:2dc101da6b0ccf74ece430245daa56a6$1@www.eclipse.org...
> Hi,
>
> I think this needs to be done on command creation or command execution
> time. There is a DirectEditPolicy#getDirectEditCommand() method where the
> command is created. So, if typed in value is generally invalid for all
> node names you could validation at the command creation time. Otherwise, I
> would move this to the model validation level, i.e. command execution
> time. If an invalid value is being assigned to a model element you would
> throw an exception for example and the UI would look at the exception and
> show the appropriate popup message.
> Hope this helps.
>
> Cheers,
> Alex
>
Re: Node name validation at creation time. Lock focus on an editpart? [message #164305 is a reply to message #163905] Tue, 04 December 2007 19:48 Go to previous message
Eclipse UserFriend
Originally posted by: arvinderbirdi.sbcglobal.net

I found a less fancy solution. I pop a jface InputDialog when the text is
invalid from the DirectEditTool subclass.
The dialog can only be closed if the text is valid.

-Arvinder


"Alex Boyko" <aboyko@ca.ibm.com> wrote in message
news:2dc101da6b0ccf74ece430245daa56a6$1@www.eclipse.org...
> Hi,
>
> I think this needs to be done on command creation or command execution
> time. There is a DirectEditPolicy#getDirectEditCommand() method where the
> command is created. So, if typed in value is generally invalid for all
> node names you could validation at the command creation time. Otherwise, I
> would move this to the model validation level, i.e. command execution
> time. If an invalid value is being assigned to a model element you would
> throw an exception for example and the UI would look at the exception and
> show the appropriate popup message.
> Hope this helps.
>
> Cheers,
> Alex
>
Previous Topic:Configuring Copy/Paste does not work
Next Topic:gmf constraints
Goto Forum:
  


Current Time: Wed Apr 30 10:21:39 EDT 2025

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

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

Back to the top