2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
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
;
34 * <p>ProtologueElement class.</p>
37 * @created Nov 5, 2009
40 public class ProtologueElement
extends AbstractEntityCollectionElement
<DescriptionElementBase
> implements ISelectableElement
, IOpenUrlEnabled
{
42 private final SelectionArbitrator selectionArbitrator
;
44 private UriWithLabelElement protologueUriText
;
45 private MediaRepresentationPart mediaRepresentationPart
;
47 private MediaRepresentation mediaRepresentation
;
50 * <p>Constructor for ProtologueElement.</p>
52 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
53 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
55 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
56 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
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);
66 public void createControls(ICdmFormElement element
, int style
) {
67 protologueUriText
= formFactory
.createUriWithLabelElement(element
, "Protologue URI", null, style
);
69 formFactory
.createOpenUrlSelectorElement(element
, "Query BHL for Reference Image", this, style
);
74 public void setEntity(DescriptionElementBase element
) {
75 this.entity
= element
;
77 if(element
.getMedia().size() == 0){
78 element
.addMedia(Media
.NewInstance());
80 media
= element
.getMedia().iterator().next();
82 if(media
.getRepresentations().size() == 0){
83 media
.addRepresentation(MediaRepresentation
.NewInstance());
85 mediaRepresentation
= media
.getRepresentations().iterator().next();
87 if(mediaRepresentation
.getParts().size() == 0){
88 mediaRepresentation
.addRepresentationPart(MediaRepresentationPart
.NewInstance(null, null));
91 mediaRepresentationPart
= mediaRepresentation
.getParts().iterator().next();
93 if(mediaRepresentationPart
.getUri() != null){
94 protologueUriText
.setText(mediaRepresentationPart
.getUri().toString());
99 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
101 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
104 public SelectionArbitrator
getSelectionArbitrator() {
105 return selectionArbitrator
;
110 public void handleEvent(Object eventSource
) {
111 if(eventSource
== protologueUriText
&& protologueUriText
.getText()!=null){
112 mediaRepresentationPart
.setUri(protologueUriText
.parseText());
117 public void setOpenUrl(URI uri
) {
118 protologueUriText
.setText(uri
.toString());
119 firePropertyChangeEvent(new CdmPropertyChangeEvent(protologueUriText
, null));
123 public Reference
getReference() {
124 return (Reference
) getName().getNomenclaturalReference();
128 public String
getDetail() {
129 return getName().getNomenclaturalMicroReference();
132 private TaxonName
getName(){
133 TaxonNameDescription description
= (TaxonNameDescription
) entity
.getInDescription();
135 TaxonName taxonName
= description
.getTaxonName();