2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.common
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.events
.SelectionListener
;
14 import eu
.etaxonomy
.cdm
.model
.media
.ExternalLink
;
15 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
16 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
17 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
18 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
19 import eu
.etaxonomy
.taxeditor
.ui
.element
.MultilanguageTextElement
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.UriWithLabelElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionElement
;
29 public class ExternalLinksElement
extends AbstractEntityCollectionElement
<ExternalLink
> implements ISelectableElement
{
31 private SelectionArbitrator selectionArbitrator
;
33 private UriWithLabelElement externalLinkUriText
;
34 private MultilanguageTextElement description
;
35 private boolean isShowDescription
= true;
43 * @param removeListener
46 public ExternalLinksElement(CdmFormFactory formFactory
, AbstractFormSection section
, ExternalLink entity
,
47 SelectionListener removeListener
, int style
) {
48 super(formFactory
, section
, entity
, removeListener
, null, style
);
49 if(formFactory
.getSelectionProvider() != null){
50 selectionArbitrator
= formFactory
.createSelectionArbitrator(this);
59 * @param removeListener
62 public ExternalLinksElement(CdmFormFactory formFactory
, AbstractFormSection section
, ExternalLink entity
, boolean isWithTypeAndDesc
,
63 SelectionListener removeListener
, int style
) {
64 super(formFactory
, section
, entity
, removeListener
, null, style
);
65 if(formFactory
.getSelectionProvider() != null){
66 selectionArbitrator
= formFactory
.createSelectionArbitrator(this);
68 this.isShowDescription
= isWithTypeAndDesc
;
75 public SelectionArbitrator
getSelectionArbitrator() {
77 return selectionArbitrator
;
81 public void setEntity(ExternalLink entity
) {
83 if (externalLinkUriText
!= null){
84 if (entity
.getUri() != null){
85 externalLinkUriText
.setText(entity
.getUri().toString());
88 if (entity
.getDescription() != null && isShowDescription
) {
89 if (description
== null){
90 description
= formFactory
.createMultiLanguageTextElement(this, "Description", null, 50, SWT
.NULL
);
92 description
.setMultilanguageText(entity
.getDescription());
98 public void createControls(ICdmFormElement element
, int style
) {
99 externalLinkUriText
= formFactory
.createUriWithLabelElement(element
, "URI", null, style
);
100 if(isShowDescription
){
101 description
= formFactory
.createMultiLanguageTextElement(element
, "Description", null, 50, style
);
106 public void handleEvent(Object eventSource
) {
107 if (eventSource
.equals(externalLinkUriText
)){
108 getEntity().setUri(externalLinkUriText
.parseText());
109 }else if (eventSource
.equals(description
)){
110 description
.getMultilanguageText().values()
111 .forEach(languageString
-> getEntity().putDescription(languageString
));