Project

General

Profile

« Previous | Next » 

Revision a41bd5e3

Added by Patrick Plitzner over 6 years ago

Fix session problem when creating field unit for a taxon

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/CreateFieldUnitContextMenu.java
13 13
import org.eclipse.ui.actions.CompoundContributionItem;
14 14

  
15 15
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
16
import eu.etaxonomy.cdm.api.service.ITaxonService;
16 17
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
17 18
import eu.etaxonomy.cdm.model.common.CdmBase;
18 19
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
......
46 47
                            if(derivateView.isListenToSelectionChange()){
47 48
                                Object selectionInput = derivateView.getSelectionInput();
48 49
                                if(selectionInput instanceof CdmBase && ((CdmBase) selectionInput).isInstanceOf(Taxon.class)){
49
                                    final Taxon taxon = HibernateProxyHelper.deproxy(selectionInput, Taxon.class);
50
                                    final Taxon taxon = HibernateProxyHelper.deproxy(CdmStore.getService(ITaxonService.class).load(((CdmBase)selectionInput).getUuid()), Taxon.class);
50 51
                                    MenuItem item = new MenuItem(menu, SWT.NONE);
51 52
                                    item.setText("Create FieldUnit for "+taxon.getName());
52 53
                                    item.addSelectionListener(new SelectionAdapter() {
......
56 57
                                                MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
57 58
                                                return;
58 59
                                            }
60

  
59 61
                                            FieldUnit fieldUnit = FieldUnit.NewInstance();
60 62
                                            fieldUnit = CdmBase.deproxy(CdmStore.getService(IOccurrenceService.class).save(fieldUnit), FieldUnit.class);
61 63
                                            IndividualsAssociation association = IndividualsAssociation.NewInstance(fieldUnit);
......
67 69
                                                description = TaxonDescription.NewInstance(taxon);
68 70
                                            }
69 71
                                            description.addElement(association);
72
                                            if(CdmStore.getCurrentSessionManager().isRemoting()){
73
                                                CdmStore.getService(ITaxonService.class).merge(taxon);
74
                                            }
75
                                            else{
76
                                                CdmStore.getService(ITaxonService.class).saveOrUpdate(taxon);
77
                                            }
70 78

  
71 79
                                            derivateView.getConversationHolder().commit();
72 80
                                            derivateView.addFieldUnit(fieldUnit);

Also available in: Unified diff