Revision 414b03e6
Added by Katja Luther about 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/common/ExternalLinksElement.java | ||
---|---|---|
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 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/common/ExternalLinksSection.java | ||
---|---|---|
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 java.util.Collection; |
|
12 |
import java.util.Comparator; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
15 |
import eu.etaxonomy.cdm.model.common.OriginalSourceBase; |
|
16 |
import eu.etaxonomy.cdm.model.media.ExternalLink; |
|
17 |
import eu.etaxonomy.cdm.model.media.ExternalLinkType; |
|
18 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
|
19 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
|
20 |
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection; |
|
21 |
|
|
22 |
/** |
|
23 |
* @author k.luther |
|
24 |
* @since 23.08.2018 |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class ExternalLinksSection extends AbstractEntityCollectionSection<OriginalSourceBase, ExternalLink> { |
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
/** |
|
32 |
* @param formFactory |
|
33 |
* @param formElement |
|
34 |
*/ |
|
35 |
public ExternalLinksSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style) { |
|
36 |
super(cdmFormFactory, conversation, parentElement, "External links", style); |
|
37 |
|
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
@Override |
|
42 |
public Comparator<ExternalLink> getComparator() { |
|
43 |
return new Comparator<ExternalLink>(){ |
|
44 |
|
|
45 |
@Override |
|
46 |
public int compare(ExternalLink o1, ExternalLink o2) { |
|
47 |
if (o1 == o2){ |
|
48 |
return 0; |
|
49 |
} |
|
50 |
if (o1 == null){ |
|
51 |
return -1; |
|
52 |
|
|
53 |
} |
|
54 |
if (o2== null){ |
|
55 |
return 1; |
|
56 |
} |
|
57 |
if (o1.getUri() == o1.getUri()){ |
|
58 |
return 0; |
|
59 |
} |
|
60 |
if (o1.getUri() == null){ |
|
61 |
return -1; |
|
62 |
} |
|
63 |
if (o2.getUri() == null){ |
|
64 |
return 1; |
|
65 |
} |
|
66 |
return o1.getUri().toString().compareTo(o2.getUri().toString()); |
|
67 |
|
|
68 |
} |
|
69 |
|
|
70 |
}; |
|
71 |
|
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
@Override |
|
77 |
public Collection<ExternalLink> getCollection(OriginalSourceBase entity) { |
|
78 |
if (entity != null){ |
|
79 |
return entity.getLinks(); |
|
80 |
} else { |
|
81 |
return null; |
|
82 |
} |
|
83 |
|
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public ExternalLink createNewElement() { |
|
88 |
ExternalLink link = ExternalLink.NewInstance(ExternalLinkType.Unknown, null); |
|
89 |
return link; |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public void addElement(ExternalLink element) { |
|
94 |
getEntity().addLink(element); |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public ExternalLink addExisting() { |
|
100 |
return null; |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public boolean allowAddExisting() { |
|
105 |
return false; |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public void removeElement(ExternalLink element) { |
|
110 |
getEntity().removeLink(element); |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public String getEmptyString() { |
|
116 |
return "No external link yet."; |
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
@Override |
|
121 |
protected String getTooltipString() { |
|
122 |
return null; |
|
123 |
} |
|
124 |
|
|
125 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/supplemental/AbstractOriginalSourceElement.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import org.eclipse.swt.SWT; |
15 | 15 |
import org.eclipse.swt.events.SelectionListener; |
16 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
|
16 | 17 |
|
17 | 18 |
import eu.etaxonomy.cdm.model.common.OriginalSourceBase; |
18 | 19 |
import eu.etaxonomy.cdm.model.common.OriginalSourceType; |
... | ... | |
20 | 21 |
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection; |
21 | 22 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
22 | 23 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
24 |
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants; |
|
23 | 25 |
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement; |
26 |
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection; |
|
24 | 27 |
|
25 | 28 |
/** |
26 | 29 |
* @author n.hoffmann |
... | ... | |
33 | 36 |
protected TextWithLabelElement text_idNamespace; |
34 | 37 |
protected TextWithLabelElement text_originaleNameString; |
35 | 38 |
|
39 |
protected ExternalLinksSection externalLinks; |
|
40 |
|
|
36 | 41 |
public AbstractOriginalSourceElement(CdmFormFactory formFactory, |
37 | 42 |
AbstractFormSection section, |
38 | 43 |
T element, SelectionListener removeListener, |
... | ... | |
47 | 52 |
public void setEntity(T entity) { |
48 | 53 |
super.setEntity(entity); |
49 | 54 |
text_originaleNameString.setText(entity.getOriginalNameString()); |
55 |
externalLinks.setEntity(entity); |
|
50 | 56 |
} |
51 | 57 |
|
52 |
/** {@inheritDoc} */ |
|
58 |
/** {@inheritDoc} |
|
59 |
* @wbp.parser.entryPoint*/ |
|
53 | 60 |
@Override |
54 | 61 |
public void createControls(ICdmFormElement formElement, int style) { |
55 | 62 |
combo_origsourcetype = formFactory |
... | ... | |
60 | 67 |
text_idNamespace = formFactory.createTextWithLabelElement(formElement, "ID Namespace", null, style); |
61 | 68 |
text_originaleNameString = formFactory.createTextWithLabelElement( |
62 | 69 |
formElement, "Original Name", null, SWT.NULL); |
70 |
externalLinks = formFactory.createExternalLinksSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE); |
|
71 |
externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
|
72 |
|
|
63 | 73 |
} |
64 | 74 |
|
65 | 75 |
/** |
Also available in: Unified diff
ref #7415: add external link section to original source part