2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.feature
;
12 import java
.net
.URISyntaxException
;
13 import java
.util
.Arrays
;
14 import java
.util
.List
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.widgets
.Label
;
20 import eu
.etaxonomy
.cdm
.api
.service
.geo
.IDistributionService
;
21 import eu
.etaxonomy
.cdm
.common
.URI
;
22 import eu
.etaxonomy
.cdm
.common
.UriUtils
;
23 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
24 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
25 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
26 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
27 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
28 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
29 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
30 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.BrowserElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
35 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
38 * <p>FeatureDistributionDetailElement class.</p>
41 * @created Sep 23, 2010
43 public class FeatureDistributionDetailElement
extends AbstractCdmDetailElement
<FeatureNodeContainer
> {
45 private BrowserElement image
;
48 * <p>Constructor for FeatureDistributionDetailElement.</p>
50 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
51 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
53 public FeatureDistributionDetailElement(CdmFormFactory formFactory
,
54 ICdmFormElement formElement
) {
55 super(formFactory
, formElement
);
59 protected void createControls(ICdmFormElement formElement
, FeatureNodeContainer entity
,
61 String serviceUriString
= PreferencesUtil
.getStringValue(PreferencePredicate
.EditMapServiceAccessPoint
.getKey());
62 String message
= null;
64 URI serviceUri
= new URI(serviceUriString
);
65 if(UriUtils
.isServiceAvailable(serviceUri
, 500)){
66 image
= formFactory
.createBrowserElement(formElement
, null, style
);
67 // FIXME : This is a temporary workaround which ic
68 // waiting for #5357 to be fixed
69 if(!isUnsavedDistribution(getEntity())) {
70 String mapUriString
= getMapUriString(getEntity());
71 image
.setImageUriString(mapUriString
);
72 message
= mapUriString
;
74 formElement
.getLayoutComposite().layout();
78 message
= String
.format("The service is not available: %s", serviceUriString
);
80 } catch (URISyntaxException e
) {
81 message
= String
.format("The URI has problems: %s", serviceUriString
);
84 Label label
= formFactory
.createLabel(getLayoutComposite(), message
, SWT
.WRAP
);
86 label
.setLayoutData(LayoutConstants
.FILL(2, 1));
90 public void handleEvent(Object eventSource
) {
94 private String
getMapUriString(FeatureNodeContainer container
){
95 String accessPoint
= PreferencesUtil
.getMapServiceAccessPoint();
96 Map
<PresenceAbsenceTerm
, java
.awt
.Color
> presenceAbsenceTermColors
= null;
97 // FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
98 // image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 :
99 int width
= image
.calculateWidth();
101 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
102 IDistributionService distributionService
= CdmStore
.getCurrentApplicationConfiguration().getDistributionService();
103 boolean includeUnpublished
= true;
105 String parameter
= distributionService
.getDistributionServiceRequestParameterString(
106 getTaxonDescriptions(),
110 presenceAbsenceTermColors
,
114 String mapUriString
= String
.format("%s?%s&ms=1000&bbox=-180,-90,180,90&l=earth", accessPoint
, parameter
);
118 private List
<TaxonDescription
> getTaxonDescriptions() {
119 return Arrays
.asList(((TaxonDescription
) getEntity().getDescription()).getTaxon().getDescriptions().toArray(new TaxonDescription
[0]));
122 private boolean isUnsavedDistribution(FeatureNodeContainer container
) {
123 for(DescriptionElementBase dist
: container
.getDescriptionElements()) {
124 if(dist
.getId() == 0) {
132 public void fillFields() {
133 String serviceUriString
= PreferencesUtil
.getStringValue(PreferencePredicate
.EditMapServiceAccessPoint
.getKey());
134 String message
= null;
136 URI serviceUri
= new URI(serviceUriString
);
137 if(UriUtils
.isServiceAvailable(serviceUri
, 500)){
138 // image = formFactory.createBrowserElement(formElement, null, style);
139 // FIXME : This is a temporary workaround which ic
140 // waiting for #5357 to be fixed
141 if(!isUnsavedDistribution(getEntity())) {
142 String mapUriString
= getMapUriString(getEntity());
143 image
.setImageUriString(mapUriString
);
144 message
= mapUriString
;
146 getParentElement().getLayoutComposite().layout();
150 message
= String
.format("The service is not available: %s", serviceUriString
);
152 } catch (URISyntaxException e
) {
153 message
= String
.format("The URI has problems: %s", serviceUriString
);