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
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.Collections
;
18 import java
.util
.HashSet
;
19 import java
.util
.List
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.widgets
.Label
;
26 import eu
.etaxonomy
.cdm
.common
.UriUtils
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
28 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
29 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
30 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
31 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
32 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
33 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
34 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.BrowserElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
38 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
39 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
42 * <p>FeatureDistributionDetailElement class.</p>
45 * @created Sep 23, 2010
48 public class FeatureDistributionDetailElement
extends AbstractCdmDetailElement
<FeatureNodeContainer
> {
50 private BrowserElement image
;
53 * <p>Constructor for FeatureDistributionDetailElement.</p>
55 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
56 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.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
,
71 String serviceUriString
= PreferencesUtil
.getPreferenceStore().getString(IPreferenceKeys
.EDIT_MAP_SERVICE_ACCES_POINT
);
72 String message
= null;
74 URI serviceUri
= new URI(serviceUriString
);
75 if(UriUtils
.isServiceAvailable(serviceUri
)){
76 image
= formFactory
.createBrowserElement(formElement
, null, style
);
77 String mapUriString
= getMapUriString(getEntity());
78 image
.setImageUriString(mapUriString
);
79 formElement
.getLayoutComposite().layout();
80 message
= mapUriString
;
83 message
= String
.format("The service is not available: %s", serviceUriString
);
85 } catch (URISyntaxException e
) {
86 message
= String
.format("The URI has problems: %s", serviceUriString
);
89 Label label
= formFactory
.createLabel(getLayoutComposite(), message
, SWT
.WRAP
);
91 label
.setLayoutData(CdmFormFactory
.FILL(2, 1));
96 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
100 public void handleEvent(Object eventSource
) {
106 * @throws URISyntaxException
108 private String
getMapUriString(FeatureNodeContainer container
){
109 String accessPoint
= PreferencesUtil
.getMapServiceAccessPoint();
110 Map
<PresenceAbsenceTermBase
<?
>, java
.awt
.Color
> presenceAbsenceTermColors
= null;
111 // FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
112 // image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 :
113 int width
= image
.calculateWidth();
115 String bbox
= "-180,-90,180,90";
116 String backLayer
= null;
118 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
120 String parameter
= CdmStore
.getGeoService().getDistributionServiceRequestParameterString(getTaxonDescriptions(), presenceAbsenceTermColors
, width
, 0, bbox
, backLayer
, languages
);
122 String mapUriString
= String
.format("%s?%s&ms=1000", accessPoint
, parameter
);
129 private List
<TaxonDescription
> getTaxonDescriptions() {
130 return Arrays
.asList(((TaxonDescription
) getEntity().getDescription()).getTaxon().getDescriptions().toArray(new TaxonDescription
[0]));