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