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.events.SelectionListener;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.media.ExternalLink;
|
14
|
import eu.etaxonomy.cdm.model.media.ExternalLinkType;
|
15
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
16
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
17
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
18
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
19
|
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
24
|
|
25
|
/**
|
26
|
* @author k.luther
|
27
|
* @since 23.08.2018
|
28
|
*
|
29
|
*/
|
30
|
public class ExternalLinksElement extends AbstractEntityCollectionElement<ExternalLink> implements ISelectableElement{
|
31
|
|
32
|
private SelectionArbitrator selectionArbitrator;
|
33
|
|
34
|
private UriWithLabelElement externalLinkUriText;
|
35
|
private EnumComboElement<ExternalLinkType> combo_linkType;
|
36
|
private MultilanguageTextElement description;
|
37
|
|
38
|
|
39
|
|
40
|
/**
|
41
|
* @param formFactory
|
42
|
* @param section
|
43
|
* @param entity
|
44
|
* @param removeListener
|
45
|
* @param style
|
46
|
*/
|
47
|
public ExternalLinksElement(CdmFormFactory formFactory, AbstractFormSection section, ExternalLink entity,
|
48
|
SelectionListener removeListener, int style) {
|
49
|
super(formFactory, section, entity, removeListener, null, style);
|
50
|
if(formFactory.getSelectionProvider() != null){
|
51
|
selectionArbitrator = formFactory.createSelectionArbitrator(this);
|
52
|
}
|
53
|
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public SelectionArbitrator getSelectionArbitrator() {
|
58
|
|
59
|
return selectionArbitrator;
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public void setEntity(ExternalLink entity) {
|
64
|
if (entity.getUri() != null){
|
65
|
externalLinkUriText.setText(entity.getUri().toString());
|
66
|
}
|
67
|
if (entity.getLinkType() != null){
|
68
|
combo_linkType.setSelection(entity.getLinkType());
|
69
|
}
|
70
|
if (entity.getDescription() != null) {
|
71
|
description.setMultilanguageText(entity.getDescription());
|
72
|
// description.setText(entity.getDescription().get(
|
73
|
// CdmStore.getDefaultLanguage()).getText());
|
74
|
}
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public void createControls(ICdmFormElement element, int style) {
|
79
|
|
80
|
combo_linkType = formFactory.createEnumComboElement(ExternalLinkType.class, element, style);
|
81
|
externalLinkUriText = formFactory.createUriWithLabelElement(element, "URI", null, style);
|
82
|
|
83
|
// description = formFactory.createMultiLineTextWithLabel(this, "Description", 50, SWT.WRAP);
|
84
|
description = formFactory.createMultiLanguageTextElement(element, "Description", null, 50, style);
|
85
|
|
86
|
|
87
|
}
|
88
|
|
89
|
@Override
|
90
|
public void handleEvent(Object eventSource) {
|
91
|
if (eventSource.equals(externalLinkUriText)){
|
92
|
getEntity().setUri(externalLinkUriText.parseText());
|
93
|
}else if (eventSource.equals(combo_linkType)){
|
94
|
getEntity().setLinkType(combo_linkType.getSelection());
|
95
|
}else if (eventSource.equals(description)){
|
96
|
description.getMultilanguageText().values()
|
97
|
.forEach(languageString -> getEntity().putDescription(languageString));
|
98
|
|
99
|
}
|
100
|
|
101
|
}
|
102
|
|
103
|
|
104
|
|
105
|
}
|