Home » Modeling » EMF » Loading resources associated with specific packages into generated EMF editor.
| | |
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 |
John T.E. Timm 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 #539664 is a reply to message #539498] |
Fri, 11 June 2010 18:19 |
John T.E. Timm 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 |
Ed Merks 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/
|
|
| | | | |
Goto Forum:
Current Time: Fri Apr 26 07:06:34 GMT 2024
Powered by FUDForum. Page generated in 0.03612 seconds
|