3 * Copyright (C) 2016 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.element
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.Collections
;
21 import java
.util
.List
;
23 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
24 import org
.eclipse
.swt
.events
.SelectionEvent
;
25 import org
.eclipse
.swt
.events
.SelectionListener
;
26 import org
.eclipse
.swt
.widgets
.Button
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
30 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
32 import eu
.etaxonomy
.taxeditor
.model
.DefaultTermComparator
;
33 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
37 public class RepresentationElement
extends AbstractCdmFormElement
implements
40 protected TermComboElement
<Language
> combo_language
;
42 protected TextWithLabelElement element_Label
;
43 protected TextWithLabelElement element_abbrevLabel
;
44 protected TextWithLabelElement element_text
;
46 protected Button button
;
48 protected Representation selectedRepresentation
;
49 protected TermBase term
;
51 // protected final boolean isTranslationWizard;
56 * Constructor for MultilanguageTextElement.
60 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
63 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
67 * a {@link eu.etaxonomy.cdm.model.common.TermBase} object.
69 * a {@link java.lang.Integer} object.
73 public RepresentationElement(CdmFormFactory formFactory
,
74 ICdmFormElement formElement
, TermBase term
,
75 Integer textHeight
, int style
) {
76 super(formFactory
, formElement
);
78 formFactory
.addPropertyChangeListener(this);
80 element_Label
= this.formFactory
.createTextWithLabelElement(formElement
, "Label", null, style
);
81 element_abbrevLabel
= this.formFactory
82 .createTextWithLabelElement(formElement
, "abbrev. Label",
84 element_text
= this.formFactory
.createMultiLineTextWithLabel(formElement
, "Description", textHeight
, style
);
85 if (PreferencesUtil
.isMultilanguageTextEditingCapability()) {
86 createRepresentationEditingElements(formElement
, style
);
94 * Constructor for MultilanguageTextElement.
98 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
101 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
103 * @param representation
104 * a {@link eu.etaxonomy.cdm.model.common.Representation} object.
106 * a {@link eu.etaxonomy.cdm.model.common.TermBase} object.
108 * a {@link java.lang.Integer} object.
112 public RepresentationElement(CdmFormFactory formFactory
,
113 ICdmFormElement formElement
, Representation representation
, TermBase term
,
114 Integer textHeight
, int style
) {
115 super(formFactory
, formElement
);
117 formFactory
.addPropertyChangeListener(this);
119 element_Label
= this.formFactory
.createTextWithLabelElement(formElement
, "Label", null, style
);
120 element_abbrevLabel
= this.formFactory
121 .createTextWithLabelElement(formElement
, "abbrev. Label",
123 element_text
= this.formFactory
.createMultiLineTextWithLabel(formElement
, "Description", textHeight
, style
);
124 if (PreferencesUtil
.isMultilanguageTextEditingCapability()) {
125 createRepresentationEditingElements(formElement
, style
);
128 setSelectedRepresentation(representation
);
133 protected void createRepresentationEditingElements(
134 ICdmFormElement formElement
, int style
) {
136 combo_language
= formFactory
.createDefinedTermComboElement(TermType
.Language
, formElement
,
138 combo_language
.addSelectionListener(this);
140 addControl(formFactory
.createLabel(getLayoutComposite(), ""));
145 public List
<Language
> getLanguages() {
147 ArrayList
<Language
> languageList
= new ArrayList
<Language
>();
148 for (Representation rep
: term
.getRepresentations()){
149 languageList
.add(rep
.getLanguage());
152 Collections
.sort(languageList
, new DefaultTermComparator
<Language
>());
161 * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt
162 * .events.SelectionEvent)
166 public void widgetSelected(SelectionEvent e
) {
167 Language selectedLanguage
= combo_language
.getSelection();
168 if (selectedLanguage
!= null) {
169 selectedRepresentation
= getTerm().getRepresentation(
171 if (selectedRepresentation
== null){
172 selectedRepresentation
= Representation
.NewInstance("", "", "", selectedLanguage
);
174 element_Label
.setText(selectedRepresentation
.getLabel());
175 element_abbrevLabel
.setText(selectedRepresentation
.getAbbreviatedLabel());
176 element_text
.setText(selectedRepresentation
.getDescription());
186 * org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse
187 * .swt.events.SelectionEvent)
191 public void widgetDefaultSelected(SelectionEvent e
) {
196 * Setter for the field <code>multilanguageText</code>.
199 * @param multilanguageText
200 * the multilanguageText to set
206 if (selectedRepresentation
!= null) {
207 combo_language
.setTerms(getLanguages());
215 protected void updateControls() {
216 Representation preferredRepresentation
= term
217 .getPreferredRepresentation(Arrays
.asList(new Language
[] { CdmStore
218 .getDefaultLanguage() }));
220 element_Label
.setText(preferredRepresentation
.getLabel());
221 element_abbrevLabel
.setText(preferredRepresentation
.getAbbreviatedLabel());
222 element_text
.setText(preferredRepresentation
.getDescription());
223 selectedRepresentation
= preferredRepresentation
;
224 if (PreferencesUtil
.isMultilanguageTextEditingCapability()) {
225 combo_language
.setSelection(preferredRepresentation
== null?CdmStore
.getDefaultLanguage():preferredRepresentation
.getLanguage());
231 * Getter for the field <code>multilanguageText</code>.
234 * @return the multilanguageText
236 public TermBase
getTerm() {
244 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
245 * .eclipse.jface.util.PropertyChangeEvent)
249 public void propertyChange(PropertyChangeEvent event
) {
253 Object eventSource
= event
.getSource();
255 if (eventSource
== element_abbrevLabel
) {
256 String abbrevLabel
= ((TextWithLabelElement
) eventSource
)
258 selectedRepresentation
.setAbbreviatedLabel(abbrevLabel
);
259 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event
));
260 } else if (eventSource
== element_Label
){
261 String label
= ((TextWithLabelElement
) eventSource
)
263 selectedRepresentation
.setLabel(label
);
264 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event
));
265 } else if (eventSource
== element_text
){
266 String text
= ((TextWithLabelElement
) eventSource
)
268 selectedRepresentation
.setText(text
);
269 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event
));
274 * @return the selectedRepresentation
276 public Representation
getSelectedRepresentation() {
277 return selectedRepresentation
;
281 * @param selectedRepresentation the selectedRepresentation to set
283 public void setSelectedRepresentation(Representation selectedRepresentation
) {
284 if (selectedRepresentation
== null){
285 selectedRepresentation
= Representation
.NewInstance("", "", "", null);
287 this.selectedRepresentation
= selectedRepresentation
;