1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.ui.section.common;
|
10
|
|
11
|
import org.eclipse.swt.SWT;
|
12
|
import org.eclipse.swt.events.SelectionListener;
|
13
|
|
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;
|
23
|
|
24
|
/**
|
25
|
* @author k.luther
|
26
|
* @since 23.08.2018
|
27
|
*
|
28
|
*/
|
29
|
public class ExternalLinksElement extends AbstractEntityCollectionElement<ExternalLink> implements ISelectableElement{
|
30
|
|
31
|
private SelectionArbitrator selectionArbitrator;
|
32
|
|
33
|
private UriWithLabelElement externalLinkUriText;
|
34
|
private MultilanguageTextElement description;
|
35
|
private boolean isShowDescription = true;
|
36
|
|
37
|
|
38
|
|
39
|
/**
|
40
|
* @param formFactory
|
41
|
* @param section
|
42
|
* @param entity
|
43
|
* @param removeListener
|
44
|
* @param style
|
45
|
*/
|
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);
|
51
|
}
|
52
|
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* @param formFactory
|
57
|
* @param section
|
58
|
* @param entity
|
59
|
* @param removeListener
|
60
|
* @param style
|
61
|
*/
|
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);
|
67
|
}
|
68
|
this.isShowDescription = isWithTypeAndDesc;
|
69
|
setEntity(entity);
|
70
|
|
71
|
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public SelectionArbitrator getSelectionArbitrator() {
|
76
|
|
77
|
return selectionArbitrator;
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public void setEntity(ExternalLink entity) {
|
82
|
this.entity = entity;
|
83
|
if (externalLinkUriText != null){
|
84
|
if (entity.getUri() != null){
|
85
|
externalLinkUriText.setText(entity.getUri().toString());
|
86
|
}
|
87
|
|
88
|
if (entity.getDescription() != null && isShowDescription) {
|
89
|
if (description == null){
|
90
|
description = formFactory.createMultiLanguageTextElement(this, "Description", null, 50, SWT.NULL);
|
91
|
}
|
92
|
description.setMultilanguageText(entity.getDescription());
|
93
|
}
|
94
|
}
|
95
|
}
|
96
|
|
97
|
@Override
|
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);
|
102
|
}
|
103
|
}
|
104
|
|
105
|
@Override
|
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));
|
112
|
|
113
|
}
|
114
|
|
115
|
}
|
116
|
|
117
|
|
118
|
|
119
|
}
|