Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331894 - Multipopulation: Double entry in combobox
Summary: Multipopulation: Double entry in combobox
Status: CLOSED FIXED
Alias: None
Product: STEM
Classification: Technology
Component: UI (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.1.2   Edit
Assignee: Stefan Edlund CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-06 08:29 EST by Jan-Frederik Wigger CLA
Modified: 2011-07-18 21:43 EDT (History)
0 users

See Also:


Attachments
screenshot of the drop down menu with the populations (92.84 KB, image/jpeg)
2010-12-06 08:33 EST, Jan-Frederik Wigger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan-Frederik Wigger CLA 2010-12-06 08:29:48 EST
Build Identifier: 3.6.0

When creating/importing multiple populations, the drop down menu in the simulation control contains the first population twice (in the example "MultiPopulationExample").
See bug 317079 and attachments.

Reproducible: Always

Steps to Reproduce:
1. Import MultiPopulationExample
2. Start any scenario
3. in Simulation Control, the drop down menu of the populations contains 2x human, 1x anopheles
Comment 1 Jan-Frederik Wigger CLA 2010-12-06 08:32:20 EST
This bug is already mentioned in bug 317079.

It seems that there is a special handling for multiple populations in a "multi-population disease model". 

See
org.eclipse.stem.diseasemodels.multipopulation.provider(MultipopulationPopulationEnumeratorAdapter.java:23) 

public String[] getPopulationIdentifiers() {

MultiPopulationSIDiseaseModel dm = (MultiPopulationSIDiseaseModel)getTarget();
StringValueList list = dm.getPopulationGroups();
EList<org.eclipse.stem.core.common.StringValue> vals = list.getValues();
		
String [] res = new String[vals.size()+1];
res[0] = dm.getPopulationIdentifier();
for(int i=1;i<vals.size()+1;++i)
  res[i] = vals.get(i-1).getValue();
		
return res;
}


The method getPopulationIdentifiers() manually adds the name of the "disease model population" to the array, afterwards adds all population groups of the disease model. 

This possibly creates double entries, as taken into account in
org.eclipse.stem.util.loggers.views(NewCSVLogWriter.java:256 and :463) 

PopulationEnumeratorAdapter en = (PopulationEnumeratorAdapter)PopulationEnumeratorAdapterFactory.INSTANCE.adapt(dm, PopulationEnumerator.class);
if(en != null) {
  en.setTarget(dm);
  String [] pops = en.getPopulationIdentifiers();
  // Skip first one, it's already been added.
  if(pops.length > 1)
    for(int i=1;i<pops.length;++i) 
      populationIdentifiers.add(pops[i]);
}


The first entry is skipped, "it's already been added" (text in comment).

I cannot overlook whether it is still useful/necessary to add a disease model population that is possibly not part of the population groups (if that was the reason for this handling). Suggestions for possible solutions:

---------------------------------------------------------
1.) Avoid double entries in PopulationIdentifiers array:

org.eclipse.stem.diseasemodels.multipopulation.provider(MultipopulationPopulationEnumeratorAdapter.java:23 )

public String[] getPopulationIdentifiers() {
MultiPopulationSIDiseaseModel dm = (MultiPopulationSIDiseaseModel)getTarget();
StringValueList list = dm.getPopulationGroups();
EList<org.eclipse.stem.core.common.StringValue> vals = list.getValues();	
		
java.util.List<String> popIDs = new java.util.ArrayList<String>();
popIDs.add(dm.getPopulationIdentifier());
for(int i=0;i<vals.size();++i)
  if (!popIDs.contains(vals.get(i).getValue()))
    popIDs.add(vals.get(i).getValue());
		
String [] res = new String[popIDs.size()];
for(int i=res.length-1;i>=0;i--)
  res[i] = popIDs.get(i);
		
return res;
}

Because the LogWriter skips the first entry so far:
Delete lines org.eclipse.stem.util.loggers.views(NewCSVLogWriter.java:260-263), change :466 to 
for(int j=1;j<subpops1.length;++j) (?not sure)

------------------------------------------------------

2.)Abandon the special handling completely, replace:
org.eclipse.stem.diseasemodels.multipopulation.provider(MultipopulationPopulationEnumeratorAdapter.java:29) 

String [] res = new String[vals.size()];
for(int i=0;i<vals.size();i++)
 res[i] = vals.get(i).getValue();



Delete lines org.eclipse.stem.util.loggers.views(NewCSVLogWriter.java:260-263), change :466 to 
for(int j=1;j<subpops1.length;++j) (?not sure)

------------------------------------------------------

3.) Keep this special handling, but just do not show in the selection list:
 
org.eclipse.stem.ui.widgets(GeoViewOptionsBar.java:384) 
might need the same check and handling as described above ("Skip first one, it's already been added"). 

if(pea != null) {
pea.setTarget(decorator);
String [] pis = pea.getPopulationIdentifiers();
for (int i=(pis.length > 1)?1:0;i<pis.length;++i)
  popIds.add(pis[i]);
} 


------------------------------------------------------


Problems with 1 and 2: Maybe I do not know all effects that a change of the return array of getPopulationIdentifiers() takes on STEM. 


Jan-Frederik Wigger
Comment 2 Jan-Frederik Wigger CLA 2010-12-06 08:33:05 EST
Created attachment 184596 [details]
screenshot of the drop down menu with the populations
Comment 3 James Kaufman CLA 2010-12-07 14:32:37 EST
Stefan, Is this the bug you fixed yesterday?
Comment 4 Stefan Edlund CLA 2010-12-17 16:55:02 EST
Jan-Frederik, I pretty much followed your first suggestion and that seems to work. Let me know if there's still any problems.

Thanks!
Comment 5 James Kaufman CLA 2011-07-18 21:43:42 EDT
Complete