1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.section.name;
|
12
|
|
13
|
import java.net.URI;
|
14
|
|
15
|
import org.eclipse.swt.events.SelectionListener;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
18
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
19
|
import eu.etaxonomy.cdm.model.media.Media;
|
20
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
21
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
22
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
23
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
33
|
|
34
|
/**
|
35
|
* <p>ProtologueElement class.</p>
|
36
|
*
|
37
|
* @author n.hoffmann
|
38
|
* @created Nov 5, 2009
|
39
|
* @version 1.0
|
40
|
*/
|
41
|
public class ProtologueElement extends AbstractEntityCollectionElement<DescriptionElementBase> implements ISelectableElement, IOpenUrlEnabled{
|
42
|
|
43
|
private final SelectionArbitrator selectionArbitrator;
|
44
|
|
45
|
private UriWithLabelElement protologueUriText;
|
46
|
private MediaRepresentationPart mediaRepresentationPart;
|
47
|
private Media media;
|
48
|
private MediaRepresentation mediaRepresentation;
|
49
|
|
50
|
/**
|
51
|
* <p>Constructor for ProtologueElement.</p>
|
52
|
*
|
53
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
54
|
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
|
55
|
* @param style a int.
|
56
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
57
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
|
58
|
*/
|
59
|
public ProtologueElement(CdmFormFactory cdmFormFactory, AbstractFormSection formElement, DescriptionElementBase element,
|
60
|
SelectionListener removeListener, int style) {
|
61
|
super(cdmFormFactory, formElement, element, removeListener, null, style);
|
62
|
selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
|
63
|
}
|
64
|
|
65
|
/** {@inheritDoc} */
|
66
|
@Override
|
67
|
public void createControls(ICdmFormElement element, int style) {
|
68
|
protologueUriText = formFactory.createUriWithLabelElement(element, "Protologue URI", null, style);
|
69
|
|
70
|
formFactory.createOpenUrlSelectorElement(element, "Query BHL for Reference Image", this, style);
|
71
|
}
|
72
|
|
73
|
/** {@inheritDoc} */
|
74
|
@Override
|
75
|
public void setEntity(DescriptionElementBase element) {
|
76
|
this.entity = element;
|
77
|
|
78
|
if(element.getMedia().size() == 0){
|
79
|
element.addMedia(Media.NewInstance());
|
80
|
}
|
81
|
media = element.getMedia().iterator().next();
|
82
|
|
83
|
if(media.getRepresentations().size() == 0){
|
84
|
media.addRepresentation(MediaRepresentation.NewInstance());
|
85
|
}
|
86
|
mediaRepresentation = media.getRepresentations().iterator().next();
|
87
|
|
88
|
if(mediaRepresentation.getParts().size() == 0){
|
89
|
mediaRepresentation.addRepresentationPart(MediaRepresentationPart.NewInstance(null, null));
|
90
|
}
|
91
|
|
92
|
mediaRepresentationPart = mediaRepresentation.getParts().iterator().next();
|
93
|
|
94
|
if(mediaRepresentationPart.getUri() != null){
|
95
|
protologueUriText.setText(mediaRepresentationPart.getUri().toString());
|
96
|
}
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* <p>Getter for the field <code>selectionArbitrator</code>.</p>
|
101
|
*
|
102
|
* @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
|
103
|
*/
|
104
|
@Override
|
105
|
public SelectionArbitrator getSelectionArbitrator() {
|
106
|
return selectionArbitrator;
|
107
|
}
|
108
|
|
109
|
/** {@inheritDoc} */
|
110
|
@Override
|
111
|
public void handleEvent(Object eventSource) {
|
112
|
if(eventSource == protologueUriText && protologueUriText.getText()!=null){
|
113
|
mediaRepresentationPart.setUri(protologueUriText.parseText());
|
114
|
}
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public void setOpenUrl(URI uri) {
|
119
|
protologueUriText.setText(uri.toString());
|
120
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(protologueUriText, null));
|
121
|
}
|
122
|
|
123
|
@Override
|
124
|
public Reference getReference() {
|
125
|
return (Reference) getName().getNomenclaturalReference();
|
126
|
}
|
127
|
|
128
|
@Override
|
129
|
public String getDetail() {
|
130
|
return getName().getNomenclaturalMicroReference();
|
131
|
}
|
132
|
|
133
|
private TaxonNameBase getName(){
|
134
|
TaxonNameDescription description = (TaxonNameDescription) entity.getInDescription();
|
135
|
|
136
|
TaxonNameBase taxonName = description.getTaxonName();
|
137
|
|
138
|
return taxonName;
|
139
|
}
|
140
|
}
|