-// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.taxeditor.ui.section.description;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.swt.events.SelectionListener;
import eu.etaxonomy.cdm.model.common.DefinedTerm;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.StateData;
+import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
/**
* @version 1.0
*/
public class ModifierElement extends AbstractEntityCollectionElement<DefinedTerm> {
-
+
private TermComboElement<DefinedTerm> combo_modifier;
/**
* @param style a int.
*/
public ModifierElement(CdmFormFactory formFactory,
- AbstractFormSection section, DefinedTerm entity,
+ AbstractFormSection<?> section, DefinedTerm entity,
SelectionListener removeListener, int style) {
super(formFactory, section, entity, removeListener, null, style);
}
-
+
/** {@inheritDoc} */
@Override
public void setEntity(DefinedTerm entity) {
this.entity = entity;
- combo_modifier.setSelection(entity);
+ if(getParentElement() instanceof ModifierSection){
+ ModifierSection parentSection = (ModifierSection) getParentElement();
+ List<DefinedTerm> modifierTerms = new ArrayList<DefinedTerm>();
+ Set<TermVocabulary<DefinedTerm>> recommendedModifierEnumeration = new HashSet<TermVocabulary<DefinedTerm>>();
+ if(parentSection.getEntity() instanceof StateData){
+ StateData stateData = (StateData) parentSection.getEntity();
+ recommendedModifierEnumeration = stateData.getCategoricalData().getFeature().getRecommendedModifierEnumeration();
+ }
+ if(parentSection.getEntity() instanceof StatisticalMeasurementValue){
+ StatisticalMeasurementValue statisticalMeasurementValue = (StatisticalMeasurementValue)parentSection.getEntity();
+ recommendedModifierEnumeration = statisticalMeasurementValue.getQuantitativeData().getFeature().getRecommendedModifierEnumeration();
+ }
+ for (TermVocabulary<DefinedTerm> termVocabulary : recommendedModifierEnumeration) {
+ modifierTerms.addAll(termVocabulary.getTerms());
+ }
+ combo_modifier.setTerms(modifierTerms);
+ }
+ if(entity!=null && entity.getId()>0){
+ combo_modifier.setSelection(entity);
+ combo_modifier.removeEmptyElement();
+ }
}
/** {@inheritDoc} */
@Override
public void createControls(ICdmFormElement element, int style) {
- combo_modifier = formFactory.createTermComboElement(DefinedTerm.class, element, "Modifier", getEntity(), style);
+ combo_modifier = formFactory.createDefinedTermComboElement(TermType.Modifier, element, "Modifier", getEntity(), style);
}
/** {@inheritDoc} */
@Override
public void handleEvent(Object eventSource) {
-
+ if(eventSource==combo_modifier && combo_modifier.getSelection()!=null){
+ combo_modifier.removeEmptyElement();
+ if(getParentElement() instanceof AbstractFormSection){
+ AbstractFormSection<?> parentSection = (AbstractFormSection<?>) getParentElement();
+ if(parentSection.getEntity() instanceof StateData){
+ StateData stateData = (StateData) parentSection.getEntity();
+ stateData.removeModifier(entity);
+ DefinedTerm term = combo_modifier.getSelection();
+ stateData.addModifier(term);
+ entity = term;
+ }
+ else if(parentSection.getEntity() instanceof StatisticalMeasurementValue){
+ StatisticalMeasurementValue parentEntity = (StatisticalMeasurementValue) parentSection.getEntity();
+ parentEntity.removeModifier(entity);
+ DefinedTerm term = combo_modifier.getSelection();
+ parentEntity.addModifier(term);
+ entity = term;
+ }
+ }
+ }
}
}