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
.ui
.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
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.widgets
.Label
;
24 import eu
.etaxonomy
.cdm
.common
.UriUtils
;
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
.IPreferenceKeys
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 import eu
.etaxonomy
.taxeditor
.ui
.forms
.BrowserElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
;
36 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
40 * <p>FeatureDistributionDetailElement class.</p>
43 * @created Sep 23, 2010
46 public class FeatureDistributionDetailElement
extends AbstractCdmDetailElement
<FeatureNodeContainer
> {
48 private BrowserElement image
;
51 * <p>Constructor for FeatureDistributionDetailElement.</p>
53 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
54 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
56 public FeatureDistributionDetailElement(CdmFormFactory formFactory
,
57 ICdmFormElement formElement
) {
58 super(formFactory
, formElement
);
63 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
67 protected void createControls(ICdmFormElement formElement
, FeatureNodeContainer entity
,
69 String serviceUriString
= PreferencesUtil
.getPreferenceStore().getString(IPreferenceKeys
.EDIT_MAP_SERVICE_ACCES_POINT
);
70 String message
= null;
72 URI serviceUri
= new URI(serviceUriString
);
73 if(UriUtils
.isServiceAvailable(serviceUri
)){
74 image
= formFactory
.createBrowserElement(formElement
, null, style
);
75 String mapUriString
= getMapUriString(getEntity());
76 image
.setImageUriString(mapUriString
);
77 formElement
.getLayoutComposite().layout();
78 message
= mapUriString
;
81 message
= String
.format("The service is not available: %s", serviceUriString
);
83 } catch (URISyntaxException e
) {
84 message
= String
.format("The URI has problems: %s", serviceUriString
);
87 Label label
= formFactory
.createLabel(getLayoutComposite(), message
, SWT
.WRAP
);
89 label
.setLayoutData(CdmFormFactory
.FILL(2, 1));
94 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
98 public void handleEvent(Object eventSource
) {
104 * @throws URISyntaxException
106 private String
getMapUriString(FeatureNodeContainer container
){
107 String accessPoint
= PreferencesUtil
.getMapServiceAccessPoint();
108 Map
<PresenceAbsenceTermBase
<?
>, java
.awt
.Color
> presenceAbsenceTermColors
= null;
109 // FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
110 // image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 :
111 int width
= image
.calculateWidth();
113 String bbox
= "-180,-90,180,90";
114 String backLayer
= null;
116 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
118 String parameter
= EditGeoServiceUtilities
.getDistributionServiceRequestParameterString(getDistributions(), presenceAbsenceTermColors
, width
, 0, bbox
, backLayer
, null, languages
);
121 String mapUriString
= accessPoint
+ "?" + parameter
+ "&ms=1000";
128 private Set
<Distribution
> getDistributions() {
129 HashSet
<Distribution
> distributions
= new HashSet
<Distribution
>();
131 for (DescriptionElementBase element
: getEntity().getDescriptionElements()) {
132 if (element
instanceof Distribution
) {
133 distributions
.add((Distribution
) element
);
136 return distributions
;