import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.common.Representation;
-import eu.etaxonomy.cdm.model.common.TermBase;
-import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.term.Representation;
+import eu.etaxonomy.cdm.model.term.TermBase;
+import eu.etaxonomy.cdm.model.term.TermType;
import eu.etaxonomy.taxeditor.model.DefaultTermComparator;
import eu.etaxonomy.taxeditor.model.ImageResources;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
-public class RepresentationElement extends AbstractCdmFormElement implements
-SelectionListener{
+public class RepresentationElement extends AbstractCdmFormElement {
protected TermComboElement<Language> combo_language;
combo_language = formFactory.createDefinedTermComboElement(TermType.Language, formElement,
"", null, false, style);
- combo_language.addSelectionListener(this);
-
}
public List<Language> getLanguages() {
return languageList;
}
- @Override
- public void widgetSelected(SelectionEvent e) {
- Language selectedLanguage = combo_language.getSelection();
- if (selectedLanguage != null) {
- selectedRepresentation = getTerm().getRepresentation(
- selectedLanguage);
- if (selectedRepresentation == null){
- selectedRepresentation = Representation.NewInstance("", "", "", selectedLanguage);
- }
- element_Label.setText(selectedRepresentation.getLabel());
- element_abbrevLabel.setText(selectedRepresentation.getAbbreviatedLabel());
- element_plural.setText(selectedRepresentation.getPlural());
- element_text.setText(selectedRepresentation.getDescription());
-
- }else {
-
- element_Label.setEnabled(false);
- element_abbrevLabel.setEnabled(false);
- element_plural.setEnabled(false);
- element_text.setEnabled(false);
- }
-
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
public void setTerm(
TermBase term, boolean update) {
this.term = term;
Representation preferredRepresentation = term
.getPreferredRepresentation(PreferencesUtil.getGlobalLanguage() );
- element_Label.setText(preferredRepresentation.getLabel());
- element_abbrevLabel.setText(preferredRepresentation.getAbbreviatedLabel());
- element_plural.setText(preferredRepresentation.getPlural());
- element_text.setText(preferredRepresentation.getDescription());
+ element_Label.setText(preferredRepresentation != null? preferredRepresentation.getLabel(): null);
+ element_abbrevLabel.setText(preferredRepresentation != null? preferredRepresentation.getAbbreviatedLabel(): null);
+ element_plural.setText(preferredRepresentation != null? preferredRepresentation.getPlural(): null);
+ element_text.setText(preferredRepresentation != null? preferredRepresentation.getDescription(): null);
selectedRepresentation = preferredRepresentation;
if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
combo_language.setSelection(preferredRepresentation == null?CdmStore.getDefaultLanguage():preferredRepresentation.getLanguage());
} else if (eventSource == button){
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
} else if (eventSource == combo_language){
- if (combo_language.getSelection() != null){
- setEnabledControls(true);
- boolean removePossible = term.getRepresentations().size() > 1 ;
- removeRepresentation.setEnabled(removePossible);
- } else{
- setEnabledControls(false);
- removeRepresentation.setEnabled(false);
- }
- firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
+ if (combo_language.getSelection() != null){
+ setEnabledControls(true);
+ boolean removePossible = term.getRepresentations().size() > 1 ;
+ removeRepresentation.setEnabled(removePossible);
+
+ Language selectedLanguage = combo_language.getSelection();
+ if (selectedLanguage != null) {
+ selectedRepresentation = getTerm().getRepresentation(selectedLanguage);
+ if (selectedRepresentation == null){
+ selectedRepresentation = Representation.NewInstance("", "", "", selectedLanguage);
+ }
+ element_Label.setText(selectedRepresentation.getLabel());
+ element_abbrevLabel.setText(selectedRepresentation.getAbbreviatedLabel());
+ element_plural.setText(selectedRepresentation.getPlural());
+ element_text.setText(selectedRepresentation.getDescription());
+
+ }else {
+ setEnabledControls(false);
+ }
+ } else{
+ setEnabledControls(false);
+ removeRepresentation.setEnabled(false);
+ }
+ firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
}
}