Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » how to get AdapterFactory for another package
how to get AdapterFactory for another package [message #645344] Thu, 16 December 2010 17:05 Go to next message
Swavek  is currently offline Swavek Friend
Messages: 20
Registered: March 2010
Junior Member
I have a generated GMF editor with domain and notational models. The objects in the domain model are called nodes and were generated from Network.xsd. The nodes have configuration information stored in another model (in separate XML file). I generated both the model & edit code for the configuration information from the separate schema file (Config.xsd) and directed them into original GMF model and edit projects. This separate schema file references the base abstract configuration object defined in the original schema file. NetworkObjectConfig is an abstract base and DefaultProcessingNodeConfig is derived from NetworkObjectConfig.

When I click on the node in a diagram I display the node configuration information in tabbed properties view. I can get to the properties that are defined in the base but when I try to get an attribute defined in DefaultProcessingNodeConfig I run into trouble.

To get the base attributes I try to get the IItemPropertyDescriptor for the given property. I do this as follows:

String propertyName = getPropertyName();
AdapterFactory adapterFactory = NetworkDiagramEditorPlugin.getInstance().getItemProvidersAda pterFactory();
Adapter adapter = adapterFactory.adapt(fConfigObject, IItemPropertySource.class);
if (adapter != null) {
IItemPropertySource ips = (IItemPropertySource)adapter;
List<IItemPropertyDescriptor> descriptors = ips.getPropertyDescriptors(config);
for (IItemPropertyDescriptor descriptor : descriptors) {
EStructuralFeature feature = (EStructuralFeature) descriptor.getFeature(fConfigObject);
if (feature.getName().equals(propertyName)) {
fDescriptor = descriptor;
break;
}
}
}

When I don't find the descriptor for this property I would like to search for the descriptor returned from the adapter factory created from the separate config schema file.

This adapter factory (NodeItemProviderAdapterFactory) is getting loaded when I create an object of type EmfAttribute via a CreateChildCommand. I would like to get this factory so I can create/get a descriptor for the EmfAttrbute object but I can't figure out how to do this.

Since the config information is stored in a separate file I tried getting to it via Resource or ResourceSet by requesting a list of adapter factories but none of those approaches work (returned list is empty). I noticed that this factory is a CompoundFactory that is owned by the EditingDomain but this domain is not reachable via TransactionUtil.getEditingDomain or any other means t hat I could think of.

The factory is loaded on demand and there is no code generated to access it directly. It is stored within an inner class and I can't get to it.

How do I get this factory?



Re: how to get AdapterFactory for another package [message #645355 is a reply to message #645344] Thu, 16 December 2010 17:15 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020904030907030309080506
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Swavek,

Comments below.

Swavek wrote:
> I have a generated GMF editor with domain and notational models. The
> objects in the domain model are called nodes and were generated from
> Network.xsd. The nodes have configuration information stored in
> another model (in separate XML file). I generated both the model &
> edit code for the configuration information from the separate schema
> file (Config.xsd) and directed them into original GMF model and edit
> projects. This separate schema file references the base abstract
> configuration object defined in the original schema file.
> NetworkObjectConfig is an abstract base and
> DefaultProcessingNodeConfig is derived from NetworkObjectConfig.
>
> When I click on the node in a diagram I display the node configuration
> information in tabbed properties view. I can get to the properties
> that are defined in the base but when I try to get an attribute
> defined in DefaultProcessingNodeConfig I run into trouble.
>
> To get the base attributes I try to get the IItemPropertyDescriptor
> for the given property. I do this as follows:
>
> String propertyName = getPropertyName();
> AdapterFactory adapterFactory =
> NetworkDiagramEditorPlugin.getInstance().getItemProvidersAda
> pterFactory();
I don't expect such a thing to be a singleton. Sounds likely to be a
source of leaks.
> Adapter adapter =
> adapterFactory.adapt(fConfigObject, IItemPropertySource.class);
Normally one wraps things with an AdapterFactoryContentProvider...
> if (adapter != null) {
> IItemPropertySource ips =
> (IItemPropertySource)adapter;
> List<IItemPropertyDescriptor> descriptors
> = ips.getPropertyDescriptors(config);
> for (IItemPropertyDescriptor descriptor :
> descriptors) {
> EStructuralFeature feature =
> (EStructuralFeature) descriptor.getFeature(fConfigObject);
> if
> (feature.getName().equals(propertyName)) {
> fDescriptor = descriptor;
> break;
> }
> }
> }
>
> When I don't find the descriptor for this property I would like to
> search for the descriptor returned from the adapter factory created
> from the separate config schema file.
Normally one uses something like

adapterFactory = new
ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Reg istry.INSTANCE);

In the editor and it finds registered item provider adapter factories as
needed.
>
> This adapter factory (NodeItemProviderAdapterFactory) is getting
> loaded when I create an object of type EmfAttribute via a
> CreateChildCommand. I would like to get this factory so I can
> create/get a descriptor for the EmfAttrbute object but I can't figure
> out how to do this.
> Since the config information is stored in a separate file I tried
> getting to it via Resource or ResourceSet by requesting a list of
> adapter factories but none of those approaches work (returned list is
> empty). I noticed that this factory is a CompoundFactory that is
> owned by the EditingDomain but this domain is not reachable via
> TransactionUtil.getEditingDomain or any other means t hat I could
> think of.
I suppose you could cast to AdapterFactoryEditingDomain to ask for it.
>
> The factory is loaded on demand and there is no code generated to
> access it directly. It is stored within an inner class and I can't
> get to it.
>
> How do I get this factory?
>
>
>
>

--------------020904030907030309080506
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Swavek,<br>
<br>
Comments below.<br>
<br>
Swavek wrote:
<blockquote cite="mid:iedgk0$c7k$1@news.eclipse.org" type="cite">I have
a generated GMF editor with domain and notational models.  The objects
in the domain model are called nodes and were generated from
Network.xsd.  The nodes have configuration information stored in
another model (in separate XML file).  I generated both the model &amp;
edit code for the configuration information from the separate schema
file (Config.xsd) and directed them into original GMF model and edit
projects.  This separate schema file references the base abstract
configuration object defined in the original schema file. 
NetworkObjectConfig is an abstract base and DefaultProcessingNodeConfig
is derived from NetworkObjectConfig.
<br>
<br>
When I click on the node in a diagram I display the node configuration
information in tabbed properties view.  I can get to the properties
that are defined in the base but when I try to get an attribute defined
in DefaultProcessingNodeConfig I run into trouble.
<br>
<br>
To get the base attributes I try to get the IItemPropertyDescriptor for
the given property.  I do this as follows:
<br>
<br>
                        String propertyName = getPropertyName();
<br>
                        AdapterFactory adapterFactory = 
NetworkDiagramEditorPlugin.getInstance().getItemProvidersAda
pterFactory();
<br>
</blockquote>
I don't expect such a thing to be a singleton.  Sounds likely to be a
source of leaks.<br>
<blockquote cite="mid:iedgk0$c7k$1@news.eclipse.org" type="cite">                       
Adapter adapter = adapterFactory.adapt(fConfigObject,
IItemPropertySource.class);
<br>
</blockquote>
Normally one wraps things with an AdapterFactoryContentProvider...<br>
<blockquote cite="mid:iedgk0$c7k$1@news.eclipse.org" type="cite">                       
if (adapter != null) {
<br>
                            IItemPropertySource ips =
(IItemPropertySource)adapter;
<br>
                            List&lt;IItemPropertyDescriptor&gt;
descriptors = ips.getPropertyDescriptors(config);
<br>
                            for (IItemPropertyDescriptor descriptor :
descriptors) {
<br>
                                 EStructuralFeature feature =
(EStructuralFeature) descriptor.getFeature(fConfigObject);
<br>
                                 if
(feature.getName().equals(propertyName)) {
<br>
                                     fDescriptor = descriptor;
<br>
                                     break;
<br>
                                 }
<br>
                            }
<br>
                        }
<br>
<br>
When I don't find the descriptor for this property I would like to
search for the descriptor returned from the adapter factory created
from the separate config schema file.
<br>
</blockquote>
Normally one uses something like     <br>
<blockquote>adapterFactory = new
ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Reg istry.INSTANCE); <br>
</blockquote>
In the editor and it finds registered item provider adapter factories
as needed.<br>
<blockquote cite="mid:iedgk0$c7k$1@news.eclipse.org" type="cite"><br>
This adapter factory (NodeItemProviderAdapterFactory) is getting loaded
when I create an object of type EmfAttribute via a CreateChildCommand. 
I would like to get this factory so I can create/get a descriptor for
the EmfAttrbute object but I can't figure out how to do this.  <br>
Since the config information is stored in a separate file I tried
getting to it via Resource or ResourceSet by requesting a list of
adapter factories but none of those approaches work (returned list is
empty).  I noticed that this factory is a CompoundFactory that is owned
by the EditingDomain but this domain is not reachable via
TransactionUtil.getEditingDomain or any other means t hat I could think
of.
<br>
</blockquote>
I suppose you could cast to AdapterFactoryEditingDomain to ask for it.<br>
<blockquote cite="mid:iedgk0$c7k$1@news.eclipse.org" type="cite"><br>
The factory is loaded on demand and there is no code generated to
access it directly.  It is stored within an inner class and I can't get
to it.
<br>
<br>
How do I get this factory?
<br>
<br>
<br>
<br>
<br>
</blockquote>
</body>
</html>

--------------020904030907030309080506--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Race condition between commit() and resolveConflicts()?
Next Topic:ItemProvider extension, how to add a type?
Goto Forum:
  


Current Time: Sat Apr 27 01:40:03 GMT 2024

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

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

Back to the top