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
.List
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.widgets
.Label
;
22 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteConfiguration
;
23 import eu
.etaxonomy
.cdm
.common
.UriUtils
;
24 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
25 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
26 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
27 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
28 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
29 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
30 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.BrowserElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
39 * <p>FeatureDistributionDetailElement class.</p>
42 * @created Sep 23, 2010
45 public class FeatureDistributionDetailElement
extends AbstractCdmDetailElement
<FeatureNodeContainer
> {
47 private BrowserElement image
;
50 * <p>Constructor for FeatureDistributionDetailElement.</p>
52 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
53 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
55 public FeatureDistributionDetailElement(CdmFormFactory formFactory
,
56 ICdmFormElement formElement
) {
57 super(formFactory
, formElement
);
62 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
66 protected void createControls(ICdmFormElement formElement
, FeatureNodeContainer entity
,
68 String serviceUriString
= PreferencesUtil
.getPreferenceStore().getString(IPreferenceKeys
.EDIT_MAP_SERVICE_ACCES_POINT
);
69 String message
= null;
71 URI serviceUri
= new URI(serviceUriString
);
72 if(UriUtils
.isServiceAvailable(serviceUri
, 500)){
73 image
= formFactory
.createBrowserElement(formElement
, null, style
);
74 String mapUriString
= getMapUriString(getEntity());
75 image
.setImageUriString(mapUriString
);
76 formElement
.getLayoutComposite().layout();
77 message
= mapUriString
;
80 message
= String
.format("The service is not available: %s", serviceUriString
);
82 } catch (URISyntaxException e
) {
83 message
= String
.format("The URI has problems: %s", serviceUriString
);
86 Label label
= formFactory
.createLabel(getLayoutComposite(), message
, SWT
.WRAP
);
88 label
.setLayoutData(LayoutConstants
.FILL(2, 1));
93 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
97 public void handleEvent(Object eventSource
) {
103 * @throws URISyntaxException
105 private String
getMapUriString(FeatureNodeContainer container
){
106 String accessPoint
= PreferencesUtil
.getMapServiceAccessPoint();
107 Map
<PresenceAbsenceTerm
, java
.awt
.Color
> presenceAbsenceTermColors
= null;
108 // FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
109 // image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 :
110 int width
= image
.calculateWidth();
111 IEditGeoService editGeoService
;
112 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
113 if(CdmStore
.getCurrentApplicationConfiguration() instanceof CdmApplicationRemoteConfiguration
) {
114 editGeoService
= ((CdmApplicationRemoteConfiguration
)CdmStore
.getCurrentApplicationConfiguration()).getEditGeoService();
116 editGeoService
=(IEditGeoService
) CdmStore
.getCurrentApplicationConfiguration().getBean(
119 String parameter
= editGeoService
.getDistributionServiceRequestParameterString(
120 getTaxonDescriptions(),
124 presenceAbsenceTermColors
,
127 String mapUriString
= String
.format("%s?%s&ms=1000&bbox=-180,-90,180,90&l=earth", accessPoint
, parameter
);
134 private List
<TaxonDescription
> getTaxonDescriptions() {
135 return Arrays
.asList(((TaxonDescription
) getEntity().getDescription()).getTaxon().getDescriptions().toArray(new TaxonDescription
[0]));