Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Loading resources associated with specific packages into generated EMF editor.
Loading resources associated with specific packages into generated EMF editor. [message #539486] Thu, 10 June 2010 23:23 Go to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
Given an EPackage, I would like to load the resource associated with the EPackage into my EMF generated editor. I have tried:

editingDomain.loadResource(ePackage.getNsURI());

but to no avail. What other EMF magic must I perform to make this work?

I also forgot to mention that I do not want this to show up in the editor but would like it accessible in properties view etc.

Thanks,

JT

[Updated on: Fri, 11 June 2010 00:15]

Report message to a moderator

Re: Loading resources associated with specific packages into generated EMF editor. [message #539489 is a reply to message #539486] Fri, 11 June 2010 00:15 Go to previous messageGo to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
I also tried this:

editingDomain.getResourceSet().getPackageRegistry().put(ePackage.getNsURI(), ePackage);
Re: Loading resources associated with specific packages into generated EMF editor. [message #539494 is a reply to message #539486] Fri, 11 June 2010 01:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
John,

There's ePackage.eResource(), but it's not part of the editing domain.
What are you trying to accomplish?


John T. wrote:
> given an EPackage, I would like to load the resource associated with
> the EPackage into my EMF generated editor. I have tried:
>
> editingDomain.loadResource(ePackage.getNsURI()); but to no avail. What
> other EMF magic must I perform to make this work?
>
> Thanks,
>
> JT


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading resources associated with specific packages into generated EMF editor. [message #539496 is a reply to message #539494] Fri, 11 June 2010 02:22 Go to previous messageGo to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
I have a model that has an EReference typed to ecore:EClass and I want to query the EPackage registry, pull out EPackage instances that meet certain criteria and make them available to the editingDomain so that EClasses from this set of packages are available for selection in the properties view. I want the serialized instances of my model to reflect only the ns URI of the package that sourced an EClass. I basically want to programmatically do what the ExtendedLoadResourcesDialog does in the generated Ecore editor. I've stared at code in the appropriate classes EcoreActionBarContributor, LoadResourceDialog, ResourceDialog but when I integrate a similar approach in my generated Editor I get different results.

[Updated on: Fri, 11 June 2010 02:25]

Report message to a moderator

Re: Loading resources associated with specific packages into generated EMF editor. [message #539498 is a reply to message #539496] Fri, 11 June 2010 03:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
John,

You should have a look at how Ecore's item providers do this. I.e.,
EModelElementItemProvider.ItemPropertyDescriptorWithUniqueCh oiceOfValueLabels.getChoiceOfValues.
It relies on the fact that
EcoreActionBarContribute.ExtendedLoadResourceAction populates the
resource set's directly package registry. The bottom line is that you
can't make the resources of your generated packages be contained by your
resource set so you'll have to find a different way.


John T. wrote:
> I have a model that has an EReference typed to ecore:EClass and I want
> to query the EPackage registry, pull out EPackage instances that meet
> certain criteria and add make them available to the editingDomain so
> that EClasses from this set of packages are available for selection in
> the properties view. I want the serialized instances of my model to
> reflect only the ns URI of the package that sourced an EClass.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading resources associated with specific packages into generated EMF editor. [message #539664 is a reply to message #539498] Fri, 11 June 2010 18:19 Go to previous messageGo to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
My problem is:

How to load resources associated with "runtime" registered packages into my EMF generated editor such that:

1) the resource contents are made available for setting properties of my instance

2) serialized version of my instance only contains references to these "runtime" registered packages via package nsURI (as opposed to platform plugin URI or file URI)

Here is what (I think) I know after inspecting the EMF generated editor for the Ecore metamodel:

1. The EcoreActionBarContributor has a load resource action

2. When this is called an ExtendedLoadResourceDialog pops up that gives three options: "browse registered packages", "browse workspace", "browse filesystem"

3. When "browse registered packages" is selected, there are two primary paths of execution to populate the list: one when isDevelopmentTimeVersion == true and one when isDevelopmentTimeVersion == false. I care about the latter.

4. When isDevelopmentTimeVersion == false, the list is populated from EPackage.Registry.INSTANCE.keySet().toArray() (a.k.a. a list of namespace URIs for registered EPackages).

5. The selection from this list is converteed to a list of space-separated values in the URI text field.

6. When OK is pressed on the ExtendedLoadResource dialog, ResourceDialog parses the URI text field back into a list of URIs. Then processResources from LoadDialog is used to iterate over the list calling:

domain.getResourceSet().getResource(uri, true)


for each URI the result (of the above statement) is passed as a resource to processResource overriden in ExtendedLoadResourceDialog which gets all of the packages from the resource and adds them to the package registry of the editing domain's resource set:

for (EPackage ePackage : getAllPackages(resource)) {
    domain.getResourceSet().getPackageRegistry().put(ePackage.getNsURI(), ePackage);
}


7. A pop-up comes up stating:
"Runtime packages are not displayed in the editor..." and that "...package contents will be available for setting properties..."

So, it would seem that in my EMF generated editor, I could replicate this same behavior. So given a namespace URI to my runtime package (that I know has been registered in EPackage.Registry - dyanmically via a "generated_package" extension point contribution) I tried:

// test
String uri = "http://www.example.org/MyModel";
Resource resource = editingDomain.getResourceSet().getResource(URI.createURI(uri), true);
for (EPackage ePackage : getAllPackages(resource)) {
    editingDomain.getResourceSet().getPackageRegistry().put(ePackage.getNsURI(), ePackage);
}


This essentially simulates the behavior of making a choice using the ExtendedLoadResourceDialog and BrowseRegsiteredPackagesDialog with isDevelopmentTimeVersion == false. However, what I find is that unlike the Ecore eidtor, the contents of the resource is not available for setting properties.

However, if I instead use the platform plugin URI:

platform:/plugin/org.example.mymodel/model/mymodel.ecore

Then the resource *is* loaded into the editor, displayed in the editor and its contents are available for setting properties. By using the platform plugin URI, I am essentially following the other path of execution (mentioned in step 3 above) where isDevelopmentTimeVersion == true.

So I can programmatically replicate the behavior one way, but not the other. Any ideas why this would be the case?

Thanks,

JT

[Updated on: Fri, 11 June 2010 19:12]

Report message to a moderator

Re: Loading resources associated with specific packages into generated EMF editor. [message #539672 is a reply to message #539664] Fri, 11 June 2010 19:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
John,

Comments below.


John T. wrote:
> Here is what (I think) I know after inspecting the EMF generated
> editor for the Ecore metamodel:
>
> 1. The EcoreActionBarContributor has a load resource action
Yes, an extended one for access various forms of packages.
>
> 2. When this is called an ExtendedLoadResourceDialog pops up that
> gives three options: "browse registered packages", "browse workspace",
> "browse filesystem"
>
> 3. When "browse registered packages" is selected, there are two
> primary paths of execution to populate the list: one when
> isDevelopmentTimeVersion == true and one when isDevelopmentTimeVersion
> == false. I care about the latter.
Yes.
>
> 4. When isDevelopmentTimeVersion == false, the list is populated from
> EPackage.Registry.INSTANCE.keySet().toArray() (a.k.a. a list of
> namespace URIs for registered EPackages).
Yes.
>
> 5. The selection from this list is converteed to a list of
> space-separated values in the URI text field.
>
> 6. When OK is pressed on the ExtendedLoadResource dialog,
> ResourceDialog parses the URI text field back into a list of URIs.
> Then processResources from LoadDialog is used to iterate over the list
> calling:
>
>
> domain.getResourceSet().getResource(uri, true)
>
>
> for each URI which passes the result as a resource to processResource
> overriden in ExtendedLoadResourceDialog which gets all of the packages
> from the resource and adds them to the package registry of the editing
> domain's resource set:
>
>
> for (EPackage ePackage : getAllPackages(resource)) {
>
> domain.getResourceSet().getPackageRegistry().put(ePackage.ge tNsURI(),
> ePackage);
> }
Yes.
>
>
> 7. A pop-up comes up stating:
> "Runtime packages are not displayed in the editor..." and that
> "...package contents will be available for setting properties..."
Yes, because in all other cases, the resource will actually be loaded
into the resource set so you'll be able to see the results of what you
did. In this case, there is no visible feedback.
>
> So, it would seem that in my EMF generated editor, I could replicate
> this same behavior. So given a namespace URI to my runtime package
> (that I know has been registered in EPackage.Registry, I tried:
>
>
> // test
> String uri = "http://www.example.org/MyModel";
> Resource resource =
> editingDomain.getResourceSet().getResource(URI.createURI(nsU RI), true);
> for (EPackage ePackage : getAllPackages(resource)) {
>
> editingDomain.getResourceSet().getPackageRegistry().put(ePac kage.getNsURI(),
> ePackage);
> }
>
>
> This essentially simulates the behavior of making a choice using the
> ExtendedLoadResourceDialog and BrowseRegsiteredPackagesDialog with
> isDevelopmentTimeVersion == false. However, what I find is that,
> unlike the Ecore eidtor, the contents of the package are not available
> for setting properties.
You've said nothing to indicate you've looked at how getChoicesOfValues
is specialized to consider the package registry's contents.
>
> However, if I instead use the platform plugin URI:
>
> platform:/plugin/org.example.mymodel/model/mymodel.ecore
>
> Then the resource *is* loaded into the editor, displayed in the editor
> and its contents are available for setting properties. By using the
> platform plugin API, I am essentially following the other path of
> execution where isDevelopmentTimeVersion == true.
Yes.
>
> So I can programmatically replicate the behaviror one way, but not the
> other. Any ideas why this would be the case?
Don't overlook the first part of my comment about having a look at
EModelElementItemProvider.ItemPropertyDescriptorWithUniqueCh oiceOfValueLabels.getChoiceOfValues.

>
> Thanks,
>
> JT


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading resources associated with specific packages into generated EMF editor. [message #539680 is a reply to message #539672] Fri, 11 June 2010 20:18 Go to previous messageGo to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
As per the EModelElementItemProvider.ItemPropertyDescriptorWithUniqueCh oiceOfValueLabels.getChoiceOfValues() method:

            Registry packageRegistry = resourceSet.getPackageRegistry();
            for (String nsURI : packageRegistry.keySet())
            {
              collectReachableObjectsOfType(visited, eObjects, packageRegistry.getEPackage(nsURI), feature.getEType());
            }


It appears to be getting packages from the resource set's package registry. In the EMF generated editor for the Ecore metamodel, packages are added to the local EPackage.Registry on the resource set (in ExtendedLoadResourceDialog). So why wouldn't my code that adds packages to this same registry work? What subtlety am I missing that makes the EMF generated editor for the Ecore metamodel different from my EMF generated editor in this regard.

I tried a quick experiment:

	public InstanceActionBarContributor() {
		super(ADDITIONS_LAST_STYLE);
//		loadResourceAction = new LoadResourceAction();
		loadResourceAction = new EcoreActionBarContributor.ExtendedLoadResourceAction();
		validateAction = new ValidateAction();
		controlAction = new ControlAction();
	}


Sure enough, the dialog will not load my packages either when runtime version is selected... Not that I undrestand why quite yet. Smile

Thanks,

JT

[Updated on: Fri, 11 June 2010 20:37]

Report message to a moderator

Re: Loading resources associated with specific packages into generated EMF editor. [message #539687 is a reply to message #539680] Fri, 11 June 2010 20:51 Go to previous messageGo to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
Alright, I see what is going on now. Adding to resource set registry is only part of the solution. I also need to extend getChoiceOfValues in my ItemProvider as you did for the Ecore editor. Thanks for leading me in the right direction!

JT
Re: Loading resources associated with specific packages into generated EMF editor. [message #539704 is a reply to message #539680] Fri, 11 June 2010 23:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
John,

Comments below.


John T. wrote:
> As per the
> EModelElementItemProvider.ItemPropertyDescriptorWithUniqueCh
> oiceOfValueLabels.getChoiceOfValues() method:
>
>
> Registry packageRegistry = resourceSet.getPackageRegistry();
> for (String nsURI : packageRegistry.keySet())
> {
> collectReachableObjectsOfType(visited, eObjects,
> packageRegistry.getEPackage(nsURI), feature.getEType());
> }
>
>
> It appears to be getting packages from the resource set's package
> registry. In the EMF generated editor for the Ecore metamodel,
> packages are added to the local EPackage.Registry on the resource set
> (in ExtendedLoadResourceDialog). So why wouldn't my code that adds
> packages to this same registry work?
Did you add code like this for your property descriptor? The code above
is specific for Ecore's own property descriptors.
> What subtlety am I missing that makes the EMF generated editor for the
> Ecore metamodel different from my EMF generated editor in this regard.
The fact that it's using this specialized property descriptor, not the
general one.
>
>
> Thanks,
>
> JT


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading resources associated with specific packages into generated EMF editor. [message #539705 is a reply to message #539687] Fri, 11 June 2010 23:01 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
John,

I should read all the notes before answering any of them. :-P

John T. wrote:
> Alright, I see what is going on now. Adding to resource set registry
> is only part of the solution. I also need to extend getChoiceOfValues
> in my ItemProvider as you did for the Ecore editor. Thanks for leading
> me in the right direction!
>
> JT


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:remembering Selections between runs.
Next Topic:CDO DBStore with existing Hibernate mapping
Goto Forum:
  


Current Time: Fri Apr 26 07:06:34 GMT 2024

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

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

Back to the top