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 7da47bb4c2b0742ac5ffbe3a10ee30c48c7f726e..07a3d89d9462f441264b014df546d341dc746636 100644 (file)
@@ -19,8 +19,11 @@ 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.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
@@ -69,10 +72,15 @@ public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<F
                        URI serviceUri = new URI(serviceUriString);
                        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);
@@ -106,16 +114,21 @@ public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<F
                // 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 :
                int width = image.calculateWidth();
-
+                IEditGeoService editGeoService;
                List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
+               if(CdmStore.getCurrentSessionManager().isRemoting()) {
+                   editGeoService = ((CdmApplicationRemoteController)CdmStore.getCurrentApplicationConfiguration()).getEditGeoService();
+               }else{
+                   editGeoService =(IEditGeoService) CdmStore.getCurrentApplicationConfiguration().getBean(
+                       "editGeoService");
+               }
 
-               String parameter = CdmStore.getGeoService().getDistributionServiceRequestParameterString(
+               String parameter = editGeoService.getDistributionServiceRequestParameterString(
                                getTaxonDescriptions(),
-                false, 
-                false, 
+                false,
+                false,
                 null,
-                null,
-                presenceAbsenceTermColors, 
+                presenceAbsenceTermColors,
                 languages);
 
                String mapUriString = String.format("%s?%s&ms=1000&bbox=-180,-90,180,90&l=earth", accessPoint, parameter);
@@ -129,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;
+       }
+
 }