3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.section
.feature
;
14 import java
.net
.URISyntaxException
;
15 import java
.util
.Arrays
;
16 import java
.util
.HashSet
;
17 import java
.util
.List
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.eclipse
.swt
.events
.ControlAdapter
;
23 import org
.eclipse
.swt
.events
.ControlEvent
;
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
.forms
.CdmFormFactory
;
31 import eu
.etaxonomy
.taxeditor
.forms
.ICdmFormElement
;
32 import eu
.etaxonomy
.taxeditor
.forms
.BrowserElement
;
33 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
34 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
35 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailElement
;
36 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
39 * <p>FeatureDistributionDetailElement class.</p>
42 * @created Sep 23, 2010
45 public class FeatureDistributionDetailElement
extends AbstractCdmDetailElement
<FeatureNodeContainer
> {
47 private static final Logger logger
= Logger
48 .getLogger(FeatureDistributionDetailElement
.class);
50 private BrowserElement image
;
53 * <p>Constructor for FeatureDistributionDetailElement.</p>
55 * @param formFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
56 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
58 public FeatureDistributionDetailElement(CdmFormFactory formFactory
,
59 ICdmFormElement formElement
) {
60 super(formFactory
, formElement
);
65 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
69 protected void createControls(ICdmFormElement formElement
, FeatureNodeContainer entity
,
72 image
= formFactory
.createBrowserElement(formElement
, null, style
);
73 image
.setImageUriString(getMapUriString(getEntity()));
74 formElement
.getLayoutComposite().layout();
79 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
83 public void handleEvent(Object eventSource
) {
89 * @throws URISyntaxException
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();
98 String bbox
= "-180,-90,180,90";
99 String backLayer
= null;
101 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
103 String parameter
= EditGeoServiceUtilities
.getDistributionServiceRequestParameterString(getDistributions(), presenceAbsenceTermColors
, width
, 0, bbox
, backLayer
, languages
);
106 String mapUriString
= accessPoint
+ "?" + parameter
+ "&ms=1000";
113 private Set
<Distribution
> getDistributions() {
114 HashSet
<Distribution
> distributions
= new HashSet
<Distribution
>();
116 for (DescriptionElementBase element
: getEntity().getDescriptionElements()) {
117 if (element
instanceof Distribution
) {
118 distributions
.add((Distribution
) element
);
121 return distributions
;