Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to determine selected element on a node
How to determine selected element on a node [message #632877] Thu, 14 October 2010 14:36 Go to next message
Nigel is currently offline NigelFriend
Messages: 7
Registered: October 2010
Junior Member
Hi,

I have successfully created and used a custom data type and used it as
an an attribute in my ecore model. This appears on my models nodes.
Users can manually edit these but it would be much friendlier to provide
an edit dialog. Following the example in the 'GMF Best Practices'
presentation (Slide 8) I have created a custom edit policy and attached
it to my GMF gen model using a custom behavior to the attributes edit part.

When the user double clicks the selected attribute, my custom edit
policy is called (as expected) and this code is run:

protected Command getOpenCommand(Request request)
{
ICommandProxy commandProxy = null;

EditPart targetEditPart = getTargetEditPart(request);

if (targetEditPart.getModel() instanceof View)
{
View view = (View)targetEditPart.getModel();
EAttribute attribute = (EAttribute)view.getElement();

commandProxy = new ICommandProxy(new
ModifyValueFloatCommand(attribute));
}

return commandProxy;
}

Unfortunatley a classcast exception occurs on the line:

EAttribute attribute = (EAttribute)view.getElement();

In the debugger I can see that the entire node is being returned not
just the selected attribute. What i need to know is:

a) Can just the attribute be returned (according to the example in 'GMF
Best Practices' it looks like it can)? If so how?

b) If only the node can be returned (some of the documentation for GEF
suggests that the attribute may not count as an individual visible part
and may not be represented in the model) can I identify the selected
part from it, or the request?

c) Is there another way of interrogating GMF to know which element is
selected? At the data type is used more than once in the same node i
cannot assume I know the one selected.

Thanks for any help on this one, I have spent two very frustrating days
in the eclipse debugger and Google searching to try and crack this one.

Best regards,

Nigel
Re: How to determine selected element on a node [message #632900 is a reply to message #632877] Thu, 14 October 2010 15:21 Go to previous messageGo to next message
Mariot Chauvin is currently offline Mariot ChauvinFriend
Messages: 174
Registered: July 2009
Senior Member
Hi Nigel,

To know which edit parts are selected you may call GraphicalViewer#getSelectedEditParts().

Hope this help.
Regards,

Mariot


--
Mariot Chauvin @ Obeo

<a href="http://www.obeo.fr">http://www.obeo.fr</a>
<a href="http://mariot-thoughts.blogspot.com">http://mariot-thoughts.blogspot.com</a>
<a href="http://fr.linkedin.com/in/mariotchauvin">http://fr.linkedin.com/in/mariotchauvin</a>

Nigel Daniels a écrit :
> Hi,
>
> I have successfully created and used a custom data type and used it as
> an an attribute in my ecore model. This appears on my models nodes.
> Users can manually edit these but it would be much friendlier to provide
> an edit dialog. Following the example in the 'GMF Best Practices'
> presentation (Slide 8) I have created a custom edit policy and attached
> it to my GMF gen model using a custom behavior to the attributes edit part.
>
> When the user double clicks the selected attribute, my custom edit
> policy is called (as expected) and this code is run:
>
> protected Command getOpenCommand(Request request)
> {
> ICommandProxy commandProxy = null;
>
> EditPart targetEditPart = getTargetEditPart(request);
>
> if (targetEditPart.getModel() instanceof View)
> {
> View view = (View)targetEditPart.getModel();
> EAttribute attribute = (EAttribute)view.getElement();
>
> commandProxy = new ICommandProxy(new
> ModifyValueFloatCommand(attribute));
> }
>
> return commandProxy;
> }
>
> Unfortunatley a classcast exception occurs on the line:
>
> EAttribute attribute = (EAttribute)view.getElement();
>
> In the debugger I can see that the entire node is being returned not
> just the selected attribute. What i need to know is:
>
> a) Can just the attribute be returned (according to the example in 'GMF
> Best Practices' it looks like it can)? If so how?
>
> b) If only the node can be returned (some of the documentation for GEF
> suggests that the attribute may not count as an individual visible part
> and may not be represented in the model) can I identify the selected
> part from it, or the request?
>
> c) Is there another way of interrogating GMF to know which element is
> selected? At the data type is used more than once in the same node i
> cannot assume I know the one selected.
>
> Thanks for any help on this one, I have spent two very frustrating days
> in the eclipse debugger and Google searching to try and crack this one.
>
> Best regards,
>
> Nigel
Re: How to determine selected element on a node [message #633089 is a reply to message #632900] Fri, 15 October 2010 10:25 Go to previous message
Nigel is currently offline NigelFriend
Messages: 7
Registered: October 2010
Junior Member
Hi Mariot,

thanks for your suggestion, I gave this a try last night:

MyDiagramEditorPlugin myEditorPlugin =
MyDiagramEditorPlugin.getInstance();
IEditorPart activeEditor =
myEditorPlugin.getWorkbench().getActiveWorkbenchWindow().get ActivePage().getActiveEditor();

IDiagramGraphicalViewer graphicalViewer =
((MyDiagramEditor)activeEditor).getDiagramGraphicalViewer();
EditPart editPart = graphicalViewer.getFocusEditPart();

List partList = graphicalViewer.getSelectedEditParts();
EditPart selectedPart = (EditPart)partList.get(0);

EAttribute attribute =
(EAttribute)((View)selectedPart.getModel()).getElement();

Unfortunately this throws the same exception. It seems that the EditPart
returned is the same EditPart returned by the original call:

View view = (View)targetEditPart.getModel();

The EditPart in both cases seems to be the correct edit part, the name
takes the form <NodeName><AttributeName>EditPart, however in both cases
the call:

((View)EditPart.getModel()).getElement();

returns the entire NodeImpl which I cannot cast to the EAttribute. In
the debugger I can see that there are a couple of components of the
EditPart that do reference the attribute:

EditPart.figure seems to have a WrappingLabel for the attribute.
EditPart.parser.editableFeatures is the EAttribute I want.

I have tried going through the following to get the parser:

CompartmentEditPart cmpEditPart = (CompartmentEditPart)targetEditPart;
IDiagramEditDomain domain = cmpEditPart.getDiagramEditDomain();
MessageFormatParser parser =
(MessageFormatParser)txtEditPart.getParser();

But then I could see no way of requesting the EAttribute from the parser.

Thanks for any other suggestions you may have.

Best regards,

Nigel
On 14/10/2010 16:21, Mariot Chauvin wrote:
> Hi Nigel,
>
> To know which edit parts are selected you may call GraphicalViewer#getSelectedEditParts().
>
> Hope this help.
> Regards,
>
> Mariot
>
>
Previous Topic:SyntaxError in a top::Figure.xpt template
Next Topic:How to create multiline messages in GMF?
Goto Forum:
  


Current Time: Wed Sep 25 15:24:11 GMT 2024

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

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

Back to the top