Access objects displayed in editor [message #201380] |
Mon, 11 August 2008 10: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 #201555 is a reply to message #201446] |
Tue, 12 August 2008 09:48 |
Eclipse User |
|
|
|
Originally posted by: daylmer.opencloud.com
Thank you Alex,
I have got the required libraries set up for the objects I need but I am
having a little trouble with the URI. What should I be putting in there? I'm
assuming that should be a URI referring to the diagram I have made but I'm
unsure of how to access it.
Thank you,
David Aylmer
|
|
|
|
Re: Access objects displayed in editor [message #201568 is a reply to message #201562] |
Tue, 12 August 2008 10:27 |
Eclipse User |
|
|
|
Originally posted by: daylmer.opencloud.com
Thanks Alex,
I have tried using both of those methods and I always get a null Resource
object returned. Am I supposed to be passing in the location of the diagram
as an argument?
David Aylmer
|
|
|
|
Re: Access objects displayed in editor [message #201625 is a reply to message #201574] |
Tue, 12 August 2008 14:59 |
Eclipse User |
|
|
|
Originally posted by: daylmer.opencloud.com
Thanks Alex,
Could the problem be to do with the fact that there is no registered
factory? How would I go about registering my own factory?
I tried debugging the ResourceImpl class but the debugger doesn't seem to be
able to access the source code that it's debugging.
David Aylmer
|
|
|
|
Re: Access objects displayed in editor [message #201732 is a reply to message #201704] |
Wed, 13 August 2008 08:46 |
Eclipse User |
|
|
|
Originally posted by: daylmer.opencloud.com
Thanks Alex,
I found this example for loading resources:
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION, new
XMIResourceFactoryImpl());
LibraryPackage libraryPackage = LibraryPackage.eINSTANCE; //*
URI fileURI = URI.createFileURI(new
File("mylibrary.xmi").getAbsolutePath());
Resource resource = resourceSet.getResource(fileURI, true);
try
{
resource.save(System.out, Collections.EMPTY_MAP);
}
catch (IOException e) {}
* So my question is how can I do this line in my plugin when it has no
knowledge of the LibraryPackage class. (Or rather my version of that class)
The errors I am getting are to do with not being able to find the ecore
file.
David Aylmer
|
|
|
|
Re: Access objects displayed in editor [message #201756 is a reply to message #201748] |
Wed, 13 August 2008 09:08 |
Eclipse User |
|
|
|
Originally posted by: daylmer.opencloud.com
Thanks Alex
> First, ResourceSetImpl should be able to load resources even without
> explicitly specified "ExtensionToFactoryMap".
The tutorial says that is required for standalone applications.
> Do not see any usage of "LibraryPackage libraryPackage" in a code snippet
> above...
The tutorial says that calling .eINSTANCE is sufficient to register it in
the package registry "which the resource uses to obtain the appropriate
metadata and factory for the model it is loading."
David Aylmer
|
|
|
Re: Access objects displayed in editor [message #201770 is a reply to message #201756] |
Wed, 13 August 2008 09:18 |
Eclipse User |
|
|
|
Originally posted by: daylmer.opencloud.com
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
|
|
|
Re: Access objects displayed in editor [message #201788 is a reply to message #201770] |
Wed, 13 August 2008 10:50 |
Eclipse User |
|
|
|
Originally posted by: daylmer.opencloud.com
Well, I managed to grab the objects form the diagram as per the example but
I had to include some reference libraries including the classes which make
up the source code I wrote for the model. How do I now configure the plugin
so that when I run it, it will already have those libraries?
David Aylmer
|
|
|
Re: Access objects displayed in editor [message #201804 is a reply to message #201770] |
Wed, 13 August 2008 11:42 |
Thomas Beyer Messages: 47 Registered: July 2009 |
Member |
|
|
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.03434 seconds