Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Re: set return type of Operation
Re: set return type of Operation [message #69038] Wed, 25 October 2006 07:07 Go to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Martin,

I'm not sure. In the Sample Ecore Editor there is an action to "Load
Resource..." and once you load the resource containing the things you
want to reference, those entries will appear as choices in the
properties view. GMF's graphical editor would need something like that
as well. Probably if you use the Ecore editor to add a reference to the
other model, once you have such a reference, the graphical editor will
give you choices from that other model as well...


Martin Jacob wrote:

> Hi,
>
> how can I set the return type of a operation with the graphical
> editor? The properties view provid just the classes from emf and my
> own classes but i want to return a other instance.
>
> any idea how to do?
>
> Thanks,
> Martin
>
Re: set return type of Operation [message #69100 is a reply to message #69038] Wed, 25 October 2006 07:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gabmecu.fiv.upv.es

I'm not sure if it is the same case, but I had a similar problem. I had
to show in a combo box all the types belonging to the DataType Class.
Normally the user can load as many resources as he may want. To access
to all the resources added by the user I used this code:

// A hashMap for associating the name of the type with its class
HashMap hashMap = new HashMap();

// The current editing domain of the editor (Change XXXX with the name
of your editor)
EditingDomain editingDomain = ( (XXXXDiagramEditor) getPart()
).getEditingDomain();

ArrayList dtList = new ArrayList(); // A list for the DataType names

// List of the loaded resources
EList rList = editingDomain.getResourceSet().getResources();

for (Iterator irList = rList.iterator(); irList.hasNext(); )
{
// We only need the StructureModel resources
XMIResourceImpl rImpl = (XMIResourceImpl) irList.next();
if (rImpl.getContents().get(0) instanceof StructureModelImpl)
{
StructureModelImpl smi = (StructureModelImpl) rImpl.getContents().get(0);

// We need the list of the DataTypes
EList smiList = smi.getDataType();
for(Iterator k = smiList.iterator(); k.hasNext(); )
{
Object obj = k.next();
if (obj instanceof DataTypeImpl)
{
DataTypeImpl dt = (DataTypeImpl) obj;
dtList.add(dt.getName());
// I'll use the hashMap to associate the Name of the Type with its class
hashMap.put(dt.getName(), dt);
}
}
}
}

As you may see, from all the resources loaded by the user, I only want
those that are StrutureModel intances. And inside the model, I'm only
interested in the DataTypes.

I hope this helps.

Gabriel Merin

Ed Merks wrote:
> Martin,
>
> I'm not sure. In the Sample Ecore Editor there is an action to "Load
> Resource..." and once you load the resource containing the things you
> want to reference, those entries will appear as choices in the
> properties view. GMF's graphical editor would need something like that
> as well. Probably if you use the Ecore editor to add a reference to the
> other model, once you have such a reference, the graphical editor will
> give you choices from that other model as well...
>
>
> Martin Jacob wrote:
>
>> Hi,
>>
>> how can I set the return type of a operation with the graphical
>> editor? The properties view provid just the classes from emf and my
>> own classes but i want to return a other instance.
>>
>> any idea how to do?
>>
>> Thanks,
>> Martin
>>
Re: set return type of Operation [message #69121 is a reply to message #69100] Wed, 25 October 2006 07:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Gabriel,

I would suggest avoiding whenever possible, the use of XyzImpl,
particularly model implementation classes like StructureModelImpl and
DataTypeImpl. I would have expected you to cast to Resource,
StructureModel, and DataType, not to particular implementations of
those. Since models support multiple inheritance but Java classes
don't, it may well be the case that you could have a StructureModel
instance that's not implemented by StructureModelImpl but rather by a
class that does not even extend the StructureModelImpl class.


Gabriel Merin Cubero wrote:

> I'm not sure if it is the same case, but I had a similar problem. I
> had to show in a combo box all the types belonging to the DataType
> Class. Normally the user can load as many resources as he may want. To
> access to all the resources added by the user I used this code:
>
> // A hashMap for associating the name of the type with its class
> HashMap hashMap = new HashMap();
>
> // The current editing domain of the editor (Change XXXX with the name
> of your editor)
> EditingDomain editingDomain = ( (XXXXDiagramEditor) getPart()
> ).getEditingDomain();
>
> ArrayList dtList = new ArrayList(); // A list for the DataType names
>
> // List of the loaded resources
> EList rList = editingDomain.getResourceSet().getResources();
>
> for (Iterator irList = rList.iterator(); irList.hasNext(); )
> {
> // We only need the StructureModel resources
> XMIResourceImpl rImpl = (XMIResourceImpl) irList.next();
> if (rImpl.getContents().get(0) instanceof StructureModelImpl)
> {
> StructureModelImpl smi = (StructureModelImpl)
> rImpl.getContents().get(0);
>
> // We need the list of the DataTypes
> EList smiList = smi.getDataType();
> for(Iterator k = smiList.iterator(); k.hasNext(); )
> {
> Object obj = k.next();
> if (obj instanceof DataTypeImpl)
> {
> DataTypeImpl dt = (DataTypeImpl) obj;
> dtList.add(dt.getName());
> // I'll use the hashMap to associate the Name of the
> Type with its class
> hashMap.put(dt.getName(), dt);
> }
> }
> }
> }
>
> As you may see, from all the resources loaded by the user, I only want
> those that are StrutureModel intances. And inside the model, I'm only
> interested in the DataTypes.
>
> I hope this helps.
>
> Gabriel Merin
>
> Ed Merks wrote:
>
>> Martin,
>>
>> I'm not sure. In the Sample Ecore Editor there is an action to "Load
>> Resource..." and once you load the resource containing the things you
>> want to reference, those entries will appear as choices in the
>> properties view. GMF's graphical editor would need something like
>> that as well. Probably if you use the Ecore editor to add a
>> reference to the other model, once you have such a reference, the
>> graphical editor will give you choices from that other model as well...
>>
>>
>> Martin Jacob wrote:
>>
>>> Hi,
>>>
>>> how can I set the return type of a operation with the graphical
>>> editor? The properties view provid just the classes from emf and my
>>> own classes but i want to return a other instance.
>>>
>>> any idea how to do?
>>>
>>> Thanks,
>>> Martin
>>>
Re: set return type of Operation [message #69142 is a reply to message #69038] Wed, 25 October 2006 07:53 Go to previous messageGo to next message
Eclipse UserFriend
Ed,

i try as u suggested and it works at the GMF's graphical editor. Now i
have the problem at genmodel file.

the ecore file:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="prog"
nsURI="http://opn.dd.bahntechnik.de">
<eClassifiers xsi:type="ecore:EClass" name="OPNSimulationProgram">
<eOperations name="test" eType="ecore:EClass
scc.prog.ecore#//AbstractSimulationProgram"/>
</eClassifiers>
</ecore:EPackage>

the genmodel file:
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
modelDirectory="/de.bahntechnik.dd.opn/src"
modelPluginID="de.bahntechnik.dd.opn" modelName="Opn"
importerID="org.eclipse.emf.importer.ecore">
<foreignModel>opn.prog.ecore</foreignModel>
<genPackages prefix="Prog" basePackage="de.bahntechnik.dd.opn"
disposableProviderFactory="true"
ecorePackage="opn.prog.ecore#/">
<genClasses ecoreClass="opn.prog.ecore#//OPNSimulationProgram"/>
</genPackages>
</genmodel:GenModel>

a error message says:

"The package '...../scc.prog.ecore#/' is needed but isn't accessible from
the Generator model"

May I did some thing wrong. Do u has any idea to solve the problem in
genmodel?

thanks,
Martin

Ed Merks wrote:

> Martin,

> I'm not sure. In the Sample Ecore Editor there is an action to "Load
> Resource..." and once you load the resource containing the things you
> want to reference, those entries will appear as choices in the
> properties view. GMF's graphical editor would need something like that
> as well. Probably if you use the Ecore editor to add a reference to the
> other model, once you have such a reference, the graphical editor will
> give you choices from that other model as well...


> Martin Jacob wrote:

>> Hi,
>>
>> how can I set the return type of a operation with the graphical
>> editor? The properties view provid just the classes from emf and my
>> own classes but i want to return a other instance.
>>
>> any idea how to do?
>>
>> Thanks,
>> Martin
>>
Re: set return type of Operation [message #69182 is a reply to message #69142] Wed, 25 October 2006 08:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Martin,

You'll need to "Reload..." the .genmodel (from the popup on the
..genmodel or from the Generator menu item on the menu bar when the
..genmodel is open) so that you an add a usedGenPackage for the
additional EPackage your model now depends on.


Martin Jacob wrote:

> Ed,
>
> i try as u suggested and it works at the GMF's graphical editor. Now i
> have the problem at genmodel file.
>
> the ecore file:
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="prog"
> nsURI="http://opn.dd.bahntechnik.de">
> <eClassifiers xsi:type="ecore:EClass" name="OPNSimulationProgram">
> <eOperations name="test" eType="ecore:EClass
> scc.prog.ecore#//AbstractSimulationProgram"/>
> </eClassifiers>
> </ecore:EPackage>
>
> the genmodel file:
> <?xml version="1.0" encoding="UTF-8"?>
> <genmodel:GenModel xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
> modelDirectory="/de.bahntechnik.dd.opn/src"
> modelPluginID="de.bahntechnik.dd.opn" modelName="Opn"
> importerID="org.eclipse.emf.importer.ecore">
> <foreignModel>opn.prog.ecore</foreignModel>
> <genPackages prefix="Prog" basePackage="de.bahntechnik.dd.opn"
> disposableProviderFactory="true"
> ecorePackage="opn.prog.ecore#/">
> <genClasses ecoreClass="opn.prog.ecore#//OPNSimulationProgram"/>
> </genPackages>
> </genmodel:GenModel>
>
> a error message says:
>
> "The package '...../scc.prog.ecore#/' is needed but isn't accessible
> from the Generator model"
>
> May I did some thing wrong. Do u has any idea to solve the problem in
> genmodel?
>
> thanks,
> Martin
>
> Ed Merks wrote:
>
>> Martin,
>
>
>> I'm not sure. In the Sample Ecore Editor there is an action to "Load
>> Resource..." and once you load the resource containing the things you
>> want to reference, those entries will appear as choices in the
>> properties view. GMF's graphical editor would need something like
>> that as well. Probably if you use the Ecore editor to add a
>> reference to the other model, once you have such a reference, the
>> graphical editor will give you choices from that other model as well...
>
>
>
>> Martin Jacob wrote:
>
>
>>> Hi,
>>>
>>> how can I set the return type of a operation with the graphical
>>> editor? The properties view provid just the classes from emf and my
>>> own classes but i want to return a other instance.
>>>
>>> any idea how to do?
>>>
>>> Thanks,
>>> Martin
>>>
>
Re: set return type of Operation [message #69255 is a reply to message #69038] Wed, 25 October 2006 09:11 Go to previous messageGo to next message
Eclipse UserFriend
Hello Ed,

> I'm not sure. In the Sample Ecore Editor there is an action to "Load
> Resource..." and once you load the resource containing the things you
Generated GMF editors contains this action as well. It is available in the
popup menu for a diagram.

-----------------
Alex Shatalin
Re: set return type of Operation [message #69275 is a reply to message #69121] Wed, 25 October 2006 09:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gabmecu.fiv.upv.es

Yes, you are very right. Thanks for the advice and sorry posting a not
very correct code.

Gabriel Merin

Ed Merks wrote:
> Gabriel,
>
> I would suggest avoiding whenever possible, the use of XyzImpl,
> particularly model implementation classes like StructureModelImpl and
> DataTypeImpl. I would have expected you to cast to Resource,
> StructureModel, and DataType, not to particular implementations of
> those. Since models support multiple inheritance but Java classes
> don't, it may well be the case that you could have a StructureModel
> instance that's not implemented by StructureModelImpl but rather by a
> class that does not even extend the StructureModelImpl class.
>
>
> Gabriel Merin Cubero wrote:
>
>> I'm not sure if it is the same case, but I had a similar problem. I
>> had to show in a combo box all the types belonging to the DataType
>> Class. Normally the user can load as many resources as he may want. To
>> access to all the resources added by the user I used this code:
>>
>> // A hashMap for associating the name of the type with its class
>> HashMap hashMap = new HashMap();
>>
>> // The current editing domain of the editor (Change XXXX with the name
>> of your editor)
>> EditingDomain editingDomain = ( (XXXXDiagramEditor) getPart()
>> ).getEditingDomain();
>>
>> ArrayList dtList = new ArrayList(); // A list for the DataType names
>>
>> // List of the loaded resources
>> EList rList = editingDomain.getResourceSet().getResources();
>>
>> for (Iterator irList = rList.iterator(); irList.hasNext(); )
>> {
>> // We only need the StructureModel resources
>> XMIResourceImpl rImpl = (XMIResourceImpl) irList.next();
>> if (rImpl.getContents().get(0) instanceof StructureModelImpl)
>> {
>> StructureModelImpl smi = (StructureModelImpl)
>> rImpl.getContents().get(0);
>>
>> // We need the list of the DataTypes
>> EList smiList = smi.getDataType();
>> for(Iterator k = smiList.iterator(); k.hasNext(); )
>> {
>> Object obj = k.next();
>> if (obj instanceof DataTypeImpl)
>> {
>> DataTypeImpl dt = (DataTypeImpl) obj;
>> dtList.add(dt.getName());
>> // I'll use the hashMap to associate the Name of the
>> Type with its class
>> hashMap.put(dt.getName(), dt);
>> }
>> }
>> }
>> }
>>
>> As you may see, from all the resources loaded by the user, I only want
>> those that are StrutureModel intances. And inside the model, I'm only
>> interested in the DataTypes.
>>
>> I hope this helps.
>>
>> Gabriel Merin
>>
>> Ed Merks wrote:
>>
>>> Martin,
>>>
>>> I'm not sure. In the Sample Ecore Editor there is an action to "Load
>>> Resource..." and once you load the resource containing the things you
>>> want to reference, those entries will appear as choices in the
>>> properties view. GMF's graphical editor would need something like
>>> that as well. Probably if you use the Ecore editor to add a
>>> reference to the other model, once you have such a reference, the
>>> graphical editor will give you choices from that other model as well...
>>>
>>>
>>> Martin Jacob wrote:
>>>
>>>> Hi,
>>>>
>>>> how can I set the return type of a operation with the graphical
>>>> editor? The properties view provid just the classes from emf and my
>>>> own classes but i want to return a other instance.
>>>>
>>>> any idea how to do?
>>>>
>>>> Thanks,
>>>> Martin
>>>>
Re: set return type of Operation [message #69295 is a reply to message #69255] Wed, 25 October 2006 09:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Alex,

I see that now. The old environment I had running didn't want to show a
popup up at all but I knew there was such a popup because I'd used
Arrange All that way before...


Alex Shatalin wrote:

> Hello Ed,
>
>> I'm not sure. In the Sample Ecore Editor there is an action to "Load
>> Resource..." and once you load the resource containing the things you
>
> Generated GMF editors contains this action as well. It is available in
> the popup menu for a diagram.
>
> -----------------
> Alex Shatalin
>
>
Re: set return type of Operation [message #69314 is a reply to message #69275] Wed, 25 October 2006 09:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Gabriel,

I'd hate to discourage people from posting helpful advice because Ed
will critique it, so don't be sorry. It's quite common to see folks
casting to Impl, but it's just not a such good thing so I wanted to
gently nudge you in a better direction. I often wonder why this pattern
shows up so often. My suspicion is that the debugger tells you the
exact Impl class so the temptation is to use exactly class the debugger
is showing. I often see folks do XyzPackageImpl.init() as well, but I
don't have a theory for why I see that so often...


Gabriel Merin Cubero wrote:

> Yes, you are very right. Thanks for the advice and sorry posting a not
> very correct code.
>
> Gabriel Merin
>
> Ed Merks wrote:
>
>> Gabriel,
>>
>> I would suggest avoiding whenever possible, the use of XyzImpl,
>> particularly model implementation classes like StructureModelImpl and
>> DataTypeImpl. I would have expected you to cast to Resource,
>> StructureModel, and DataType, not to particular implementations of
>> those. Since models support multiple inheritance but Java classes
>> don't, it may well be the case that you could have a StructureModel
>> instance that's not implemented by StructureModelImpl but rather by a
>> class that does not even extend the StructureModelImpl class.
>>
>>
>> Gabriel Merin Cubero wrote:
>>
>>> I'm not sure if it is the same case, but I had a similar problem. I
>>> had to show in a combo box all the types belonging to the DataType
>>> Class. Normally the user can load as many resources as he may want.
>>> To access to all the resources added by the user I used this code:
>>>
>>> // A hashMap for associating the name of the type with its class
>>> HashMap hashMap = new HashMap();
>>>
>>> // The current editing domain of the editor (Change XXXX with the
>>> name of your editor)
>>> EditingDomain editingDomain = ( (XXXXDiagramEditor) getPart()
>>> ).getEditingDomain();
>>>
>>> ArrayList dtList = new ArrayList(); // A list for the DataType names
>>>
>>> // List of the loaded resources
>>> EList rList = editingDomain.getResourceSet().getResources();
>>>
>>> for (Iterator irList = rList.iterator(); irList.hasNext(); )
>>> {
>>> // We only need the StructureModel resources
>>> XMIResourceImpl rImpl = (XMIResourceImpl) irList.next();
>>> if (rImpl.getContents().get(0) instanceof StructureModelImpl)
>>> {
>>> StructureModelImpl smi = (StructureModelImpl)
>>> rImpl.getContents().get(0);
>>>
>>> // We need the list of the DataTypes
>>> EList smiList = smi.getDataType();
>>> for(Iterator k = smiList.iterator(); k.hasNext(); )
>>> {
>>> Object obj = k.next();
>>> if (obj instanceof DataTypeImpl)
>>> {
>>> DataTypeImpl dt = (DataTypeImpl) obj;
>>> dtList.add(dt.getName());
>>> // I'll use the hashMap to associate the Name of the
>>> Type with its class
>>> hashMap.put(dt.getName(), dt);
>>> }
>>> }
>>> }
>>> }
>>>
>>> As you may see, from all the resources loaded by the user, I only
>>> want those that are StrutureModel intances. And inside the model,
>>> I'm only interested in the DataTypes.
>>>
>>> I hope this helps.
>>>
>>> Gabriel Merin
>>>
>>> Ed Merks wrote:
>>>
>>>> Martin,
>>>>
>>>> I'm not sure. In the Sample Ecore Editor there is an action to
>>>> "Load Resource..." and once you load the resource containing the
>>>> things you want to reference, those entries will appear as choices
>>>> in the properties view. GMF's graphical editor would need
>>>> something like that as well. Probably if you use the Ecore editor
>>>> to add a reference to the other model, once you have such a
>>>> reference, the graphical editor will give you choices from that
>>>> other model as well...
>>>>
>>>>
>>>> Martin Jacob wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> how can I set the return type of a operation with the graphical
>>>>> editor? The properties view provid just the classes from emf and
>>>>> my own classes but i want to return a other instance.
>>>>>
>>>>> any idea how to do?
>>>>>
>>>>> Thanks,
>>>>> Martin
>>>>>
Re: set return type of Operation [message #69336 is a reply to message #69314] Wed, 25 October 2006 09:58 Go to previous message
Eclipse UserFriend
Originally posted by: gabmecu.fiv.upv.es

Don't worry. I'm very thankful for your advice and help. I just was a
bit ashamed because I read that advice before and I still made the same
mistake.

You're also right about why I used Impl instead of the name of the
class: the debugger.

Gabriel Merin.

Ed Merks wrote:
> Gabriel,
>
> I'd hate to discourage people from posting helpful advice because Ed
> will critique it, so don't be sorry. It's quite common to see folks
> casting to Impl, but it's just not a such good thing so I wanted to
> gently nudge you in a better direction. I often wonder why this pattern
> shows up so often. My suspicion is that the debugger tells you the
> exact Impl class so the temptation is to use exactly class the debugger
> is showing. I often see folks do XyzPackageImpl.init() as well, but I
> don't have a theory for why I see that so often...
>
Previous Topic:What controls the layout within a compartment???
Next Topic:How to warn the GMF Diagram Editor that something has changed..
Goto Forum:
  


Current Time: Fri May 09 10:22:18 EDT 2025

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

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

Back to the top