Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » From Model to Edit Part
From Model to Edit Part [message #708199] Tue, 02 August 2011 15:05 Go to next message
nicolas h is currently offline nicolas hFriend
Messages: 60
Registered: February 2011
Location: Grenoble, France
Member
Hi there,
I've been mulling it over for a long time.
I know how to get Model Element from Edit Part :
EObject myObject = myEditPart.resolveSemanticElement();


Is there a way to get the Edit Part from the Model Element please ?


Regards,

--
Nicolas
Re: From Model to Edit Part [message #708209 is a reply to message #708199] Tue, 02 August 2011 15:17 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi nicolas,

have you tried

EditPart editPart = (EditPart) getDiagramGraphicalViewer().getEditPartRegistry().get(semanticElement);

?

Regards,
Andreas



Re: From Model to Edit Part [message #708247 is a reply to message #708209] Tue, 02 August 2011 15:58 Go to previous messageGo to next message
nicolas h is currently offline nicolas hFriend
Messages: 60
Registered: February 2011
Location: Grenoble, France
Member
Thanks for your answer Andreas.

getDiagramGraphicalWiever may be defined in IDiagramWorkbenchPart interface, implemented in <myModel>DiagramEditor. I don't really know how to access to this reference.

Here is my usecase :

I had just created my diagram and open my Diagram in my Diagram Editor :
Resource diagram = <myModel>DiagramEditorUtil.createDiagram(diagramModelFileURI, domainModelFileURI, monitor);
/* ... */
<myModel>DiagramEditorUtil.openDiagram(diagram);


1. <myModel>DiagramEditor is the one active Editor. Can I get a <myModel>DiagramEditor reference after that ?

2. Can I get <myModel>DiagramEditor reference without opening it ?

Thank you,

Regards,

Nico


Re: From Model to Edit Part [message #708250 is a reply to message #708199] Tue, 02 August 2011 15:19 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Hi,

Assuming that your "parentEditPart" contains the editPart which
represents the "targetModelElement" in one of its children or
grand-children, you can try the following line:

IGraphicalEditPart targetPart =
parentEditPart.findEditPart(parentEditPart, targetModelElement);

HTH,

--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: From Model to Edit Part [message #708770 is a reply to message #708247] Wed, 03 August 2011 06:51 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi nicolas

Quote:

1. <myModel>DiagramEditor is the one active Editor. Can I get a <myModel>DiagramEditor reference after that ?

The DiagramEditorUtil#openEditor returns a reference to your editor. Or you can
access the active editor like this:

IEditorPart myEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();

This only works from within the display thread, so maybe you have to wrap this call into a Display#syncExec().

The IEditorPart is then adaptable to the graphical viewer:

IEditorPart myEditor = DiagramEditorUtil.openEditor(...);
GraphicalViewer viewer = (GraphicalViewer.class)myEditor.getAdapter(GraphicalViewer.class):


Quote:

2. Can I get <myModel>DiagramEditor reference without opening it ?

What is the need for that? Sure you can, but you can not access editparts since they will be created on editor open and disposed on editor close.



Re: From Model to Edit Part [message #708816 is a reply to message #708770] Wed, 03 August 2011 07:43 Go to previous messageGo to next message
nicolas h is currently offline nicolas hFriend
Messages: 60
Registered: February 2011
Location: Grenoble, France
Member
Hi Mickael, Andreas

Thanks for your replies.

Quote:
The DiagramEditorUtil#openEditor returns a reference to your editor. Or you can
access the active editor like this:

IEditorPart myEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();



Good idea, I didn't think about getting my editor instance by that way.

Quote:
What is the need for that? Sure you can, but you can not access editparts since they will be created on editor open and disposed on editor close.


It means that my solution does not solve my initial problem:

UC1:
I want to create my diagram, create a small initial model, and finally open my diagram. Sure I can use DiagramEditorUtil#createInitialModel to add model elements to my diagram, but I don't know how to define the position and the size of my elements on diagram.

UC2:
As a general rule, I wish I could add semantic element with it graphical aspect anywhere, in a view for example, even if the diagram is closed. For example, I generate <model>Diagram width GMF, So I two files, the model file xxx.model and the diagram file xxx.model_diag. I release a button in a view, and a new model element is added in xxx.model with it graphical aspect in xxx.model_diag, so I could see it when I opened my diagram.

For that, I found some code using CreateViewAndElementRequest class but in order to adding an object in the diagram, I had to get the rootEditPart.

Obviously, using editpart is not the way to do this...

Quote:
Hi,

Assuming that your "parentEditPart" contains the editPart which
represents the "targetModelElement" in one of its children or
grand-children, you can try the following line:

IGraphicalEditPart targetPart =
parentEditPart.findEditPart(parentEditPart, targetModelElement);

HTH,


That might be my previous problem : I did'nt know how to get "(parent|root)EditPart"

Thanks for your help,

Regards,

--
Nicolas
Re: From Model to Edit Part [message #708886 is a reply to message #708816] Wed, 03 August 2011 08:58 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi Nicolas,
Quote:

UC1:
I want to create my diagram, create a small initial model, and finally open my diagram. Sure I can use DiagramEditorUtil#createInitialModel to add model elements to my diagram, but I don't know how to define the position and the size of my elements on diagram.

I did something similar in my open source project YAKINDU Statechart Tools. This code creates a semantic element (initialState) and adds some layout constraints to the view. Maybe this is a starting point for you.
//Create semantic element
Entry initialState = SGraphFactory.eINSTANCE.createEntry();
		initialState.setKind(EntryKind.INITIAL);
//Create view for semantic element
Node initialStateView = ViewService.createNode(
				parentView, initialState,
				SemanticHints.ENTRY, DiagramActivator.DIAGRAM_PREFERENCES_HINT);
//Set inital bounds for the view
Bounds bounds = NotationFactory.eINSTANCE.createBounds();
		bounds.setX(70);
		bounds.setY(20);
		initialStateView.setLayoutConstraint(bounds);


Quote:

UC2:
As a general rule, I wish I could add semantic element with it graphical aspect anywhere, in a view for example, even if the diagram is closed. For example, I generate <model>Diagram width GMF, So I two files, the model file xxx.model and the diagram file xxx.model_diag. I release a button in a view, and a new model element is added in xxx.model with it graphical aspect in xxx.model_diag, so I could see it when I opened my diagram.


Basically, the approach of UC1 works for that Usecase, too. You can simply load the resource and modify it like this.



Re: From Model to Edit Part [message #709727 is a reply to message #708886] Thu, 04 August 2011 08:27 Go to previous message
nicolas h is currently offline nicolas hFriend
Messages: 60
Registered: February 2011
Location: Grenoble, France
Member
Hi Andreas,
Thanks for your example. I will go into detail soon.

Regards,

--
Nicolas
Previous Topic:EMF and GEF
Next Topic:Variables View
Goto Forum:
  


Current Time: Sat Apr 20 04:44:58 GMT 2024

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

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

Back to the top