Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Querying of EModel
Querying of EModel [message #53586] Wed, 27 September 2006 13:13 Go to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 191
Registered: July 2009
Senior Member
Hi ,
I have class called Department(id,name) and Employee(id,name,dept)

I am creating a view with controls for altering the properties of the
Employee model ( imagine like a SWT page with set of controls). I have
drop down for the Employee.dept , the values for the dept dropdown must be
from department.name .

I have a small query in this , is EMF Query is the best suited technoligy
for this purpose or is there any other best way to do it ?

thanks.
Kamesh
Re: Querying of EModel [message #54088 is a reply to message #53586] Thu, 28 September 2006 13:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Kamesh,

I think that EMF Query is most appropriate when the criteria for selecting
elements from the model are variable, because it allows plugging in OCL
expressions or a wide variety of recombinable Condition objects.

Often, though, the requirement is more simply satisfied by an
EcoreUtil.getAllContents(...) iterator with judicious use of the
TreeIterator.prune() method. You can also make a more responsive UI by
listening for model changes that add/remove values that you would put in
your list and keep a cache up-to-date, so that you don't have to scan the
whole model every time the list needs to be shown.

Cheers,

Christian


Kamesh Sampath wrote:

> Hi ,
> I have class called Department(id,name) and Employee(id,name,dept)
>
> I am creating a view with controls for altering the properties of the
> Employee model ( imagine like a SWT page with set of controls). I have
> drop down for the Employee.dept , the values for the dept dropdown must be
> from department.name .
>
> I have a small query in this , is EMF Query is the best suited technoligy
> for this purpose or is there any other best way to do it ?
>
> thanks.
> Kamesh
Re: Querying of EModel [message #54142 is a reply to message #54088] Thu, 28 September 2006 13:49 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 191
Registered: July 2009
Senior Member
Hi Christian,

I agree to your thought .

Will i be able to change my dropdown(combo) contents based on model
changes ?

I am still not clear on the following,

iterator with judicious use of the
TreeIterator.prune() method

Can you please clarify on that ?

Please let me if this question is not to be asked on EMFT . Will post
the same in the concerned newsgroups.

Thanks.

Regards,
Kamesh

Christian W. Damus wrote:
> Hi, Kamesh,
>
> I think that EMF Query is most appropriate when the criteria for selecting
> elements from the model are variable, because it allows plugging in OCL
> expressions or a wide variety of recombinable Condition objects.
>
> Often, though, the requirement is more simply satisfied by an
> EcoreUtil.getAllContents(...) iterator with judicious use of the
> TreeIterator.prune() method. You can also make a more responsive UI by
> listening for model changes that add/remove values that you would put in
> your list and keep a cache up-to-date, so that you don't have to scan the
> whole model every time the list needs to be shown.
>
> Cheers,
>
> Christian
>
>
> Kamesh Sampath wrote:
>
>
>> Hi ,
>> I have class called Department(id,name) and Employee(id,name,dept)
>>
>> I am creating a view with controls for altering the properties of the
>> Employee model ( imagine like a SWT page with set of controls). I have
>> drop down for the Employee.dept , the values for the dept dropdown must be
>> from department.name .
>>
>> I have a small query in this , is EMF Query is the best suited technoligy
>> for this purpose or is there any other best way to do it ?
>>
>> thanks.
>> Kamesh
>>
>
>


--

Kamesh Sampath
Re: Querying of EModel [message #54170 is a reply to message #54142] Thu, 28 September 2006 14:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Kamesh,

EMF supports the concept of a tree iterator, which extends the Iterator
API with a method called prune(). Methods such as
ResourceSet/Resource.getAllContents and EObject.eAllContents return such
an iterator, as do various EcoreUtil.getAllContents/getAllProperContents
(all of which are based on EcoreUtil.TreeContentIterator or
AbstractTreeIterator). So you can easily iterate over the contents of a
tree to avoid needing to do it recursively, and you can use the prune()
method to avoid walking down a tree branch you don't want to visit. So
a quick tree walk to find all the objects matching some criterion is
very easy to write, and with appropriate pruning can be tuned to avoid
walking branches that can't lead to the results you are looking for.


Kamesh Sampath wrote:
> Hi Christian,
>
> I agree to your thought .
>
> Will i be able to change my dropdown(combo) contents based on model
> changes ?
>
> I am still not clear on the following,
>
> iterator with judicious use of the
> TreeIterator.prune() method
>
> Can you please clarify on that ?
>
> Please let me if this question is not to be asked on EMFT . Will post
> the same in the concerned newsgroups.
>
> Thanks.
>
> Regards,
> Kamesh
>
> Christian W. Damus wrote:
>> Hi, Kamesh,
>>
>> I think that EMF Query is most appropriate when the criteria for
>> selecting
>> elements from the model are variable, because it allows plugging in OCL
>> expressions or a wide variety of recombinable Condition objects.
>>
>> Often, though, the requirement is more simply satisfied by an
>> EcoreUtil.getAllContents(...) iterator with judicious use of the
>> TreeIterator.prune() method. You can also make a more responsive UI by
>> listening for model changes that add/remove values that you would put in
>> your list and keep a cache up-to-date, so that you don't have to scan
>> the
>> whole model every time the list needs to be shown.
>>
>> Cheers,
>>
>> Christian
>>
>>
>> Kamesh Sampath wrote:
>>
>>
>>> Hi ,
>>> I have class called Department(id,name) and Employee(id,name,dept)
>>>
>>> I am creating a view with controls for altering the properties of the
>>> Employee model ( imagine like a SWT page with set of controls). I have
>>> drop down for the Employee.dept , the values for the dept dropdown
>>> must be
>>> from department.name .
>>>
>>> I have a small query in this , is EMF Query is the best suited
>>> technoligy
>>> for this purpose or is there any other best way to do it ?
>>>
>>> thanks.
>>> Kamesh
>>>
>>
>>
>
>
Re: Querying of EModel [message #54197 is a reply to message #54170] Thu, 28 September 2006 17:28 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 191
Registered: July 2009
Senior Member
Ed,

Thanks for the info on the TreeIterator ,

I have implemented the same and the code snippet is as follows,

Resource resource = ((Resource) editingDomain.getResourceSet()
.getResources().get(0));
StrutsConfigType root = (StrutsConfigType) resource.getContents()
.get(0);
TreeIterator iterator = EcoreUtil.getAllProperContents(root
.getFormBeans(), false);
ArrayList beanNames = new ArrayList();
while (iterator.hasNext()) {
Object obj = iterator.next();
// System.out.println(obj.getClass());
if (obj instanceof FormBeanType) {
FormBeanType beanType = (FormBeanType) obj;
if (beanType != null) {
System.out.println(beanType.getName());
beanNames.add(beanType.getName());
}
}
}

But i have not used purne(). Is this a right approach or there is any
other better way ??

thanks,
Kamesh

Ed Merks wrote:
> Kamesh,
>
> EMF supports the concept of a tree iterator, which extends the
> Iterator API with a method called prune(). Methods such as
> ResourceSet/Resource.getAllContents and EObject.eAllContents return
> such an iterator, as do various
> EcoreUtil.getAllContents/getAllProperContents (all of which are based
> on EcoreUtil.TreeContentIterator or AbstractTreeIterator). So you can
> easily iterate over the contents of a tree to avoid needing to do it
> recursively, and you can use the prune() method to avoid walking down
> a tree branch you don't want to visit. So a quick tree walk to find
> all the objects matching some criterion is very easy to write, and
> with appropriate pruning can be tuned to avoid walking branches that
> can't lead to the results you are looking for.
>
>
> Kamesh Sampath wrote:
>> Hi Christian,
>>
>> I agree to your thought .
>>
>> Will i be able to change my dropdown(combo) contents based on model
>> changes ?
>>
>> I am still not clear on the following,
>>
>> iterator with judicious use of the
>> TreeIterator.prune() method
>>
>> Can you please clarify on that ?
>>
>> Please let me if this question is not to be asked on EMFT . Will post
>> the same in the concerned newsgroups.
>>
>> Thanks.
>>
>> Regards,
>> Kamesh
>>
>> Christian W. Damus wrote:
>>> Hi, Kamesh,
>>>
>>> I think that EMF Query is most appropriate when the criteria for
>>> selecting
>>> elements from the model are variable, because it allows plugging in OCL
>>> expressions or a wide variety of recombinable Condition objects.
>>>
>>> Often, though, the requirement is more simply satisfied by an
>>> EcoreUtil.getAllContents(...) iterator with judicious use of the
>>> TreeIterator.prune() method. You can also make a more responsive UI by
>>> listening for model changes that add/remove values that you would
>>> put in
>>> your list and keep a cache up-to-date, so that you don't have to
>>> scan the
>>> whole model every time the list needs to be shown.
>>>
>>> Cheers,
>>>
>>> Christian
>>>
>>>
>>> Kamesh Sampath wrote:
>>>
>>>
>>>> Hi ,
>>>> I have class called Department(id,name) and Employee(id,name,dept)
>>>>
>>>> I am creating a view with controls for altering the properties of the
>>>> Employee model ( imagine like a SWT page with set of controls). I have
>>>> drop down for the Employee.dept , the values for the dept dropdown
>>>> must be
>>>> from department.name .
>>>>
>>>> I have a small query in this , is EMF Query is the best suited
>>>> technoligy
>>>> for this purpose or is there any other best way to do it ?
>>>>
>>>> thanks.
>>>> Kamesh
>>>>
>>>
>>>
>>
>>


--

Kamesh Sampath
Re: Querying of EModel [message #54223 is a reply to message #54197] Thu, 28 September 2006 17:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Kamesh,

This looks fine. Note that the beanType != null guard is redundant.
Firstly, because the tree iterator will never return null and secondly
because the instanceof FormBeanType test will not return true for null.


Kamesh Sampath wrote:
> Ed,
>
> Thanks for the info on the TreeIterator ,
>
> I have implemented the same and the code snippet is as follows,
>
> Resource resource = ((Resource) editingDomain.getResourceSet()
> .getResources().get(0));
> StrutsConfigType root = (StrutsConfigType) resource.getContents()
> .get(0);
> TreeIterator iterator = EcoreUtil.getAllProperContents(root
> .getFormBeans(), false);
> ArrayList beanNames = new ArrayList();
> while (iterator.hasNext()) {
> Object obj = iterator.next();
> // System.out.println(obj.getClass());
> if (obj instanceof FormBeanType) {
> FormBeanType beanType = (FormBeanType) obj;
> if (beanType != null) {
> System.out.println(beanType.getName());
> beanNames.add(beanType.getName());
> }
> }
> }
>
> But i have not used purne(). Is this a right approach or there is any
> other better way ??
>
> thanks,
> Kamesh
>
> Ed Merks wrote:
>> Kamesh,
>>
>> EMF supports the concept of a tree iterator, which extends the
>> Iterator API with a method called prune(). Methods such as
>> ResourceSet/Resource.getAllContents and EObject.eAllContents return
>> such an iterator, as do various
>> EcoreUtil.getAllContents/getAllProperContents (all of which are based
>> on EcoreUtil.TreeContentIterator or AbstractTreeIterator). So you
>> can easily iterate over the contents of a tree to avoid needing to do
>> it recursively, and you can use the prune() method to avoid walking
>> down a tree branch you don't want to visit. So a quick tree walk to
>> find all the objects matching some criterion is very easy to write,
>> and with appropriate pruning can be tuned to avoid walking branches
>> that can't lead to the results you are looking for.
>>
>>
>> Kamesh Sampath wrote:
>>> Hi Christian,
>>>
>>> I agree to your thought .
>>>
>>> Will i be able to change my dropdown(combo) contents based on model
>>> changes ?
>>>
>>> I am still not clear on the following,
>>>
>>> iterator with judicious use of the
>>> TreeIterator.prune() method
>>>
>>> Can you please clarify on that ?
>>>
>>> Please let me if this question is not to be asked on EMFT . Will
>>> post the same in the concerned newsgroups.
>>>
>>> Thanks.
>>>
>>> Regards,
>>> Kamesh
>>>
>>> Christian W. Damus wrote:
>>>> Hi, Kamesh,
>>>>
>>>> I think that EMF Query is most appropriate when the criteria for
>>>> selecting
>>>> elements from the model are variable, because it allows plugging in
>>>> OCL
>>>> expressions or a wide variety of recombinable Condition objects.
>>>>
>>>> Often, though, the requirement is more simply satisfied by an
>>>> EcoreUtil.getAllContents(...) iterator with judicious use of the
>>>> TreeIterator.prune() method. You can also make a more responsive
>>>> UI by
>>>> listening for model changes that add/remove values that you would
>>>> put in
>>>> your list and keep a cache up-to-date, so that you don't have to
>>>> scan the
>>>> whole model every time the list needs to be shown.
>>>>
>>>> Cheers,
>>>>
>>>> Christian
>>>>
>>>>
>>>> Kamesh Sampath wrote:
>>>>
>>>>
>>>>> Hi ,
>>>>> I have class called Department(id,name) and Employee(id,name,dept)
>>>>>
>>>>> I am creating a view with controls for altering the properties of the
>>>>> Employee model ( imagine like a SWT page with set of controls). I
>>>>> have
>>>>> drop down for the Employee.dept , the values for the dept dropdown
>>>>> must be
>>>>> from department.name .
>>>>>
>>>>> I have a small query in this , is EMF Query is the best suited
>>>>> technoligy
>>>>> for this purpose or is there any other best way to do it ?
>>>>>
>>>>> thanks.
>>>>> Kamesh
>>>>>
>>>>
>>>>
>>>
>>>
>
>
Re: Querying of EModel [message #54328 is a reply to message #54223] Fri, 29 September 2006 03:11 Go to previous message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 191
Registered: July 2009
Senior Member
Ed,

thanks a lot !

Regards,
Kamesh

Ed Merks wrote:
> Kamesh,
>
> This looks fine. Note that the beanType != null guard is redundant.
> Firstly, because the tree iterator will never return null and secondly
> because the instanceof FormBeanType test will not return true for null.
>
>
> Kamesh Sampath wrote:
>> Ed,
>>
>> Thanks for the info on the TreeIterator ,
>>
>> I have implemented the same and the code snippet is as follows,
>>
>> Resource resource = ((Resource) editingDomain.getResourceSet()
>> .getResources().get(0));
>> StrutsConfigType root = (StrutsConfigType) resource.getContents()
>> .get(0);
>> TreeIterator iterator = EcoreUtil.getAllProperContents(root
>> .getFormBeans(), false);
>> ArrayList beanNames = new ArrayList();
>> while (iterator.hasNext()) {
>> Object obj = iterator.next();
>> // System.out.println(obj.getClass());
>> if (obj instanceof FormBeanType) {
>> FormBeanType beanType = (FormBeanType) obj;
>> if (beanType != null) {
>> System.out.println(beanType.getName());
>> beanNames.add(beanType.getName());
>> }
>> }
>> }
>>
>> But i have not used purne(). Is this a right approach or there is any
>> other better way ??
>>
>> thanks,
>> Kamesh
>>
>> Ed Merks wrote:
>>> Kamesh,
>>>
>>> EMF supports the concept of a tree iterator, which extends the
>>> Iterator API with a method called prune(). Methods such as
>>> ResourceSet/Resource.getAllContents and EObject.eAllContents return
>>> such an iterator, as do various
>>> EcoreUtil.getAllContents/getAllProperContents (all of which are
>>> based on EcoreUtil.TreeContentIterator or AbstractTreeIterator). So
>>> you can easily iterate over the contents of a tree to avoid needing
>>> to do it recursively, and you can use the prune() method to avoid
>>> walking down a tree branch you don't want to visit. So a quick tree
>>> walk to find all the objects matching some criterion is very easy to
>>> write, and with appropriate pruning can be tuned to avoid walking
>>> branches that can't lead to the results you are looking for.
>>>
>>>
>>> Kamesh Sampath wrote:
>>>> Hi Christian,
>>>>
>>>> I agree to your thought .
>>>>
>>>> Will i be able to change my dropdown(combo) contents based on model
>>>> changes ?
>>>>
>>>> I am still not clear on the following,
>>>>
>>>> iterator with judicious use of the
>>>> TreeIterator.prune() method
>>>>
>>>> Can you please clarify on that ?
>>>>
>>>> Please let me if this question is not to be asked on EMFT . Will
>>>> post the same in the concerned newsgroups.
>>>>
>>>> Thanks.
>>>>
>>>> Regards,
>>>> Kamesh
>>>>
>>>> Christian W. Damus wrote:
>>>>> Hi, Kamesh,
>>>>>
>>>>> I think that EMF Query is most appropriate when the criteria for
>>>>> selecting
>>>>> elements from the model are variable, because it allows plugging
>>>>> in OCL
>>>>> expressions or a wide variety of recombinable Condition objects.
>>>>>
>>>>> Often, though, the requirement is more simply satisfied by an
>>>>> EcoreUtil.getAllContents(...) iterator with judicious use of the
>>>>> TreeIterator.prune() method. You can also make a more responsive
>>>>> UI by
>>>>> listening for model changes that add/remove values that you would
>>>>> put in
>>>>> your list and keep a cache up-to-date, so that you don't have to
>>>>> scan the
>>>>> whole model every time the list needs to be shown.
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Christian
>>>>>
>>>>>
>>>>> Kamesh Sampath wrote:
>>>>>
>>>>>
>>>>>> Hi ,
>>>>>> I have class called Department(id,name) and Employee(id,name,dept)
>>>>>>
>>>>>> I am creating a view with controls for altering the properties of
>>>>>> the
>>>>>> Employee model ( imagine like a SWT page with set of controls). I
>>>>>> have
>>>>>> drop down for the Employee.dept , the values for the dept
>>>>>> dropdown must be
>>>>>> from department.name .
>>>>>>
>>>>>> I have a small query in this , is EMF Query is the best suited
>>>>>> technoligy
>>>>>> for this purpose or is there any other best way to do it ?
>>>>>>
>>>>>> thanks.
>>>>>> Kamesh
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>
>>


--

Kamesh Sampath
Re: Querying of EModel [message #592540 is a reply to message #53586] Thu, 28 September 2006 13:30 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Kamesh,

I think that EMF Query is most appropriate when the criteria for selecting
elements from the model are variable, because it allows plugging in OCL
expressions or a wide variety of recombinable Condition objects.

Often, though, the requirement is more simply satisfied by an
EcoreUtil.getAllContents(...) iterator with judicious use of the
TreeIterator.prune() method. You can also make a more responsive UI by
listening for model changes that add/remove values that you would put in
your list and keep a cache up-to-date, so that you don't have to scan the
whole model every time the list needs to be shown.

Cheers,

Christian


Kamesh Sampath wrote:

> Hi ,
> I have class called Department(id,name) and Employee(id,name,dept)
>
> I am creating a view with controls for altering the properties of the
> Employee model ( imagine like a SWT page with set of controls). I have
> drop down for the Employee.dept , the values for the dept dropdown must be
> from department.name .
>
> I have a small query in this , is EMF Query is the best suited technoligy
> for this purpose or is there any other best way to do it ?
>
> thanks.
> Kamesh
Re: Querying of EModel [message #592555 is a reply to message #54088] Thu, 28 September 2006 13:49 Go to previous message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 191
Registered: July 2009
Senior Member
Hi Christian,

I agree to your thought .

Will i be able to change my dropdown(combo) contents based on model
changes ?

I am still not clear on the following,

iterator with judicious use of the
TreeIterator.prune() method

Can you please clarify on that ?

Please let me if this question is not to be asked on EMFT . Will post
the same in the concerned newsgroups.

Thanks.

Regards,
Kamesh

Christian W. Damus wrote:
> Hi, Kamesh,
>
> I think that EMF Query is most appropriate when the criteria for selecting
> elements from the model are variable, because it allows plugging in OCL
> expressions or a wide variety of recombinable Condition objects.
>
> Often, though, the requirement is more simply satisfied by an
> EcoreUtil.getAllContents(...) iterator with judicious use of the
> TreeIterator.prune() method. You can also make a more responsive UI by
> listening for model changes that add/remove values that you would put in
> your list and keep a cache up-to-date, so that you don't have to scan the
> whole model every time the list needs to be shown.
>
> Cheers,
>
> Christian
>
>
> Kamesh Sampath wrote:
>
>
>> Hi ,
>> I have class called Department(id,name) and Employee(id,name,dept)
>>
>> I am creating a view with controls for altering the properties of the
>> Employee model ( imagine like a SWT page with set of controls). I have
>> drop down for the Employee.dept , the values for the dept dropdown must be
>> from department.name .
>>
>> I have a small query in this , is EMF Query is the best suited technoligy
>> for this purpose or is there any other best way to do it ?
>>
>> thanks.
>> Kamesh
>>
>
>


--

Kamesh Sampath
Re: Querying of EModel [message #592571 is a reply to message #54142] Thu, 28 September 2006 14:04 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Kamesh,

EMF supports the concept of a tree iterator, which extends the Iterator
API with a method called prune(). Methods such as
ResourceSet/Resource.getAllContents and EObject.eAllContents return such
an iterator, as do various EcoreUtil.getAllContents/getAllProperContents
(all of which are based on EcoreUtil.TreeContentIterator or
AbstractTreeIterator). So you can easily iterate over the contents of a
tree to avoid needing to do it recursively, and you can use the prune()
method to avoid walking down a tree branch you don't want to visit. So
a quick tree walk to find all the objects matching some criterion is
very easy to write, and with appropriate pruning can be tuned to avoid
walking branches that can't lead to the results you are looking for.


Kamesh Sampath wrote:
> Hi Christian,
>
> I agree to your thought .
>
> Will i be able to change my dropdown(combo) contents based on model
> changes ?
>
> I am still not clear on the following,
>
> iterator with judicious use of the
> TreeIterator.prune() method
>
> Can you please clarify on that ?
>
> Please let me if this question is not to be asked on EMFT . Will post
> the same in the concerned newsgroups.
>
> Thanks.
>
> Regards,
> Kamesh
>
> Christian W. Damus wrote:
>> Hi, Kamesh,
>>
>> I think that EMF Query is most appropriate when the criteria for
>> selecting
>> elements from the model are variable, because it allows plugging in OCL
>> expressions or a wide variety of recombinable Condition objects.
>>
>> Often, though, the requirement is more simply satisfied by an
>> EcoreUtil.getAllContents(...) iterator with judicious use of the
>> TreeIterator.prune() method. You can also make a more responsive UI by
>> listening for model changes that add/remove values that you would put in
>> your list and keep a cache up-to-date, so that you don't have to scan
>> the
>> whole model every time the list needs to be shown.
>>
>> Cheers,
>>
>> Christian
>>
>>
>> Kamesh Sampath wrote:
>>
>>
>>> Hi ,
>>> I have class called Department(id,name) and Employee(id,name,dept)
>>>
>>> I am creating a view with controls for altering the properties of the
>>> Employee model ( imagine like a SWT page with set of controls). I have
>>> drop down for the Employee.dept , the values for the dept dropdown
>>> must be
>>> from department.name .
>>>
>>> I have a small query in this , is EMF Query is the best suited
>>> technoligy
>>> for this purpose or is there any other best way to do it ?
>>>
>>> thanks.
>>> Kamesh
>>>
>>
>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Querying of EModel [message #592579 is a reply to message #54170] Thu, 28 September 2006 17:28 Go to previous message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 191
Registered: July 2009
Senior Member
Ed,

Thanks for the info on the TreeIterator ,

I have implemented the same and the code snippet is as follows,

Resource resource = ((Resource) editingDomain.getResourceSet()
.getResources().get(0));
StrutsConfigType root = (StrutsConfigType) resource.getContents()
.get(0);
TreeIterator iterator = EcoreUtil.getAllProperContents(root
.getFormBeans(), false);
ArrayList beanNames = new ArrayList();
while (iterator.hasNext()) {
Object obj = iterator.next();
// System.out.println(obj.getClass());
if (obj instanceof FormBeanType) {
FormBeanType beanType = (FormBeanType) obj;
if (beanType != null) {
System.out.println(beanType.getName());
beanNames.add(beanType.getName());
}
}
}

But i have not used purne(). Is this a right approach or there is any
other better way ??

thanks,
Kamesh

Ed Merks wrote:
> Kamesh,
>
> EMF supports the concept of a tree iterator, which extends the
> Iterator API with a method called prune(). Methods such as
> ResourceSet/Resource.getAllContents and EObject.eAllContents return
> such an iterator, as do various
> EcoreUtil.getAllContents/getAllProperContents (all of which are based
> on EcoreUtil.TreeContentIterator or AbstractTreeIterator). So you can
> easily iterate over the contents of a tree to avoid needing to do it
> recursively, and you can use the prune() method to avoid walking down
> a tree branch you don't want to visit. So a quick tree walk to find
> all the objects matching some criterion is very easy to write, and
> with appropriate pruning can be tuned to avoid walking branches that
> can't lead to the results you are looking for.
>
>
> Kamesh Sampath wrote:
>> Hi Christian,
>>
>> I agree to your thought .
>>
>> Will i be able to change my dropdown(combo) contents based on model
>> changes ?
>>
>> I am still not clear on the following,
>>
>> iterator with judicious use of the
>> TreeIterator.prune() method
>>
>> Can you please clarify on that ?
>>
>> Please let me if this question is not to be asked on EMFT . Will post
>> the same in the concerned newsgroups.
>>
>> Thanks.
>>
>> Regards,
>> Kamesh
>>
>> Christian W. Damus wrote:
>>> Hi, Kamesh,
>>>
>>> I think that EMF Query is most appropriate when the criteria for
>>> selecting
>>> elements from the model are variable, because it allows plugging in OCL
>>> expressions or a wide variety of recombinable Condition objects.
>>>
>>> Often, though, the requirement is more simply satisfied by an
>>> EcoreUtil.getAllContents(...) iterator with judicious use of the
>>> TreeIterator.prune() method. You can also make a more responsive UI by
>>> listening for model changes that add/remove values that you would
>>> put in
>>> your list and keep a cache up-to-date, so that you don't have to
>>> scan the
>>> whole model every time the list needs to be shown.
>>>
>>> Cheers,
>>>
>>> Christian
>>>
>>>
>>> Kamesh Sampath wrote:
>>>
>>>
>>>> Hi ,
>>>> I have class called Department(id,name) and Employee(id,name,dept)
>>>>
>>>> I am creating a view with controls for altering the properties of the
>>>> Employee model ( imagine like a SWT page with set of controls). I have
>>>> drop down for the Employee.dept , the values for the dept dropdown
>>>> must be
>>>> from department.name .
>>>>
>>>> I have a small query in this , is EMF Query is the best suited
>>>> technoligy
>>>> for this purpose or is there any other best way to do it ?
>>>>
>>>> thanks.
>>>> Kamesh
>>>>
>>>
>>>
>>
>>


--

Kamesh Sampath
Re: Querying of EModel [message #592590 is a reply to message #54197] Thu, 28 September 2006 17:41 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Kamesh,

This looks fine. Note that the beanType != null guard is redundant.
Firstly, because the tree iterator will never return null and secondly
because the instanceof FormBeanType test will not return true for null.


Kamesh Sampath wrote:
> Ed,
>
> Thanks for the info on the TreeIterator ,
>
> I have implemented the same and the code snippet is as follows,
>
> Resource resource = ((Resource) editingDomain.getResourceSet()
> .getResources().get(0));
> StrutsConfigType root = (StrutsConfigType) resource.getContents()
> .get(0);
> TreeIterator iterator = EcoreUtil.getAllProperContents(root
> .getFormBeans(), false);
> ArrayList beanNames = new ArrayList();
> while (iterator.hasNext()) {
> Object obj = iterator.next();
> // System.out.println(obj.getClass());
> if (obj instanceof FormBeanType) {
> FormBeanType beanType = (FormBeanType) obj;
> if (beanType != null) {
> System.out.println(beanType.getName());
> beanNames.add(beanType.getName());
> }
> }
> }
>
> But i have not used purne(). Is this a right approach or there is any
> other better way ??
>
> thanks,
> Kamesh
>
> Ed Merks wrote:
>> Kamesh,
>>
>> EMF supports the concept of a tree iterator, which extends the
>> Iterator API with a method called prune(). Methods such as
>> ResourceSet/Resource.getAllContents and EObject.eAllContents return
>> such an iterator, as do various
>> EcoreUtil.getAllContents/getAllProperContents (all of which are based
>> on EcoreUtil.TreeContentIterator or AbstractTreeIterator). So you
>> can easily iterate over the contents of a tree to avoid needing to do
>> it recursively, and you can use the prune() method to avoid walking
>> down a tree branch you don't want to visit. So a quick tree walk to
>> find all the objects matching some criterion is very easy to write,
>> and with appropriate pruning can be tuned to avoid walking branches
>> that can't lead to the results you are looking for.
>>
>>
>> Kamesh Sampath wrote:
>>> Hi Christian,
>>>
>>> I agree to your thought .
>>>
>>> Will i be able to change my dropdown(combo) contents based on model
>>> changes ?
>>>
>>> I am still not clear on the following,
>>>
>>> iterator with judicious use of the
>>> TreeIterator.prune() method
>>>
>>> Can you please clarify on that ?
>>>
>>> Please let me if this question is not to be asked on EMFT . Will
>>> post the same in the concerned newsgroups.
>>>
>>> Thanks.
>>>
>>> Regards,
>>> Kamesh
>>>
>>> Christian W. Damus wrote:
>>>> Hi, Kamesh,
>>>>
>>>> I think that EMF Query is most appropriate when the criteria for
>>>> selecting
>>>> elements from the model are variable, because it allows plugging in
>>>> OCL
>>>> expressions or a wide variety of recombinable Condition objects.
>>>>
>>>> Often, though, the requirement is more simply satisfied by an
>>>> EcoreUtil.getAllContents(...) iterator with judicious use of the
>>>> TreeIterator.prune() method. You can also make a more responsive
>>>> UI by
>>>> listening for model changes that add/remove values that you would
>>>> put in
>>>> your list and keep a cache up-to-date, so that you don't have to
>>>> scan the
>>>> whole model every time the list needs to be shown.
>>>>
>>>> Cheers,
>>>>
>>>> Christian
>>>>
>>>>
>>>> Kamesh Sampath wrote:
>>>>
>>>>
>>>>> Hi ,
>>>>> I have class called Department(id,name) and Employee(id,name,dept)
>>>>>
>>>>> I am creating a view with controls for altering the properties of the
>>>>> Employee model ( imagine like a SWT page with set of controls). I
>>>>> have
>>>>> drop down for the Employee.dept , the values for the dept dropdown
>>>>> must be
>>>>> from department.name .
>>>>>
>>>>> I have a small query in this , is EMF Query is the best suited
>>>>> technoligy
>>>>> for this purpose or is there any other best way to do it ?
>>>>>
>>>>> thanks.
>>>>> Kamesh
>>>>>
>>>>
>>>>
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Querying of EModel [message #592633 is a reply to message #54223] Fri, 29 September 2006 03:11 Go to previous message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 191
Registered: July 2009
Senior Member
Ed,

thanks a lot !

Regards,
Kamesh

Ed Merks wrote:
> Kamesh,
>
> This looks fine. Note that the beanType != null guard is redundant.
> Firstly, because the tree iterator will never return null and secondly
> because the instanceof FormBeanType test will not return true for null.
>
>
> Kamesh Sampath wrote:
>> Ed,
>>
>> Thanks for the info on the TreeIterator ,
>>
>> I have implemented the same and the code snippet is as follows,
>>
>> Resource resource = ((Resource) editingDomain.getResourceSet()
>> .getResources().get(0));
>> StrutsConfigType root = (StrutsConfigType) resource.getContents()
>> .get(0);
>> TreeIterator iterator = EcoreUtil.getAllProperContents(root
>> .getFormBeans(), false);
>> ArrayList beanNames = new ArrayList();
>> while (iterator.hasNext()) {
>> Object obj = iterator.next();
>> // System.out.println(obj.getClass());
>> if (obj instanceof FormBeanType) {
>> FormBeanType beanType = (FormBeanType) obj;
>> if (beanType != null) {
>> System.out.println(beanType.getName());
>> beanNames.add(beanType.getName());
>> }
>> }
>> }
>>
>> But i have not used purne(). Is this a right approach or there is any
>> other better way ??
>>
>> thanks,
>> Kamesh
>>
>> Ed Merks wrote:
>>> Kamesh,
>>>
>>> EMF supports the concept of a tree iterator, which extends the
>>> Iterator API with a method called prune(). Methods such as
>>> ResourceSet/Resource.getAllContents and EObject.eAllContents return
>>> such an iterator, as do various
>>> EcoreUtil.getAllContents/getAllProperContents (all of which are
>>> based on EcoreUtil.TreeContentIterator or AbstractTreeIterator). So
>>> you can easily iterate over the contents of a tree to avoid needing
>>> to do it recursively, and you can use the prune() method to avoid
>>> walking down a tree branch you don't want to visit. So a quick tree
>>> walk to find all the objects matching some criterion is very easy to
>>> write, and with appropriate pruning can be tuned to avoid walking
>>> branches that can't lead to the results you are looking for.
>>>
>>>
>>> Kamesh Sampath wrote:
>>>> Hi Christian,
>>>>
>>>> I agree to your thought .
>>>>
>>>> Will i be able to change my dropdown(combo) contents based on model
>>>> changes ?
>>>>
>>>> I am still not clear on the following,
>>>>
>>>> iterator with judicious use of the
>>>> TreeIterator.prune() method
>>>>
>>>> Can you please clarify on that ?
>>>>
>>>> Please let me if this question is not to be asked on EMFT . Will
>>>> post the same in the concerned newsgroups.
>>>>
>>>> Thanks.
>>>>
>>>> Regards,
>>>> Kamesh
>>>>
>>>> Christian W. Damus wrote:
>>>>> Hi, Kamesh,
>>>>>
>>>>> I think that EMF Query is most appropriate when the criteria for
>>>>> selecting
>>>>> elements from the model are variable, because it allows plugging
>>>>> in OCL
>>>>> expressions or a wide variety of recombinable Condition objects.
>>>>>
>>>>> Often, though, the requirement is more simply satisfied by an
>>>>> EcoreUtil.getAllContents(...) iterator with judicious use of the
>>>>> TreeIterator.prune() method. You can also make a more responsive
>>>>> UI by
>>>>> listening for model changes that add/remove values that you would
>>>>> put in
>>>>> your list and keep a cache up-to-date, so that you don't have to
>>>>> scan the
>>>>> whole model every time the list needs to be shown.
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Christian
>>>>>
>>>>>
>>>>> Kamesh Sampath wrote:
>>>>>
>>>>>
>>>>>> Hi ,
>>>>>> I have class called Department(id,name) and Employee(id,name,dept)
>>>>>>
>>>>>> I am creating a view with controls for altering the properties of
>>>>>> the
>>>>>> Employee model ( imagine like a SWT page with set of controls). I
>>>>>> have
>>>>>> drop down for the Employee.dept , the values for the dept
>>>>>> dropdown must be
>>>>>> from department.name .
>>>>>>
>>>>>> I have a small query in this , is EMF Query is the best suited
>>>>>> technoligy
>>>>>> for this purpose or is there any other best way to do it ?
>>>>>>
>>>>>> thanks.
>>>>>> Kamesh
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>
>>


--

Kamesh Sampath
Previous Topic:Requires plug-in "org.eclipse.net4j"
Next Topic:code generation with JET2 and EMF
Goto Forum:
  


Current Time: Fri Apr 26 16:07:40 GMT 2024

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

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

Back to the top