-// $Id$
/**
* Copyright (C) 2016 EDIT
* European Distributed Institute of Taxonomy
*/
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
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;
protected TextWithLabelElement element_Label;
protected TextWithLabelElement element_abbrevLabel;
+ protected TextWithLabelElement element_plural;
protected TextWithLabelElement element_text;
protected Button button;
-
+
protected Representation selectedRepresentation;
protected TermBase term;
private Button removeRepresentation;
- // protected final boolean isTranslationWizard;
-
-
- /**
- * <p>
- * Constructor for MultilanguageTextElement.
- * </p>
- *
- * @param formFactory
- * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
- * object.
- * @param formElement
- * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
- * object.
- *
- * @param term
- * a {@link eu.etaxonomy.cdm.model.common.TermBase} object.
- * @param textHeight
- * a {@link java.lang.Integer} object.
- * @param style
- * a int.
- */
public RepresentationElement(CdmFormFactory formFactory,
ICdmFormElement formElement, TermBase term,
Integer textHeight, int style, boolean fill) {
- super(formFactory, formElement);
-
- formFactory.addPropertyChangeListener(this);
-
- element_Label = this.formFactory.createTextWithLabelElement(formElement, "Label", null, style);
- element_abbrevLabel = this.formFactory
- .createTextWithLabelElement(formElement, "abbrev. Label",
- null, style);
- element_text = this.formFactory.createMultiLineTextWithLabel(formElement, "Description", textHeight, style);
- if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
- createRepresentationEditingElements(formElement, style);
- }
- setTerm(term, fill);
-
+ this(formFactory, formElement, null, term, textHeight, style, fill);
}
- /**
- * <p>
- * Constructor for MultilanguageTextElement.
- * </p>
- *
- * @param formFactory
- * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
- * object.
- * @param formElement
- * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
- * object.
- * @param representation
- * a {@link eu.etaxonomy.cdm.model.common.Representation} object.
- * @param term
- * a {@link eu.etaxonomy.cdm.model.common.TermBase} object.
- * @param textHeight
- * a {@link java.lang.Integer} object.
- * @param style
- * a int.
- */
public RepresentationElement(CdmFormFactory formFactory,
ICdmFormElement formElement, Representation representation, TermBase term,
Integer textHeight, int style, boolean fill) {
formFactory.addPropertyChangeListener(this);
element_Label = this.formFactory.createTextWithLabelElement(formElement, "Label", null, style);
- element_abbrevLabel = this.formFactory
- .createTextWithLabelElement(formElement, "abbrev. Label",
- null, style);
+ element_abbrevLabel = this.formFactory.createTextWithLabelElement(formElement, "abbrev. Label", null, style);
+ element_plural = this.formFactory.createTextWithLabelElement(formElement, "Plural", null, style);
element_text = this.formFactory.createMultiLineTextWithLabel(formElement, "Description", textHeight, style);
if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
createRepresentationEditingElements(formElement, style);
}
setTerm(term, fill);
- setSelectedRepresentation(representation);
-
+ if(representation!=null){
+ setSelectedRepresentation(representation);
+ }
}
removeRepresentation.setToolTipText("Remove representation");
removeRepresentation.addSelectionListener(new DeleteListener(this));
addControl(removeRepresentation);
-
+
combo_language = formFactory.createDefinedTermComboElement(TermType.Language, formElement,
"", null, false, style);
- combo_language.addSelectionListener(this);
-
- //addControl(formFactory.createLabel(getLayoutComposite(), ""));
}
public List<Language> getLanguages() {
return languageList;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt
- * .events.SelectionEvent)
- */
- /** {@inheritDoc} */
- @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_text.setText(selectedRepresentation.getDescription());
-
- }else {
-
- element_Label.setEnabled(false);
- element_abbrevLabel.setEnabled(false);
- element_text.setEnabled(false);
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse
- * .swt.events.SelectionEvent)
- */
- /** {@inheritDoc} */
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- /**
- * <p>
- * Setter for the field <code>multilanguageText</code>.
- * </p>
- *
- * @param multilanguageText
- * the multilanguageText to set
- */
public void setTerm(
TermBase term, boolean update) {
this.term = term;
if (selectedRepresentation != null) {
combo_language.setTerms(getLanguages());
-
+
} else{
- element_Label.setEnabled(false);
- element_abbrevLabel.setEnabled(false);
- element_text.setEnabled(false);
+ setEnabledControls(false);
if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
removeRepresentation.setEnabled(false);
}
}
}
- /**
- *
- */
+ private void setEnabledControls(boolean enabled){
+ element_Label.setEnabled(enabled);
+ element_abbrevLabel.setEnabled(enabled);
+ element_plural.setEnabled(enabled);
+ element_text.setEnabled(enabled);
+ }
+
protected void updateControls() {
Representation preferredRepresentation = term
.getPreferredRepresentation(PreferencesUtil.getGlobalLanguage() );
- element_Label.setText(preferredRepresentation.getLabel());
- element_abbrevLabel.setText(preferredRepresentation.getAbbreviatedLabel());
- 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());
boolean removePossible = term.getRepresentations().size() > 1 ;
removeRepresentation.setEnabled(removePossible);
-
+
}
}
- /**
- * <p>
- * Getter for the field <code>multilanguageText</code>.
- * </p>
- *
- * @return the multilanguageText
- */
public TermBase getTerm() {
return term;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
- * .eclipse.jface.util.PropertyChangeEvent)
- */
- /** {@inheritDoc} */
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event == null) {
.getText();
selectedRepresentation.setAbbreviatedLabel(abbrevLabel);
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
+ }
+ else if (eventSource == element_plural){
+ String plural = ((TextWithLabelElement) eventSource)
+ .getText();
+ selectedRepresentation.setPlural(plural);
+ firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
} else if (eventSource == element_Label){
String label = ((TextWithLabelElement) eventSource)
.getText();
} else if (eventSource == button){
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
} else if (eventSource == combo_language){
- if (combo_language.getSelection() != null){
- element_Label.setEnabled(true);
- element_abbrevLabel.setEnabled(true);
- element_text.setEnabled(true);
- boolean removePossible = term.getRepresentations().size() > 1 ;
- removeRepresentation.setEnabled(removePossible);
- } else{
- element_Label.setEnabled(false);
- element_abbrevLabel.setEnabled(false);
- element_text.setEnabled(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));
}
}
- /**
- * @return the selectedRepresentation
- */
public Representation getSelectedRepresentation() {
return selectedRepresentation;
}
- /**
- * @param selectedRepresentation the selectedRepresentation to set
- */
public void setSelectedRepresentation(Representation selectedRepresentation) {
if (selectedRepresentation == null){
selectedRepresentation = Representation.NewInstance("", "", "", null);
}
this.selectedRepresentation = selectedRepresentation;
}
-
+
private class DeleteListener extends SelectionAdapter {
private final RepresentationElement element;