Fix session problem when creating field unit for a taxon
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 2 Dec 2015 09:39:16 +0000 (10:39 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 2 Dec 2015 10:09:38 +0000 (11:09 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/CreateFieldUnitContextMenu.java

index dc3176b..0828a31 100644 (file)
@@ -13,6 +13,7 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.CompoundContributionItem;
 
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
@@ -46,7 +47,7 @@ public class CreateFieldUnitContextMenu extends CompoundContributionItem {
                             if(derivateView.isListenToSelectionChange()){
                                 Object selectionInput = derivateView.getSelectionInput();
                                 if(selectionInput instanceof CdmBase && ((CdmBase) selectionInput).isInstanceOf(Taxon.class)){
-                                    final Taxon taxon = HibernateProxyHelper.deproxy(selectionInput, Taxon.class);
+                                    final Taxon taxon = HibernateProxyHelper.deproxy(CdmStore.getService(ITaxonService.class).load(((CdmBase)selectionInput).getUuid()), Taxon.class);
                                     MenuItem item = new MenuItem(menu, SWT.NONE);
                                     item.setText("Create FieldUnit for "+taxon.getName());
                                     item.addSelectionListener(new SelectionAdapter() {
@@ -56,6 +57,7 @@ public class CreateFieldUnitContextMenu extends CompoundContributionItem {
                                                 MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
                                                 return;
                                             }
+
                                             FieldUnit fieldUnit = FieldUnit.NewInstance();
                                             fieldUnit = CdmBase.deproxy(CdmStore.getService(IOccurrenceService.class).save(fieldUnit), FieldUnit.class);
                                             IndividualsAssociation association = IndividualsAssociation.NewInstance(fieldUnit);
@@ -67,6 +69,12 @@ public class CreateFieldUnitContextMenu extends CompoundContributionItem {
                                                 description = TaxonDescription.NewInstance(taxon);
                                             }
                                             description.addElement(association);
+                                            if(CdmStore.getCurrentSessionManager().isRemoting()){
+                                                CdmStore.getService(ITaxonService.class).merge(taxon);
+                                            }
+                                            else{
+                                                CdmStore.getService(ITaxonService.class).saveOrUpdate(taxon);
+                                            }
 
                                             derivateView.getConversationHolder().commit();
                                             derivateView.addFieldUnit(fieldUnit);