Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Processing all EObject from global action(Example code to process all EObjects from global action)
Processing all EObject from global action [message #647545] Thu, 06 January 2011 23:28 Go to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
I'm adding some global actions, and needed to figure out how to get at all the EObjects. So here is the code that I came up with, which works for my particular application. If you have some enhancements please feel encouraged to post.
Jay

EditingDomain editingDomain = ((IEditingDomainProvider)activeEditorPart).getEditingDomain( );
// get the root
Resource res = editingDomain.getResourceSet().getResources().get(0);
if (res instanceof XMIResourceImpl){
XMIResourceImpl xmi = (XMIResourceImpl) res;
TreeIterator<EObject> iter =xmi.getAllContents();
for (;iter.hasNext(); ) {
EObject ob = (EObject)iter.next();
}
}



Re: Processing all EObject from global action [message #647548 is a reply to message #647545] Fri, 07 January 2011 00:16 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Jay,

Comments below.

Jay Norwood wrote:
> I'm adding some global actions, and needed to figure out how to get at
> all the EObjects. So here is the code that I came up with, which
> works for my particular application. If you have some enhancements
> please feel encouraged to post.
> Jay
>
> EditingDomain editingDomain =
> ((IEditingDomainProvider)activeEditorPart).getEditingDomain( );
> // get the root
> Resource res = editingDomain.getResourceSet().getResources().get(0);
Don't you want to handle all resources? ResourceSet.getAllContents()
might be helpful; note that it yields resources and their contents...
> if (res instanceof XMIResourceImpl){
You're only interested in XMI resources?
> XMIResourceImpl xmi = (XMIResourceImpl) res;
> TreeIterator<EObject> iter =xmi.getAllContents();
> for (;iter.hasNext(); ) {
> EObject ob = (EObject)iter.next();
> }
> }
Note that any given resource might contain objects with references that
are unresolved proxies. EcoreUtil.resolveAll helps ensure that all
proxies are resolve.
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EMF Transaction] Problems with WorkspaceSynchronizer.getFile(Resource)
Next Topic:EMF [compare]
Goto Forum:
  


Current Time: Thu Apr 25 00:29:22 GMT 2024

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

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

Back to the top