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
.CdmApplicationRemoteController
;
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
.DescriptionElementBase
;
27 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
28 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
29 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
30 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
31 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.BrowserElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
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.element.CdmFormFactory} object.
54 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.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
, 500)){
74 image
= formFactory
.createBrowserElement(formElement
, null, style
);
75 // FIXME : This is a temporary workaround which ic
76 // waiting for #5357 to be fixed
77 if(!isUnsavedDistribution(getEntity())) {
78 String mapUriString
= getMapUriString(getEntity());
79 image
.setImageUriString(mapUriString
);
80 message
= mapUriString
;
82 formElement
.getLayoutComposite().layout();
86 message
= String
.format("The service is not available: %s", serviceUriString
);
88 } catch (URISyntaxException e
) {
89 message
= String
.format("The URI has problems: %s", serviceUriString
);
92 Label label
= formFactory
.createLabel(getLayoutComposite(), message
, SWT
.WRAP
);
94 label
.setLayoutData(LayoutConstants
.FILL(2, 1));
99 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
103 public void handleEvent(Object eventSource
) {
109 * @throws URISyntaxException
111 private String
getMapUriString(FeatureNodeContainer container
){
112 String accessPoint
= PreferencesUtil
.getMapServiceAccessPoint();
113 Map
<PresenceAbsenceTerm
, java
.awt
.Color
> presenceAbsenceTermColors
= null;
114 // FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
115 // image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 :
116 int width
= image
.calculateWidth();
117 IEditGeoService editGeoService
;
118 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
119 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
120 editGeoService
= ((CdmApplicationRemoteController
)CdmStore
.getCurrentApplicationConfiguration()).getEditGeoService();
122 editGeoService
=(IEditGeoService
) CdmStore
.getCurrentApplicationConfiguration().getBean(
126 String parameter
= editGeoService
.getDistributionServiceRequestParameterString(
127 getTaxonDescriptions(),
131 presenceAbsenceTermColors
,
134 String mapUriString
= String
.format("%s?%s&ms=1000&bbox=-180,-90,180,90&l=earth", accessPoint
, parameter
);
141 private List
<TaxonDescription
> getTaxonDescriptions() {
142 return Arrays
.asList(((TaxonDescription
) getEntity().getDescription()).getTaxon().getDescriptions().toArray(new TaxonDescription
[0]));
145 private boolean isUnsavedDistribution(FeatureNodeContainer container
) {
146 for(DescriptionElementBase dist
: container
.getDescriptionElements()) {
147 if(dist
.getId() == 0) {