Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to create exact type children without including subtypes.
How to create exact type children without including subtypes. [message #429246] Wed, 15 April 2009 10:19 Go to next message
Shahim Essaid is currently offline Shahim EssaidFriend
Messages: 3
Registered: July 2009
Junior Member
Hello,

Is there an option that would prevent adding subtypes of a reference type
from being added to the list of children?

I know that I can manually make changes in the collectNewChildDescriptors
method but I will have to do this in hundreds of places. Is there a way to
set the default code generation to only add children of the exact type and
I can then manually change the ones that need the subtypes. Even better,
is there some ecore/XML schema annotation that controls this?

Thank you,
Shahim
Re: How to create exact type children without including subtypes. [message #429248 is a reply to message #429246] Wed, 15 April 2009 10:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Shahim,

Comments below.

Shahim Essaid wrote:
> Hello,
>
> Is there an option that would prevent adding subtypes of a reference
> type from being added to the list of children?
No.
>
> I know that I can manually make changes in the
> collectNewChildDescriptors method but I will have to do this in
> hundreds of places. Is there a way to set the default code generation
> to only add children of the exact type and I can then manually change
> the ones that need the subtypes. Even better, is there some ecore/XML
> schema annotation that controls this?
Any class that's substitutable will be allowed as a choice.
>
> Thank you,
> Shahim
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to create exact type children without including subtypes. [message #429249 is a reply to message #429248] Wed, 15 April 2009 11:48 Go to previous messageGo to next message
Shahim Essaid is currently offline Shahim EssaidFriend
Messages: 3
Registered: July 2009
Junior Member
Ed,

Thank you for your response.

I am looking at the ItemProvider Jet template but I have no experience
working with them. What do I need to do/learn so that I can modify them to
accomplish what I need? Can you please give me some hints? I'd rather
spend few hours learn how to do this instead of spending the hours
commenting out the default generated code.

Which part of the template looks up the subclasses and how can I change it
so that it only adds the declared reference type as a child? (I am
pasting below the part of the template that appears relevant)

Thanks,
Shahim





<%if (genModel.isCreationCommands()) {%>
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s
describing the children
* that can be created under this object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
<%if (genModel.useClassOverrideAnnotation()) {%>
@Override
<%}%>
protected void
collectNewChildDescriptors(<%=genModel.getImportedName(genModel.useGenerics()
? "java.util.Collection<java.lang.Object>" : "java.util.Collection")%>
newChildDescriptors, Object object)
{
super.collectNewChildDescriptors(newChildDescriptors, object);
<%for (GenClass.ChildCreationData childCreationData :
genClass.getChildCreationData()) { GenFeature createFeature =
childCreationData.createFeature; GenFeature delegatedFeature =
childCreationData.delegatedFeature; GenClassifier createClassifier =
childCreationData.createClassifier;%>
<%if (createFeature.isFeatureMapType()) {%>
<%if (delegatedFeature.isReferenceType()) { GenClass createClass =
(GenClass)createClassifier;%>
<%@ include
file=" ItemProvider/newChildDescriptorsReferenceDelegatedFeature.ov erride.javajetinc "
fail="alternative"%>
<%@ start %>

newChildDescriptors.add
(createChildParameter
(<%=createFeature.getQualifiedFeatureAccessor()%>,

<%=genModel.getImportedName("org.eclipse.emf.ecore.util.FeatureMapUtil ")%>.createEntry
(<%=delegatedFeature.getQualifiedFeatureAccessor()%>,
<%if (createClass.isMapEntry()) { %>

< %=createClass.getGenPackage().getQualifiedEFactoryInstanceAc cessor()% >.create(<%=createClass.getQualifiedClassifierAccessor()%>))));
<%} else {%>

< %=createClass.getGenPackage().getQualifiedFactoryInstanceAcc essor()% >.create<%=createClass.getName()%>())));
<%}%>
<%@ include
file=" ItemProvider/newChildDescriptorsReferenceDelegatedFeature.in sert.javajetinc "
fail="silent"%>
<%@ end
%>< %//ItemProvider/newChildDescriptorsReferenceDelegatedFeature .override.javajetinc% >
<%} else { GenDataType createDataType =
(GenDataType)createClassifier;%>
<%@ include
file=" ItemProvider/newChildDescriptorsAttributeDelegatedFeature.ov erride.javajetinc "
fail="alternative"%>
<%@ start %>

newChildDescriptors.add
(createChildParameter
(<%=createFeature.getQualifiedFeatureAccessor()%>,

<%=genModel.getImportedName("org.eclipse.emf.ecore.util.FeatureMapUtil ")%>.createEntry
(<%=delegatedFeature.getQualifiedFeatureAccessor()%>,
<%if (delegatedFeature.isEnumBasedType()) {%>

< %=delegatedFeature.getTypeGenEnum().getStaticValue(delegated Feature.getEcoreFeature().getDefaultValueLiteral())% >)));
<%} else if (delegatedFeature.isStringBasedType()) {%>

<%=delegatedFeature.getCreateChildValueLiteral()%>)));<%=genModel.getNonNLS()% >
<%} else { String literal =
delegatedFeature.getCreateChildValueLiteral();%>

< %=createDataType.getGenPackage().getQualifiedEFactoryInstanc eAccessor()% >.createFromString(<%=createDataType.getQualifiedClassifierAccessor()% >,
<%=literal%>))));<%if (literal != null) {%><%=genModel.getNonNLS()%><%}
else {%> // TODO: ensure this is a valid literal value<%}%>
<%}%>
<%@ include
file=" ItemProvider/newChildDescriptorsAttributeDelegatedFeature.in sert.javajetinc "
fail="silent"%>
<%@ end
%>< %//ItemProvider/newChildDescriptorsAttributeDelegatedFeature .override.javajetinc% >
<%}%>
<%} else if (createFeature.isReferenceType()) { GenClass createClass
= (GenClass)createClassifier;%>
<%@ include
file=" ItemProvider/newChildDescriptorsReferenceFeature.override.ja vajetinc "
fail="alternative"%>
<%@ start %>

newChildDescriptors.add
(createChildParameter
(<%=createFeature.getQualifiedFeatureAccessor()%>,
<%if (createClass.isMapEntry()) { %>

< %=createClass.getGenPackage().getQualifiedEFactoryInstanceAc cessor()% >.create(<%=createClass.getQualifiedClassifierAccessor()%>)));
<%} else {%>

< %=createClass.getGenPackage().getQualifiedFactoryInstanceAcc essor()% >.create<%=createClass.getName()%>()));
<%}%>
<%@ include
file=" ItemProvider/newChildDescriptorsReferenceFeature.insert.java jetinc "
fail="silent"%>
<%@ end
%>< %//ItemProvider/newChildDescriptorsReferenceFeature.override .javajetinc
%>
<%} else { GenDataType createDataType =
(GenDataType)createClassifier;%>
<%@ include
file=" ItemProvider/newChildDescriptorsAttributeFeature.override.ja vajetinc "
fail="alternative"%>
<%@ start %>

newChildDescriptors.add
(createChildParameter
(<%=createFeature.getQualifiedFeatureAccessor()%>,
<%if (createFeature.isEnumBasedType()) {%>

< %=createFeature.getTypeGenEnum().getStaticValue(createFeatur e.getEcoreFeature().getDefaultValueLiteral())% >));
<%} else if (createFeature.isStringBasedType()) {%>

<%=createFeature.getCreateChildValueLiteral()%>));<%=genModel.getNonNLS()% >
<%} else { String literal =
createFeature.getCreateChildValueLiteral();%>

< %=createDataType.getGenPackage().getQualifiedEFactoryInstanc eAccessor()% >.createFromString(<%=createDataType.getQualifiedClassifierAccessor()% >,
<%=literal%>)));<%if (literal != null) {%><%=genModel.getNonNLS()%><%}
else {%> // TODO: ensure this is a valid literal value<%}%>
<%}%>
<%@ include
file=" ItemProvider/newChildDescriptorsAttributeFeature.insert.java jetinc "
fail="silent"%>
<%@ end
%>< %//ItemProvider/newChildDescriptorsAttributeFeature.override .javajetinc% >
<%}%>
<%}%>
}

Ed Merks wrote:

> Shahim,

> Comments below.

> Shahim Essaid wrote:
>> Hello,
>>
>> Is there an option that would prevent adding subtypes of a reference
>> type from being added to the list of children?
> No.
>>
>> I know that I can manually make changes in the
>> collectNewChildDescriptors method but I will have to do this in
>> hundreds of places. Is there a way to set the default code generation
>> to only add children of the exact type and I can then manually change
>> the ones that need the subtypes. Even better, is there some ecore/XML
>> schema annotation that controls this?
> Any class that's substitutable will be allowed as a choice.
>>
>> Thank you,
>> Shahim
>>
Re: How to create exact type children without including subtypes. [message #429257 is a reply to message #429249] Wed, 15 April 2009 15:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Shahim,

Comments below.

Shahim Essaid wrote:
> Ed,
>
> Thank you for your response.
> I am looking at the ItemProvider Jet template but I have no experience
> working with them. What do I need to do/learn so that I can modify
> them to accomplish what I need?
You've looked at the FAQ? You've uses the nice google newsgroup search
to find previous posts?
> Can you please give me some hints? I'd rather spend few hours learn
> how to do this instead of spending the hours commenting out the
> default generated code.
Yes, I can imagine...
> Which part of the template looks up the subclasses and how can I
> change it so that it only adds the declared reference type as a child?
It's complicated. I could spend quite a bit of time just trying to
explain it and I don't have that much time.
> (I am pasting below the part of the template that appears relevant)
Yep.
>
> Thanks,
> Shahim
>
>
>
>
>
> <%if (genModel.isCreationCommands()) {%>
> /**
> * This adds {@link
> org.eclipse.emf.edit.command.CommandParameter}s describing the children
> * that can be created under this object.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> <%if (genModel.useClassOverrideAnnotation()) {%>
> @Override
> <%}%>
> protected void
> collectNewChildDescriptors(<%=genModel.getImportedName(genModel.useGenerics()
> ? "java.util.Collection<java.lang.Object>" : "java.util.Collection")%>
> newChildDescriptors, Object object)
> {
> super.collectNewChildDescriptors(newChildDescriptors, object);
> <%for (GenClass.ChildCreationData childCreationData :
> genClass.getChildCreationData()) { GenFeature createFeature =
> childCreationData.createFeature; GenFeature delegatedFeature =
> childCreationData.delegatedFeature; GenClassifier createClassifier =
> childCreationData.createClassifier;%>
> <%if (createFeature.isFeatureMapType()) {%>
> <%if (delegatedFeature.isReferenceType()) { GenClass
> createClass = (GenClass)createClassifier;%>
> <%@ include
> file=" ItemProvider/newChildDescriptorsReferenceDelegatedFeature.ov erride.javajetinc "
> fail="alternative"%>
> <%@ start %>
>
> newChildDescriptors.add
> (createChildParameter
> (<%=createFeature.getQualifiedFeatureAccessor()%>,
>
> <%=genModel.getImportedName("org.eclipse.emf.ecore.util.FeatureMapUtil ")%>.createEntry
>
> (<%=delegatedFeature.getQualifiedFeatureAccessor()%>,
> <%if (createClass.isMapEntry()) { %>
>
> < %=createClass.getGenPackage().getQualifiedEFactoryInstanceAc cessor()% >.create(<%=createClass.getQualifiedClassifierAccessor()%>))));
>
> <%} else {%>
>
> < %=createClass.getGenPackage().getQualifiedFactoryInstanceAcc essor()% >.create<%=createClass.getName()%>())));
>
> <%}%>
> <%@ include
> file=" ItemProvider/newChildDescriptorsReferenceDelegatedFeature.in sert.javajetinc "
> fail="silent"%>
> <%@ end
> %>< %//ItemProvider/newChildDescriptorsReferenceDelegatedFeature .override.javajetinc% >
>
> <%} else { GenDataType createDataType =
> (GenDataType)createClassifier;%>
> <%@ include
> file=" ItemProvider/newChildDescriptorsAttributeDelegatedFeature.ov erride.javajetinc "
> fail="alternative"%>
> <%@ start %>
>
> newChildDescriptors.add
> (createChildParameter
> (<%=createFeature.getQualifiedFeatureAccessor()%>,
>
> <%=genModel.getImportedName("org.eclipse.emf.ecore.util.FeatureMapUtil ")%>.createEntry
>
> (<%=delegatedFeature.getQualifiedFeatureAccessor()%>,
> <%if (delegatedFeature.isEnumBasedType()) {%>
>
> < %=delegatedFeature.getTypeGenEnum().getStaticValue(delegated Feature.getEcoreFeature().getDefaultValueLiteral())% >)));
>
> <%} else if (delegatedFeature.isStringBasedType()) {%>
>
> <%=delegatedFeature.getCreateChildValueLiteral()%>)));<%=genModel.getNonNLS()% >
>
> <%} else { String literal =
> delegatedFeature.getCreateChildValueLiteral();%>
>
> < %=createDataType.getGenPackage().getQualifiedEFactoryInstanc eAccessor()% >.createFromString(<%=createDataType.getQualifiedClassifierAccessor()% >,
> <%=literal%>))));<%if (literal != null)
> {%><%=genModel.getNonNLS()%><%} else {%> // TODO: ensure this is a
> valid literal value<%}%>
> <%}%>
> <%@ include
> file=" ItemProvider/newChildDescriptorsAttributeDelegatedFeature.in sert.javajetinc "
> fail="silent"%>
> <%@ end
> %>< %//ItemProvider/newChildDescriptorsAttributeDelegatedFeature .override.javajetinc% >
>
> <%}%>
> <%} else if (createFeature.isReferenceType()) { GenClass
> createClass = (GenClass)createClassifier;%>
> <%@ include
> file=" ItemProvider/newChildDescriptorsReferenceFeature.override.ja vajetinc "
> fail="alternative"%>
> <%@ start %>
>
> newChildDescriptors.add
> (createChildParameter
> (<%=createFeature.getQualifiedFeatureAccessor()%>,
> <%if (createClass.isMapEntry()) { %>
>
> < %=createClass.getGenPackage().getQualifiedEFactoryInstanceAc cessor()% >.create(<%=createClass.getQualifiedClassifierAccessor()%>)));
>
> <%} else {%>
>
> < %=createClass.getGenPackage().getQualifiedFactoryInstanceAcc essor()% >.create<%=createClass.getName()%>()));
>
> <%}%>
> <%@ include
> file=" ItemProvider/newChildDescriptorsReferenceFeature.insert.java jetinc "
> fail="silent"%>
> <%@ end
> %>< %//ItemProvider/newChildDescriptorsReferenceFeature.override .javajetinc
> %>
> <%} else { GenDataType createDataType =
> (GenDataType)createClassifier;%>
> <%@ include
> file=" ItemProvider/newChildDescriptorsAttributeFeature.override.ja vajetinc "
> fail="alternative"%>
> <%@ start %>
>
> newChildDescriptors.add
> (createChildParameter
> (<%=createFeature.getQualifiedFeatureAccessor()%>,
> <%if (createFeature.isEnumBasedType()) {%>
>
> < %=createFeature.getTypeGenEnum().getStaticValue(createFeatur e.getEcoreFeature().getDefaultValueLiteral())% >));
>
> <%} else if (createFeature.isStringBasedType()) {%>
>
> <%=createFeature.getCreateChildValueLiteral()%>));<%=genModel.getNonNLS()% >
>
> <%} else { String literal =
> createFeature.getCreateChildValueLiteral();%>
>
> < %=createDataType.getGenPackage().getQualifiedEFactoryInstanc eAccessor()% >.createFromString(<%=createDataType.getQualifiedClassifierAccessor()% >,
> <%=literal%>)));<%if (literal != null) {%><%=genModel.getNonNLS()%><%}
> else {%> // TODO: ensure this is a valid literal value<%}%>
> <%}%>
> <%@ include
> file=" ItemProvider/newChildDescriptorsAttributeFeature.insert.java jetinc "
> fail="silent"%>
> <%@ end
> %>< %//ItemProvider/newChildDescriptorsAttributeFeature.override .javajetinc% >
>
> <%}%>
> <%}%>
> }
>
> Ed Merks wrote:
>
>> Shahim,
>
>> Comments below.
>
>> Shahim Essaid wrote:
>>> Hello,
>>>
>>> Is there an option that would prevent adding subtypes of a reference
>>> type from being added to the list of children?
>> No.
>>>
>>> I know that I can manually make changes in the
>>> collectNewChildDescriptors method but I will have to do this in
>>> hundreds of places. Is there a way to set the default code
>>> generation to only add children of the exact type and I can then
>>> manually change the ones that need the subtypes. Even better, is
>>> there some ecore/XML schema annotation that controls this?
>> Any class that's substitutable will be allowed as a choice.
>>>
>>> Thank you,
>>> Shahim
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to create exact type children without including subtypes. [message #429262 is a reply to message #429257] Wed, 15 April 2009 19:05 Go to previous message
Shahim Essaid is currently offline Shahim EssaidFriend
Messages: 3
Registered: July 2009
Junior Member
Ed,

It does appear complicated :-). I will just modify the generated code for
now until I have more experience with EMF. Thank you for your help.

Shahim
Previous Topic:How to determine model's metamodel?
Next Topic:Re: using tcp as rcp client and server protocol?
Goto Forum:
  


Current Time: Fri Apr 26 21:08:29 GMT 2024

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

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

Back to the top