Revision 52d904ba
Added by Katja Luther almost 3 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/ProtologueElement.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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 |
|
|
10 |
package eu.etaxonomy.taxeditor.ui.section.name; |
|
11 |
|
|
12 |
import java.net.URI; |
|
13 |
|
|
14 |
import org.eclipse.swt.events.SelectionListener; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
17 |
import eu.etaxonomy.cdm.model.description.TaxonNameDescription; |
|
18 |
import eu.etaxonomy.cdm.model.media.Media; |
|
19 |
import eu.etaxonomy.cdm.model.media.MediaRepresentation; |
|
20 |
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart; |
|
21 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
22 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
23 |
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection; |
|
24 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
|
25 |
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent; |
|
26 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
|
27 |
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement; |
|
28 |
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator; |
|
29 |
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement; |
|
30 |
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled; |
|
31 |
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement; |
|
32 |
|
|
33 |
/** |
|
34 |
* <p>ProtologueElement class.</p> |
|
35 |
* |
|
36 |
* @author n.hoffmann |
|
37 |
* @created Nov 5, 2009 |
|
38 |
* @version 1.0 |
|
39 |
*/ |
|
40 |
public class ProtologueElement extends AbstractEntityCollectionElement<DescriptionElementBase> implements ISelectableElement, IOpenUrlEnabled{ |
|
41 |
|
|
42 |
private final SelectionArbitrator selectionArbitrator; |
|
43 |
|
|
44 |
private UriWithLabelElement protologueUriText; |
|
45 |
private MediaRepresentationPart mediaRepresentationPart; |
|
46 |
private Media media; |
|
47 |
private MediaRepresentation mediaRepresentation; |
|
48 |
|
|
49 |
/** |
|
50 |
* <p>Constructor for ProtologueElement.</p> |
|
51 |
* |
|
52 |
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object. |
|
53 |
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object. |
|
54 |
* @param style a int. |
|
55 |
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object. |
|
56 |
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object. |
|
57 |
*/ |
|
58 |
public ProtologueElement(CdmFormFactory cdmFormFactory, AbstractFormSection<?> formElement, DescriptionElementBase element, |
|
59 |
SelectionListener removeListener, int style) { |
|
60 |
super(cdmFormFactory, formElement, element, removeListener, null, style); |
|
61 |
selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this); |
|
62 |
} |
|
63 |
|
|
64 |
/** {@inheritDoc} */ |
|
65 |
@Override |
|
66 |
public void createControls(ICdmFormElement element, int style) { |
|
67 |
protologueUriText = formFactory.createUriWithLabelElement(element, "Protologue URI", null, style); |
|
68 |
|
|
69 |
formFactory.createOpenUrlSelectorElement(element, "Query BHL for Reference Image", this, style); |
|
70 |
} |
|
71 |
|
|
72 |
/** {@inheritDoc} */ |
|
73 |
@Override |
|
74 |
public void setEntity(DescriptionElementBase element) { |
|
75 |
this.entity = element; |
|
76 |
|
|
77 |
if(element.getMedia().size() == 0){ |
|
78 |
element.addMedia(Media.NewInstance()); |
|
79 |
} |
|
80 |
media = element.getMedia().iterator().next(); |
|
81 |
|
|
82 |
if(media.getRepresentations().size() == 0){ |
|
83 |
media.addRepresentation(MediaRepresentation.NewInstance()); |
|
84 |
} |
|
85 |
mediaRepresentation = media.getRepresentations().iterator().next(); |
|
86 |
|
|
87 |
if(mediaRepresentation.getParts().size() == 0){ |
|
88 |
mediaRepresentation.addRepresentationPart(MediaRepresentationPart.NewInstance(null, null)); |
|
89 |
} |
|
90 |
|
|
91 |
mediaRepresentationPart = mediaRepresentation.getParts().iterator().next(); |
|
92 |
|
|
93 |
if(mediaRepresentationPart.getUri() != null){ |
|
94 |
protologueUriText.setText(mediaRepresentationPart.getUri().toString()); |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* <p>Getter for the field <code>selectionArbitrator</code>.</p> |
|
100 |
* |
|
101 |
* @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object. |
|
102 |
*/ |
|
103 |
@Override |
|
104 |
public SelectionArbitrator getSelectionArbitrator() { |
|
105 |
return selectionArbitrator; |
|
106 |
} |
|
107 |
|
|
108 |
/** {@inheritDoc} */ |
|
109 |
@Override |
|
110 |
public void handleEvent(Object eventSource) { |
|
111 |
if(eventSource == protologueUriText && protologueUriText.getText()!=null){ |
|
112 |
mediaRepresentationPart.setUri(protologueUriText.parseText()); |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public void setOpenUrl(URI uri) { |
|
118 |
protologueUriText.setText(uri.toString()); |
|
119 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(protologueUriText, null)); |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public Reference getReference() { |
|
124 |
return (Reference) getName().getNomenclaturalReference(); |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public String getDetail() { |
|
129 |
return getName().getNomenclaturalMicroReference(); |
|
130 |
} |
|
131 |
|
|
132 |
private TaxonName getName(){ |
|
133 |
TaxonNameDescription description = (TaxonNameDescription) entity.getInDescription(); |
|
134 |
|
|
135 |
TaxonName taxonName = description.getTaxonName(); |
|
136 |
|
|
137 |
return taxonName; |
|
138 |
} |
|
139 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/ProtologueSection.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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 |
|
|
10 |
package eu.etaxonomy.taxeditor.ui.section.name; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.Collection; |
|
14 |
import java.util.Comparator; |
|
15 |
import java.util.List; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
18 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
19 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
20 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
21 |
import eu.etaxonomy.cdm.model.description.TaxonNameDescription; |
|
22 |
import eu.etaxonomy.cdm.model.description.TextData; |
|
23 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
24 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
25 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
|
26 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
|
27 |
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection; |
|
28 |
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator; |
|
29 |
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection; |
|
30 |
|
|
31 |
/** |
|
32 |
* <p>ProtologueSection class.</p> |
|
33 |
* |
|
34 |
* @author n.hoffmann |
|
35 |
* @created Nov 5, 2009 |
|
36 |
*/ |
|
37 |
public class ProtologueSection extends AbstractEntityCollectionSection<TaxonName, DescriptionElementBase> implements ITaxonBaseDetailSection{ |
|
38 |
|
|
39 |
private TaxonBase taxonBase; |
|
40 |
|
|
41 |
/** |
|
42 |
* <p>Constructor for ProtologueSection.</p> |
|
43 |
* |
|
44 |
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object. |
|
45 |
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object. |
|
46 |
* @param style a int. |
|
47 |
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
48 |
*/ |
|
49 |
public ProtologueSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style) { |
|
50 |
super(cdmFormFactory, conversation, parentElement, "Protologues / Original Publications", style); |
|
51 |
} |
|
52 |
|
|
53 |
/** {@inheritDoc} */ |
|
54 |
@Override |
|
55 |
public DescriptionElementBase createNewElement() { |
|
56 |
return TextData.NewInstance(Feature.PROTOLOGUE()); |
|
57 |
} |
|
58 |
|
|
59 |
|
|
60 |
/** {@inheritDoc} */ |
|
61 |
@Override |
|
62 |
public Collection<DescriptionElementBase> getCollection(TaxonName entity) { |
|
63 |
Collection<DescriptionElementBase> result = new ArrayList<>(); |
|
64 |
List<TaxonNameDescription> descriptions = getTaxonNameDescriptions(entity); |
|
65 |
for (TaxonNameDescription desc : descriptions){ |
|
66 |
desc.getElements() |
|
67 |
.stream() |
|
68 |
.filter(element -> element.getFeature().equals(Feature.PROTOLOGUE())) |
|
69 |
.forEach(element -> result.add(element)); |
|
70 |
} |
|
71 |
return result; |
|
72 |
//OLD: return getTaxonNameDescription(entity).getElements(); |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public Comparator<DescriptionElementBase> getComparator() { |
|
77 |
return new DefaultCdmBaseComparator<>(); |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
/** {@inheritDoc} */ |
|
82 |
@Override |
|
83 |
public String getEmptyString() { |
|
84 |
return "No protologues yet."; |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
/** {@inheritDoc} */ |
|
89 |
@Override |
|
90 |
protected String getTooltipString() { |
|
91 |
return "Create a new protologue"; |
|
92 |
} |
|
93 |
|
|
94 |
/** {@inheritDoc} */ |
|
95 |
@Override |
|
96 |
public void addElement(DescriptionElementBase element) { |
|
97 |
//for simplification we always use the first description to add elements here |
|
98 |
getTaxonNameDescription(getEntity()).addElement(element); |
|
99 |
} |
|
100 |
|
|
101 |
/** {@inheritDoc} */ |
|
102 |
@Override |
|
103 |
public void removeElement(DescriptionElementBase element) { |
|
104 |
List<TaxonNameDescription> descriptions = getTaxonNameDescriptions(getEntity()); |
|
105 |
for (TaxonNameDescription desc : descriptions){ |
|
106 |
desc.removeElement(element); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
/** {@inheritDoc} */ |
|
111 |
@Override |
|
112 |
public void setTaxonBase(TaxonBase entity) { |
|
113 |
this.taxonBase = entity; |
|
114 |
TaxonName name = HibernateProxyHelper.deproxy(entity.getName()); |
|
115 |
setEntity(name); |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* NOTE: returns first description |
|
120 |
* @param name |
|
121 |
* @return |
|
122 |
*/ |
|
123 |
private TaxonNameDescription getTaxonNameDescription(TaxonName name){ |
|
124 |
if(name.getDescriptions().size() == 0){ |
|
125 |
name.addDescription(TaxonNameDescription.NewInstance(name)); |
|
126 |
} |
|
127 |
return name.getDescriptions().iterator().next(); |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Try to fix FIXME in {@link #getTaxonNameDescription(TaxonNameBase)} |
|
132 |
* @param name |
|
133 |
* @return |
|
134 |
*/ |
|
135 |
private List<TaxonNameDescription> getTaxonNameDescriptions(TaxonName name){ |
|
136 |
List<TaxonNameDescription> result = new ArrayList<>(); |
|
137 |
if (name == null){ |
|
138 |
return result; |
|
139 |
} |
|
140 |
for (TaxonNameDescription desc : name.getDescriptions()){ |
|
141 |
result.add(desc); |
|
142 |
} |
|
143 |
return result; |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public TaxonBase getTaxonBase() { |
|
148 |
return taxonBase; |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* {@inheritDoc} |
|
153 |
*/ |
|
154 |
@Override |
|
155 |
public DescriptionElementBase addExisting() { |
|
156 |
return null; |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* {@inheritDoc} |
|
161 |
*/ |
|
162 |
@Override |
|
163 |
public boolean allowAddExisting() { |
|
164 |
return false; |
|
165 |
} |
|
166 |
} |
Also available in: Unified diff
remove protologue detail files