Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to set duplicates at EList
How to set duplicates at EList [message #1032880] Wed, 03 April 2013 15:04 Go to next message
Fatla 777 is currently offline Fatla 777Friend
Messages: 13
Registered: April 2013
Junior Member
I have been trying to set duplicates,Strings,at EList.

The issue that the following method bans to add duplicates:

elist.set(index, value);
I have been searching on a way that fixes that and I have found that I need to disable Uniqueness but this would may affect the rest of framework.


I know that EList is a containment lists that cannot allow duplicates.
However,is there any workarounds that make me resolve the issue I have!

Any ideas would be appreciated.

Thanks.
Re: How to set duplicates at EList [message #1033031 is a reply to message #1032880] Wed, 03 April 2013 19:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Multi-valued EAttributes allow duplicates if you set "unique" to false
in your Ecore model.

On 03/04/2013 5:16 PM, Fatla 777 wrote:
> I have been trying to set duplicates,Strings,at EList.
>
> The issue that the following method bans to add duplicates:
>
> elist.set(index, value);
> I have been searching on a way that fixes that and I have found that I
> need to disable Uniqueness but this would may affect the rest of
> framework.
>
>
> I know that EList is a containment lists that cannot allow duplicates.
> However,is there any workarounds that make me resolve the issue I have!
>
> Any ideas would be appreciated.
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to set duplicates at EList [message #1033052 is a reply to message #1033031] Wed, 03 April 2013 20:04 Go to previous messageGo to next message
Fatla 777 is currently offline Fatla 777Friend
Messages: 13
Registered: April 2013
Junior Member
Frankly I have set it manually at myClassImpl to test it.
The default is unique so the old code was:
{
if (students == null)
    {    
      students= new EDataTypeUniqueEList<String>(String.class, this, StudentPackage.PARAMS);
    }



My new manual updates:
	students= new EObjectEList<String>(String.class, this, StudentPackage.PARAMS);


that makes it work perfect.

I am in middle in smth and I will try to update at ecore file later .. will that produce the same result .EObjectEList !

Additionally,would you save sometime for me and tell me the flag that enables me to disable the uniqueness at emf !

Thanks Ed.

Re: How to set duplicates at EList [message #1033327 is a reply to message #1033052] Thu, 04 April 2013 05:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Fatla,

Comments below.

On 03/04/2013 10:04 PM, Fatla 777 wrote:
> Frankly I have set it manually at myClassImpl to test it.
> The default is unique so the old code was:
> {
> if (students == null)
> { students= new EDataTypeUniqueEList<String>(String.class,
> this, StudentPackage.PARAMS);
> }
Best you do it in the model so that StudentPackage.PARAMS.isUnique
returns false.
>
>
> My new manual updates:
> students= new EObjectEList<String>(String.class, this,
> StudentPackage.PARAMS);
>
> that makes it work perfect.
>
> I am in middle in smth and I will try to update at ecore file later ..
> will that produce the same result .EObjectEList !
It's not generally supported for EObject

https://bugs.eclipse.org/bugs/show_bug.cgi?id=89325

so you'd have to create a specialized list that overrides isUnique to
return false (and then live with the consequences that the framework
generally assumes all EObject lists contain only unique objects).
>
> Additionally,would you save sometime for me and tell me the flag that
> enables me to disable the uniqueness at emf !
org.eclipse.emf.ecore.ETypedElement.isUnique(), but as I mentioned,
that's effectively ignored for EReferences.
>
> Thanks Ed.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to set duplicates at EList [message #1033412 is a reply to message #1033327] Thu, 04 April 2013 07:58 Go to previous messageGo to next message
Fatla 777 is currently offline Fatla 777Friend
Messages: 13
Registered: April 2013
Junior Member
I have managed as you said and handled @EMF.

Now the generated code @StudentImpl

if (studeents== null) {
			studeents= new EDataTypeEList<String>(String.class, this, StudentPackage.PARAMS);
		}
		return studeents;


Now I can add duplicates as I wanted but the issue that the duplicates will have same index.
Kindly find the attached example.

I have managed it previously by changing the type of generated EList to EObjectEList.
However you have mentioned that I can create specialized List,are there any workarounds that make me to achieve what I need,indexes not repeated, without I change the type of this property at EMF.
my emf is like:

class Students extends common.Identifiable {
  attr String text;
  !unique attr String[*] grades;
}
Re: How to set duplicates at EList [message #1033465 is a reply to message #1033412] Thu, 04 April 2013 08:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Fatla,

Comments below.

On 04/04/2013 9:58 AM, Fatla 777 wrote:
> I have managed as you said and handled @EMF.
>
> Now the generated code @StudentImpl
>
> if (studeents== null) {
> studeents= new EDataTypeEList<String>(String.class, this, StudentPackage.PARAMS);
> }
> return studeents;
>
> Now I can add duplicates as I wanted but the issue that the duplicates will have same index.
How you are determining the index?
> Kindly find the attached example.
>
> I have managed it previously by changing the type of generated EList to EObjectEList.
I don't understand this point.
> However you have mentioned that I can create specialized List,are there any workarounds that make me to achieve what I need,indexes not repeated, without I change the type of this property at EMF.
You've not explained how you compute indices. Clearly if you allow
duplicates you'll need to be more careful not just to use List.indexOf
because that will always find the first one.
> my emf is like:
>
> class Students extends common.Identifiable {
> attr String text;
> !unique attr String[*] grades;
> }


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to set duplicates at EList [message #1034653 is a reply to message #1033465] Fri, 05 April 2013 18:20 Go to previous messageGo to next message
Fatla 777 is currently offline Fatla 777Friend
Messages: 13
Registered: April 2013
Junior Member
Hello Ed,

Regarding indices rendering,
here is how I render it:

tableViewerColumn.setLabelProvider(new ColumnLabelProvider() {
			
      public String getText(Object object) {
//EmployeeNames is list of String
	return String.valueOf(company.getEmployeeNames().indexOf(object)+ 1);
			}
    });


By this approach it will always return the first index.
I h don't have the luxury to alter the emf file and change the types.
Can give me a hint to handle this index issue!

Thanks Ed.

Re: How to set duplicates at EList [message #1034954 is a reply to message #1034653] Sat, 06 April 2013 05:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Fatla,

Comments below.

On 05/04/2013 8:20 PM, Fatla 777 wrote:
> Hello Ed,
>
> Regarding indices rendering, here is how I render it:
>
> tableViewerColumn.setLabelProvider(new ColumnLabelProvider() {
>
> public String getText(Object object) {
> //EmployeeNames is list of String
> return String.valueOf(company.getEmployeeNames().indexOf(object)+ 1);
> }
> });
>
>
> By this approach it will always return the first index.
This actually isn't an EMF question anymore. Of course that's what it
does. Even if you iterated over the list yourself and used == to test
they might even be the same string instance, though probably not...
> I h don't have the luxury to alter the emf file and change the types.
Perhaps you'll have to consider using some type of wrapper object in
this view to uniquely identify the string's index.
> Can give me a hint to handle this index issue!
>
> Thanks Ed.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to set duplicates at EList [message #1035133 is a reply to message #1034954] Sat, 06 April 2013 11:17 Go to previous messageGo to next message
Fatla 777 is currently offline Fatla 777Friend
Messages: 13
Registered: April 2013
Junior Member
Thanks Ed for you assistance.
I have found out this solution over other forum.
Here is the solution for my issue, in case someone was following up the thread:


 TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
 tableViewerColumn.setLabelProvider(new ColumnLabelProvider() {

     public String getText(Object object) {
         int index = 1;
         for (String employee : company.getEmployeeNames()) {
             if (employee == object) 
                 return String.valueOf(index);
             index++;
         }
         return "";
     }
});
Re: How to set duplicates at EList [message #1035144 is a reply to message #1035133] Sat, 06 April 2013 11:33 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Fatla,

Comments below.

On 06/04/2013 1:17 PM, Fatla 777 wrote:
> Thanks Ed for you assistance.
> I have found out this solution over other forum.
> Here is the solution for my issue, in case someone was following up
> the thread:
>
>
> TableViewerColumn tableViewerColumn = new
> TableViewerColumn(tableViewer, SWT.NONE);
> tableViewerColumn.setLabelProvider(new ColumnLabelProvider() {
>
> public String getText(Object object) {
> int index = 1;
> for (String employee : company.getEmployeeNames()) {
> if (employee == object) return
> String.valueOf(index);
So you have two identical string instances in this list?
> index++;
> }
> return "";
> }
> });


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:CDO MappingStrategy example and CDO Questions.
Next Topic:CDO server client connectivity via lan connected system
Goto Forum:
  


Current Time: Tue Mar 19 05:45:48 GMT 2024

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

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

Back to the top