- fixed saving problem due to cloning of FieldUnit
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 22 Oct 2013 11:12:25 +0000 (11:12 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 22 Oct 2013 11:12:25 +0000 (11:12 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/CreateDerivateContextMenu.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java

index 7f19d3eb75f2859dcba893545d9f7c36fdb3367b..5fe1fa149a8e361fa7cdafdbb3280045ed5f37cc 100644 (file)
@@ -1,5 +1,8 @@
 package eu.etaxonomy.taxeditor.editor.view.derivate;
 
+import java.util.UUID;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.action.ContributionItem;
 import org.eclipse.jface.action.IContributionItem;
 import org.eclipse.jface.viewers.ISelection;
@@ -15,21 +18,20 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.CompoundContributionItem;
 import org.eclipse.ui.handlers.IHandlerService;
 
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
 import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 public class CreateDerivateContextMenu extends CompoundContributionItem {
 
-    private final IHandlerService handlerService = (IHandlerService) EditorUtil.getService(IHandlerService.class);
+    private final IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
 
     /* (non-Javadoc)
      * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
@@ -52,33 +54,27 @@ public class CreateDerivateContextMenu extends CompoundContributionItem {
 
                                     @Override
                                     public void widgetSelected(SelectionEvent e) {
-                                        IOccurrenceService occurrenceService = CdmStore.getCurrentApplicationConfiguration().getOccurrenceService();
-                                        SpecimenOrObservationBase fieldUnit = occurrenceService.load(((FieldUnit) selectedElement).getUuid());
+                                        ICdmApplicationConfiguration currentApplicationConfiguration = CdmStore.getCurrentApplicationConfiguration();
+//                                        TransactionStatus transaction = currentApplicationConfiguration.startTransaction();
+                                        IOccurrenceService occurrenceService = currentApplicationConfiguration.getOccurrenceService();
+                                        FieldUnit fieldUnit = (FieldUnit)selectedElement;
+                                        UUID uuid = fieldUnit.getUuid();
+                                        fieldUnit = (FieldUnit) occurrenceService.load(uuid);
+//                                        fieldUnit = (FieldUnit)HibernateProxyHelper.deproxy(fieldUnit);
 
                                         DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
                                         fieldUnit.addDerivationEvent(DerivationEvent.NewSimpleInstance(fieldUnit, specimen, DerivationEventType.GATHERING_IN_SITU()));
                                         specimen.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
-//                                        specimen.getTitleCache(); //update title cache
+                                        specimen.getTitleCache(); //update title cache
                                         IWorkbenchPart activePart = AbstractUtility.getActivePart();
-                                        occurrenceService.saveOrUpdate(fieldUnit);
+//                                        occurrenceService.saveOrUpdate(fieldUnit);
+//                                        occurrenceService.saveOrUpdate(specimen);
+//                                        currentApplicationConfiguration.commitTransaction(transaction);
                                         if(activePart instanceof DerivateView){
                                             DerivateView derivateView = (DerivateView)activePart;
                                             derivateView.viewer.refresh();
+                                            derivateView.getEditor().doSave(new NullProgressMonitor());
                                         }
-//                                        DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
-//                                        fieldUnit.addDerivationEvent(DerivationEvent.NewSimpleInstance(fieldUnit, specimen, DerivationEventType.GATHERING_IN_SITU()));
-//                                        specimen.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
-//                                        specimen.getTitleCache(); //update title cache
-//                                        IEditorPart activeEditor = AbstractUtility.getActiveEditor();
-//                                        IWorkbenchPart activePart = AbstractUtility.getActivePart();
-//                                        ConversationHolder conversation = CdmStore.createConversation();
-//                                        CdmStore.getService(IOccurrenceService.class).saveOrUpdate(fieldUnit);
-//                                        conversation.commit();
-//                                        conversation.close();
-//                                        if(activePart instanceof DerivateView){
-//                                            DerivateView derivateView = (DerivateView)activePart;
-//                                            derivateView.viewer.refresh();
-//                                        }
                                     }
 
                                     @Override
index 3c3c87bbf9f2ac61db817b793a4d787d6949a8f6..992f99b15a08dccc413044e94d8ce32ba9d849fd 100644 (file)
@@ -43,9 +43,8 @@ public class DerivateContentProvider implements ITreeContentProvider {
                  }
                }
            }
-           // return the FieldUnit itself if element is a FieldUnit (used clone() due to recursion issues -> see javadoc of this method)
            else if(inputElement instanceof FieldUnit){
-               FieldUnit fieldUnit = ((FieldUnit) inputElement).clone();
+               FieldUnit fieldUnit = (FieldUnit) inputElement;
                fieldUnit.getTitleCache();
                return Collections.singleton(fieldUnit).toArray();
            }