Merge branch 'develop' into unify_derivative_views
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / feature / FeatureDistributionDetailElement.java
index d18b9d7a5f4a7ce2c238be9695e33bd6afb953e4..07a3d89d9462f441264b014df546d341dc746636 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -19,17 +19,20 @@ import java.util.Map;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Label;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
 import eu.etaxonomy.cdm.common.UriUtils;
+import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
 import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.BrowserElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 
@@ -41,9 +44,9 @@ import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
  * @version 1.0
  */
 public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<FeatureNodeContainer> {
-       
+
        private BrowserElement image;
-       
+
        /**
         * <p>Constructor for FeatureDistributionDetailElement.</p>
         *
@@ -67,12 +70,17 @@ public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<F
                String message = null;
                try {
                        URI serviceUri = new URI(serviceUriString);
-                       if(UriUtils.isServiceAvailable(serviceUri)){
+                       if(UriUtils.isServiceAvailable(serviceUri, 500)){
                                image = formFactory.createBrowserElement(formElement, null, style);
-                               String mapUriString = getMapUriString(getEntity());
-                               image.setImageUriString(mapUriString);
+                               // FIXME : This is a temporary workaround which ic
+                               //         waiting for #5357 to be fixed
+                               if(!isUnsavedDistribution(getEntity())) {
+                                   String mapUriString = getMapUriString(getEntity());
+                                   image.setImageUriString(mapUriString);
+                                   message = mapUriString;
+                               }
                                formElement.getLayoutComposite().layout();
-                               message = mapUriString; 
+
                                return;
                        } else {
                                message = String.format("The service is not available: %s", serviceUriString);
@@ -80,7 +88,7 @@ public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<F
                } catch (URISyntaxException e) {
                        message = String.format("The URI has problems: %s", serviceUriString);
                }
-               
+
                Label label = formFactory.createLabel(getLayoutComposite(), message, SWT.WRAP);
                addControl(label);
                label.setLayoutData(LayoutConstants.FILL(2, 1));
@@ -93,31 +101,40 @@ public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<F
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
-               // 
+               //
        }
 
        /**
         * @return
-        * @throws URISyntaxException 
+        * @throws URISyntaxException
         */
        private String getMapUriString(FeatureNodeContainer container){
                String accessPoint = PreferencesUtil.getMapServiceAccessPoint();
-               Map<PresenceAbsenceTermBase<?>, java.awt.Color> presenceAbsenceTermColors = null;
+               Map<PresenceAbsenceTerm, java.awt.Color> presenceAbsenceTermColors = null;
                // FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
-               // image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 : 
+               // image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 :
                int width = image.calculateWidth();
-               
-               String bbox = "-180,-90,180,90"; 
-               String backLayer = null;
-
+                IEditGeoService editGeoService;
                List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
-               
-               String parameter = CdmStore.getGeoService().getDistributionServiceRequestParameterString(getTaxonDescriptions(), presenceAbsenceTermColors, width, 0, bbox, backLayer, languages);
-               
-               String mapUriString = String.format("%s?%s&ms=1000", accessPoint, parameter);
+               if(CdmStore.getCurrentSessionManager().isRemoting()) {
+                   editGeoService = ((CdmApplicationRemoteController)CdmStore.getCurrentApplicationConfiguration()).getEditGeoService();
+               }else{
+                   editGeoService =(IEditGeoService) CdmStore.getCurrentApplicationConfiguration().getBean(
+                       "editGeoService");
+               }
+
+               String parameter = editGeoService.getDistributionServiceRequestParameterString(
+                               getTaxonDescriptions(),
+                false,
+                false,
+                null,
+                presenceAbsenceTermColors,
+                languages);
+
+               String mapUriString = String.format("%s?%s&ms=1000&bbox=-180,-90,180,90&l=earth", accessPoint, parameter);
                return mapUriString;
        }
-       
+
        /**
         * @return
         */
@@ -125,4 +142,13 @@ public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<F
                return Arrays.asList(((TaxonDescription) getEntity().getDescription()).getTaxon().getDescriptions().toArray(new TaxonDescription[0]));
        }
 
+       private boolean isUnsavedDistribution(FeatureNodeContainer container) {
+           for(DescriptionElementBase dist : container.getDescriptionElements()) {
+               if(dist.getId() == 0) {
+                   return true;
+               }
+           }
+           return false;
+       }
+
 }