#5357 Add check to avoid transient object exception
authorCherian Mathew <c.mathew@bgbm.org>
Mon, 26 Oct 2015 17:24:16 +0000 (18:24 +0100)
committerCherian Mathew <c.mathew@bgbm.org>
Mon, 26 Oct 2015 17:24:16 +0000 (18:24 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureDistributionDetailElement.java

index 138a0e760e1fd26c56f20604fa18269b58ea021a..07a3d89d9462f441264b014df546d341dc746636 100644 (file)
@@ -19,10 +19,11 @@ import java.util.Map;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Label;
 
-import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
+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;
@@ -71,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);
@@ -110,12 +116,13 @@ public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<F
                int width = image.calculateWidth();
                 IEditGeoService editGeoService;
                List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
-               if(CdmStore.getCurrentApplicationConfiguration() instanceof CdmApplicationRemoteConfiguration) {
-                   editGeoService = ((CdmApplicationRemoteConfiguration)CdmStore.getCurrentApplicationConfiguration()).getEditGeoService();
+               if(CdmStore.getCurrentSessionManager().isRemoting()) {
+                   editGeoService = ((CdmApplicationRemoteController)CdmStore.getCurrentApplicationConfiguration()).getEditGeoService();
                }else{
                    editGeoService =(IEditGeoService) CdmStore.getCurrentApplicationConfiguration().getBean(
                        "editGeoService");
                }
+
                String parameter = editGeoService.getDistributionServiceRequestParameterString(
                                getTaxonDescriptions(),
                 false,
@@ -135,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;
+       }
+
 }