Project

General

Profile

Download (4.9 KB) Statistics
| Branch: | Tag: | Revision:
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
import java.net.URISyntaxException;
15

    
16
import org.eclipse.swt.events.SelectionListener;
17

    
18
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
19
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
20
import eu.etaxonomy.cdm.model.media.Media;
21
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
22
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
23
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
26
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
27
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
28
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
29
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
30
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
31
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
32
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
33
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
34
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
35

    
36
/**
37
 * <p>ProtologueElement class.</p>
38
 *
39
 * @author n.hoffmann
40
 * @created Nov 5, 2009
41
 * @version 1.0
42
 */
43
public class ProtologueElement extends AbstractEntityCollectionElement<DescriptionElementBase> implements ISelectableElement, IOpenUrlEnabled{
44

    
45
	private final SelectionArbitrator selectionArbitrator;
46

    
47
	private TextWithLabelElement protologueUriText;
48
	private MediaRepresentationPart mediaRepresentationPart;
49
	private Media media;
50
	private MediaRepresentation mediaRepresentation;
51

    
52
	/**
53
	 * <p>Constructor for ProtologueElement.</p>
54
	 *
55
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
56
	 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
57
	 * @param style a int.
58
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
59
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
60
	 */
61
	public ProtologueElement(CdmFormFactory cdmFormFactory, AbstractFormSection formElement, DescriptionElementBase element,
62
			SelectionListener removeListener, int style) {
63
		super(cdmFormFactory, formElement, element, removeListener, null, style);
64
		selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
65
	}
66

    
67
	/** {@inheritDoc} */
68
	@Override
69
	public void createControls(ICdmFormElement element, int style) {
70
		protologueUriText = formFactory.createTextWithLabelElement(this, "Protologue URI", "", style);
71

    
72
		formFactory.createOpenUrlSelectorElement(element, "Query BHL for Reference Image", this, style);
73
	}
74

    
75
	/** {@inheritDoc} */
76
	@Override
77
	public void setEntity(DescriptionElementBase element) {
78
		this.entity = element;
79

    
80
		if(element.getMedia().size() == 0){
81
			element.addMedia(Media.NewInstance());
82
		}
83
		media = element.getMedia().iterator().next();
84

    
85
		if(media.getRepresentations().size() == 0){
86
			media.addRepresentation(MediaRepresentation.NewInstance());
87
		}
88
		mediaRepresentation = media.getRepresentations().iterator().next();
89

    
90
		if(mediaRepresentation.getParts().size() == 0){
91
			mediaRepresentation.addRepresentationPart(MediaRepresentationPart.NewInstance(null, null));
92
		}
93

    
94
		mediaRepresentationPart = mediaRepresentation.getParts().iterator().next();
95

    
96
		if(mediaRepresentationPart.getUri() != null){
97
			protologueUriText.setText(mediaRepresentationPart.getUri().toString());
98
		}
99
	}
100

    
101
	/**
102
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
103
	 *
104
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
105
	 */
106
	@Override
107
    public SelectionArbitrator getSelectionArbitrator() {
108
		return selectionArbitrator;
109
	}
110

    
111
	/** {@inheritDoc} */
112
	@Override
113
	public void handleEvent(Object eventSource) {
114
		if(eventSource == protologueUriText && protologueUriText.getText()!=null){
115
			try {
116
				mediaRepresentationPart.setUri(new URI(protologueUriText.getText()));
117
			} catch (URISyntaxException e) {
118
				MessagingUtils.warningDialog("Could not parse URI", getClass(), e.getMessage());
119
			}
120
		}
121
	}
122

    
123
	@Override
124
	public void setOpenUrl(URI uri) {
125
		protologueUriText.setText(uri.toString());
126
		firePropertyChangeEvent(new CdmPropertyChangeEvent(protologueUriText, null));
127
	}
128

    
129
	@Override
130
	public Reference getReference() {
131
		return (Reference) getName().getNomenclaturalReference();
132
	}
133

    
134
	@Override
135
	public String getDetail() {
136
		return getName().getNomenclaturalMicroReference();
137
	}
138

    
139
	private TaxonNameBase getName(){
140
		TaxonNameDescription description = (TaxonNameDescription) entity.getInDescription();
141

    
142
		TaxonNameBase taxonName = description.getTaxonName();
143

    
144
		return taxonName;
145
	}
146
}
(18-18/25)