Access objects displayed in editor [message #201380] |
Mon, 11 August 2008 06:38  |
Eclipse User |
|
|
|
Originally posted by: daylmer.opencloud.com
I have made a simple ecore model representing a basic state transition
machine. From that I have used gmf to generate the necessary files to
create the graphical editor. I can run this editor as a separate eclipse
application. I can create a new diagram and add states, transitions etc.
and it updates both the diagram and the model. My question is how do I get
hold of the Java objects that have been instantiated which represent the
various parts of the diagram. How can I write a simple class in this
running eclipse application which could access the states and transitions
in order to check them for integrity or simply print out their names on
the command line?
Thank you
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Access objects displayed in editor [message #201804 is a reply to message #201770] |
Wed, 13 August 2008 07:42  |
Eclipse User |
|
|
|
Hi David,
i am not sure, what exact approach you are trying to achieve, but
referring to your initial posting, you only want the access the domain
model objects, right?
Maybe this simple snippets helps to get the diagrameditpart and go from
there?
(this approach works only, once you want to access the wrappers of the
current diagram file, opened in the editor)
#######
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor();
if (part instanceof HmiDiagramEditor) {
HmiDiagramEditor editor = (HmiDiagramEditor) part;
DiagramEditPart dep = editor.getDiagramEditPart();
}
#######
Now you could upcast this DiagramEditPart to your application's root
EditPart and access the children via the appropriate getter-methods.
Or you could access specific GraphicalEditParts in your diagram via the
workbech-selection service as follows:
####
ISelection selection =
PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().getActiveEditor( ).getEditorSite().getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection)
selection;
Object obj = structuredSelection.getFirstElement();
if (obj instanceof GraphicalEditPart){
GraphicalEditPart ep = (GraphicalEditPart) obj;
}
}
To get the domain model object from the GraphicalEditPart you could use:
#######
GraphicalEditPart ep;
EObject domainModelEObject = ((View) ep.getModel()).getElement()
#######
If this is not, what your looking for, maybe you could provide a more
detailed description, of how you want to access the domain model and when.
HTH
Thomas
David Aylmer wrote:
> My extremely limited knowledge of GMF would suggest to me that when a user
> adds nodes and connections to the diagram, the plugin is instantiating the
> objects in the ecore model. I can't understand how it can be so difficult to
> get hold of these objects. I thought that was the whole point of building
> the graphical editor.
> Constructing the diagram and saving as a xml file or equivalent and then
> having to reload it to get the objects seems a crazy way of getting hold of
> the objects.
> David Aylmer
|
|
|
Powered by
FUDForum. Page generated in 0.15860 seconds