// $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.List;
+import java.util.Set;
+
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
import eu.etaxonomy.cdm.model.common.LanguageString;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.description.State;
import eu.etaxonomy.cdm.model.description.StateData;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType;
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
/**
* @version 1.0
*/
public class StateDataElement extends AbstractEntityCollectionElement<StateData> {
-
+
private TermComboElement<State> combo_state;
private ModifierSection section_modifiers;
private TextWithLabelElement text_modifyingText;
SelectionListener removeListener, int style) {
super(formFactory, section, entity, removeListener, null, style);
}
-
+
/** {@inheritDoc} */
@Override
public void setEntity(StateData entity) {
this.entity = entity;
+ List<State> stateTerms = new ArrayList<State>();
+ Set<TermVocabulary<State>> stateVocabularies = getEntity().getCategoricalData().getFeature().getSupportedCategoricalEnumerations();
+ for (TermVocabulary<State> termVocabulary : stateVocabularies) {
+ stateTerms.addAll(termVocabulary.getTerms());
+ }
+ combo_state.setTerms(stateTerms);
combo_state.setSelection(entity.getState());
section_modifiers.setEntity(entity);
- if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null)
- text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
+ section_modifiers.setExpanded(!entity.getModifiers().isEmpty());
+ if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
+ text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
+ }
+ if(getEntity().getId()>0){
+ combo_state.removeEmptyElement();
+ }
}
/** {@inheritDoc} */
@Override
public void createControls(ICdmFormElement element, int style) {
- combo_state = formFactory.createTermComboElement(State.class, element, "State", null, style);
- section_modifiers = (ModifierSection) formFactory.createEntityDetailSection(EntityDetailType.MODIFIER, getConversationHolder(), element, Section.TWISTIE);
+ combo_state = formFactory.createDefinedTermComboElement(TermType.State, element, "State", null, style);
+ section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED);
section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
text_modifyingText = formFactory.createTextWithLabelElement(element, "Modifying Text", null, style);
}
public void handleEvent(Object eventSource) {
if(eventSource == combo_state){
getEntity().setState(combo_state.getSelection());
+ combo_state.removeEmptyElement();
}
if(eventSource == text_modifyingText){
getEntity().putModifyingText(LanguageString.NewInstance(text_modifyingText.getText(), CdmStore.getDefaultLanguage()));