Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF/Genmodel] Filtering right instances in generated editor
[EMF/Genmodel] Filtering right instances in generated editor [message #648487] Thu, 13 January 2011 07:53 Go to next message
Vladimir  is currently offline Vladimir Friend
Messages: 6
Registered: January 2011
Junior Member
In EMF I modeled some metamodel of a data model. M y classes are: Table, KeyColumn and ExportLink. Table  class has KeyColumns and ExportLink has KeyColumns  as well.  But ExportLink should have only instances of Table's KeyColumns. My problem is filtering Table's K eyColumns in generated editor. Multiline popup is populated by KeyColumn instances belonging to all Table instances and I am not able to filter th em efficiently.

My questions are:
1. What is the best (modeling or configuring) practice to solve this problem?
2. How can I simply transform my existing model instances in case of bad metamodel?

Thanks,
Vladimir

[Updated on: Thu, 13 January 2011 07:56]

Report message to a moderator

Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648631 is a reply to message #648487] Thu, 13 January 2011 17:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010302050201080803030700
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Vladimir,

Check out this FAQ:

2.46 How can I control which instances are available as choices when
editing a property in the properties view?
< http://wiki.eclipse.org/index.php/EMF/FAQ#How_can_I_control_ which_instances_are_available_as_choices_when_editing_a_prop erty_in_the_properties_view.3F>

You'll want to define a named constraint that flags invalid choices as
an error so the user can be informed and can use the editor to fix it.

Generally all this involved writing code.


Vladimir wrote:
> In EMF I modeled some metamodel of a data model. M
> y classes are: Table, KeyColumn and ExportLink. Table
> class has KeyColumns and ExportLink has KeyColumns
> as well. But ExportLink should have only instances of
> Table's KeyColumns. My problem is filtering Table's K
> eyColumns in generated editor. Multiline popup is populated
> by KeyColumn instances belonging to
> all Table instances and I am not able to filter th em efficiently.
>
> My questions are:
> 1. What is the best (modeling or configuring) practice to solve this
> problem?
> 2. How will I simply transform my existing model instances in case of
> bad metamodel?
>
> Thanks,
> Vladimir

--------------010302050201080803030700
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">
Vladimir,<br>
<br>
Check out this FAQ:<br>
<blockquote><a
href=" http://wiki.eclipse.org/index.php/EMF/FAQ#How_can_I_control_ which_instances_are_available_as_choices_when_editing_a_prop erty_in_the_properties_view.3F"><span
class="tocnumber">2.46</span> <span class="toctext">How can I control
which instances are available as choices when editing a property in the
properties view?</span></a><br>
</blockquote>
You'll want to define a named constraint that flags invalid choices as
an error so the user can be informed and can use the editor to fix it.<br>
<br>
Generally all this involved writing code.<br>
<br>
<br>
Vladimir wrote:
<blockquote cite="mid:igmao2$h0s$1@news.eclipse.org" type="cite"> In EMF I modeled some metamodel of a data model. M
y classes are: Table, KeyColumn and ExportLink. Table
 class has KeyColumns and ExportLink has KeyColumns 
as well.  But ExportLink should have only instances of 
Table's KeyColumns. My problem is filtering Table's K
eyColumns in generated editor. Multiline popup is populated
by KeyColumn instances belonging to 
all Table instances and I am not able to filter th em efficiently.
<br>
<br>
My questions are:
<br>
1. What is the best (modeling or configuring) practice to solve this
problem?
<br>
2. How will I simply transform my existing model instances in case of
bad metamodel?
<br>
<br>
Thanks,
<br>
Vladimir
<br>
</blockquote>
</body>
</html>

--------------010302050201080803030700--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648749 is a reply to message #648631] Fri, 14 January 2011 12:07 Go to previous messageGo to next message
Vladimir  is currently offline Vladimir Friend
Messages: 6
Registered: January 2011
Junior Member
Ed,

thanks for the link. I am convinced that linked solution is the right one I need. In the meantime I looked around and I found support for Feature Setting Delegates in Helios. Please see http:// wiki.eclipse.org/EMF/New_and_Noteworthy/Helios#Support_for_F eature_Setting_Delegates.

It is completely generated solution based on OCL constraints. But my first attempt to implement it ended with confusing exception:

!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.ocl.ecore.delegate.OCLDelegateException: Missing or invalid derivation constraint for 'SqlModel::ExportLink.exportedKeys'

I simply added annotation with constraint on exportedKeys reference. I was pleased that only model code was regenerated. But OCL constraint is generated in a comment.

Do you agree with me that setting delegates can be used for filtering? Did I misunderstand anything in implementation?

Vladimir
Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648755 is a reply to message #648749] Fri, 14 January 2011 12:41 Go to previous messageGo to next message
Vladimir  is currently offline Vladimir Friend
Messages: 6
Registered: January 2011
Junior Member
> But OCL constraint is generated in a comment.

Sorry, I oversaw generated OCL constraints in the code:
	protected void createOrgAnnotations() {
		String source = "org.eclipse.ocl.ecore.OCL";			
		addAnnotation
		  (getExportLink_ExportedKeys(), 
		   source, 
		   new String[] {
			 "derivation", "if (self.relationship.master.oclIsUndefined()) then OrderedSet{} else self.relationship.master.keyColumns->asOrderedSet() endif"
		   });		
		addAnnotation
		  (getExportLink_ExportedFields(), 
		   source, 
		   new String[] {
			 "derivation", "if (self.relationship.master.oclIsUndefined()) then OrderedSet{} else self.relationship.master.columns->asOrderedSet() endif"
		   });		
		addAnnotation
		  (getImportLink_ForeignKeys(), 
		   source, 
		   new String[] {
			 "derivation", "if (self.relationship.detail.oclIsUndefined()) then OrderedSet{} else self.relationship.detail.keyColumns->asOrderedSet() endif"
		   });		
		addAnnotation
		  (getImportLink_ForeignFields(), 
		   source, 
		   new String[] {
			 "derivation", "if (self.relationship.detail.oclIsUndefined()) then OrderedSet{} else self.relationship.detail.columns->asOrderedSet() endif"
		   });
	}
Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648801 is a reply to message #648755] Fri, 14 January 2011 14:53 Go to previous messageGo to next message
Vladimir  is currently offline Vladimir Friend
Messages: 6
Registered: January 2011
Junior Member
So, for now I returned to the solution recommended by Ed. It definitely works for me. Instead of the OCL expression:
if (self.relationship.master.oclIsUndefined()) then
    OrderedSet{}
else
    self.relationship.master.keyColumns->asOrderedSet()
endif


I wrote following code:
@Override
public Collection<?> getChoiceOfValues(Object object) {
    List<Object> choiceOfValues = new ArrayList<Object>();
    // Filter the choices before returning them
    if (object instanceof ExportLinkImpl) {
        ExportLinkImpl exportLinkImpl = (ExportLinkImpl) object;
        TableImpl master = (TableImpl) ((RelationshipImpl) exportLinkImpl.eContainer()).getMaster();
        if (master != null) {
            choiceOfValues.addAll(master.getKeyColumns());
        }
    }
    return choiceOfValues;
}
Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648823 is a reply to message #648749] Fri, 14 January 2011 16:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Vladimdir,

I'm not sure I understand how you'd expect to use it for filtering; the
property descriptors search the whole instance for valid candidates
(objects of the right type), so I don't see how any form of setting
delegate would impact that search. You might use OCL to implement a
constraint...


Vladimir wrote:
> Ed,
>
> thanks for the link. I am convinced that linked solution is the right
> one I need. In the meantime I looked around and I found support for
> Feature Setting Delegates in Helios. Please see
> http://wiki.eclipse.org/EMF/New_and_Noteworthy/Helios#Suppor t_for_Feature_Setting_Delegates
>
>
> It is completely generated solution based on OCL constraints. But my
> first attempt to implement it ended with confusing exception:
>
> !MESSAGE Unhandled event loop exception
> !STACK 0
> org.eclipse.ocl.ecore.delegate.OCLDelegateException: Missing or
> invalid derivation constraint for 'SqlModel::ExportLink.exportedKeys'
>
> I simply added annotation with constraint on exportedKeys reference. I
> was pleased that only model code was regenerated. But OCL constraint
> is generated in a comment.
>
> Do you agree with me that setting delegates can be used for filtering?
> Did I misunderstand anything in implementation?
>
> Vladimir
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648824 is a reply to message #648801] Fri, 14 January 2011 16:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Vlad,

Comments below.

Vladimir wrote:
> So, for now I returned to the solution recommended by Ed. It
> definitely works for me. Instead of the OCL expression:
>
> if (self.relationship.master.oclIsUndefined()) then
> OrderedSet{}
> else
> self.relationship.master.keyColumns->asOrderedSet()
> endif
>
>
> I wrote following code:
>
> @Override
> public Collection<?> getChoiceOfValues(Object object) {
> List<Object> choiceOfValues = new ArrayList<Object>();
> // Filter the choices before returning them
> if (object instanceof ExportLinkImpl) {
I've asked many people this same question yet no one ever answers it:
What compels you to use the Impl classes rather than the interfaces when
casting? The reason I ask is because we never show examples like this.
Worst of all, there's no reason to expect that every instance of
ExportLink will necessarily be implemented by ExportLinkImpl. In fact,
with multiple inheritance, that generally won't be something you can or
should expect...
> ExportLinkImpl exportLinkImpl = (ExportLinkImpl) object;
> TableImpl master = (TableImpl) ((RelationshipImpl)
> exportLinkImpl.eContainer()).getMaster();
> if (master != null) {
> choiceOfValues.addAll(master.getKeyColumns());
> }
> }
> return choiceOfValues;
> }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648846 is a reply to message #648824] Fri, 14 January 2011 17:33 Go to previous messageGo to next message
Vladimir  is currently offline Vladimir Friend
Messages: 6
Registered: January 2011
Junior Member
> What compels you to use the Impl classes rather than the interfaces when
casting?

What compels me? Desperation? Smile
No, seriously: that snippet was only very working version. I've already corrected it. Don't crucify me Smile
Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648851 is a reply to message #648823] Fri, 14 January 2011 17:52 Go to previous message
Vladimir  is currently offline Vladimir Friend
Messages: 6
Registered: January 2011
Junior Member
> I'm not sure I understand how you'd expect to use it for filtering; the
> property descriptors search the whole instance for valid candidates
> (objects of the right type), so I don't see how any form of setting
> delegate would impact that search. You might use OCL to implement a
> constraint...

Ed,

that was only an idea, rather my wish. If you type something like that
"self.relationship.master.keyColumns->asOrderedSet()"
in interactive OCL console, you get right collection, not constraint. It would be nice if OCL expression could supersede a relation. Maybe an operation instead of a relation is better for such feature.

Vladimir

[Updated on: Fri, 14 January 2011 17:56]

Report message to a moderator

Re: [EMF/Genmodel] Filtering right instances in generated editor [message #648853 is a reply to message #648846] Fri, 14 January 2011 17:43 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Vladimir,

Sorry, I don't mean to insult you. I just wonder why I see it so
often. There are two obvious choices for casting. Cast to the
interface or cast to the implementation class. I would expect the
latter to be an uncompelling choice (the name isn't so pretty) so I
wonder why folks make the choice so often. I'm just very curious. I
imagine if the bundle didn't export the impl package folks wouldn't make
that mistake (but then their model wouldn't be extensible).


Vladimir wrote:
>> What compels you to use the Impl classes rather than the interfaces when
> casting?
>
> What compels me? Desperation? :)
> No, seriously: that snippet was only very working version. I've
> already corrected it. Don't crucify me :)


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EMF Compare] Extending UI
Next Topic:[CDO] [Config] DataSource not properly initialized
Goto Forum:
  


Current Time: Sat Apr 27 01:11:39 GMT 2024

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

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

Back to the top