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.feature;
|
12
|
|
13
|
import java.net.URI;
|
14
|
import java.net.URISyntaxException;
|
15
|
import java.util.Arrays;
|
16
|
import java.util.HashSet;
|
17
|
import java.util.List;
|
18
|
import java.util.Map;
|
19
|
import java.util.Set;
|
20
|
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.eclipse.swt.events.ControlAdapter;
|
23
|
import org.eclipse.swt.events.ControlEvent;
|
24
|
|
25
|
import eu.etaxonomy.cdm.ext.geo.EditGeoServiceUtilities;
|
26
|
import eu.etaxonomy.cdm.model.common.Language;
|
27
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
28
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
29
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
30
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
31
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
import eu.etaxonomy.taxeditor.ui.forms.BrowserElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
|
35
|
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
|
36
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
37
|
|
38
|
/**
|
39
|
* <p>FeatureDistributionDetailElement class.</p>
|
40
|
*
|
41
|
* @author n.hoffmann
|
42
|
* @created Sep 23, 2010
|
43
|
* @version 1.0
|
44
|
*/
|
45
|
public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<FeatureNodeContainer> {
|
46
|
|
47
|
private static final Logger logger = Logger
|
48
|
.getLogger(FeatureDistributionDetailElement.class);
|
49
|
|
50
|
private BrowserElement image;
|
51
|
|
52
|
/**
|
53
|
* <p>Constructor for FeatureDistributionDetailElement.</p>
|
54
|
*
|
55
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
|
56
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
|
57
|
*/
|
58
|
public FeatureDistributionDetailElement(CdmFormFactory formFactory,
|
59
|
ICdmFormElement formElement) {
|
60
|
super(formFactory, formElement);
|
61
|
}
|
62
|
|
63
|
|
64
|
/* (non-Javadoc)
|
65
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
|
66
|
*/
|
67
|
/** {@inheritDoc} */
|
68
|
@Override
|
69
|
protected void createControls(ICdmFormElement formElement, FeatureNodeContainer entity,
|
70
|
int style) {
|
71
|
|
72
|
image = formFactory.createBrowserElement(formElement, null, style);
|
73
|
image.setImageUriString(getMapUriString(getEntity()));
|
74
|
formElement.getLayoutComposite().layout();
|
75
|
}
|
76
|
|
77
|
|
78
|
/* (non-Javadoc)
|
79
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
|
80
|
*/
|
81
|
/** {@inheritDoc} */
|
82
|
@Override
|
83
|
public void handleEvent(Object eventSource) {
|
84
|
//
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* @return
|
89
|
* @throws URISyntaxException
|
90
|
*/
|
91
|
private String getMapUriString(FeatureNodeContainer container){
|
92
|
String accessPoint = PreferencesUtil.getMapServiceAccessPoint();
|
93
|
Map<PresenceAbsenceTermBase<?>, java.awt.Color> presenceAbsenceTermColors = null;
|
94
|
// FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
|
95
|
// image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 :
|
96
|
int width = image.calculateWidth();
|
97
|
|
98
|
String bbox = "-180,-90,180,90";
|
99
|
String backLayer = null;
|
100
|
|
101
|
List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
|
102
|
|
103
|
String parameter = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(getDistributions(), presenceAbsenceTermColors, width, 0, bbox, backLayer, languages);
|
104
|
|
105
|
|
106
|
String mapUriString = accessPoint + "?" + parameter + "&ms=1000";
|
107
|
return mapUriString;
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* @return
|
112
|
*/
|
113
|
private Set<Distribution> getDistributions() {
|
114
|
HashSet<Distribution> distributions = new HashSet<Distribution>();
|
115
|
|
116
|
for (DescriptionElementBase element : getEntity().getDescriptionElements()) {
|
117
|
if (element instanceof Distribution) {
|
118
|
distributions.add((Distribution) element);
|
119
|
}
|
120
|
}
|
121
|
return distributions;
|
122
|
}
|
123
|
|
124
|
}
|