Fix editing of transient entities in EntitySelectionElement #5592
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 23 Feb 2016 17:25:31 +0000 (18:25 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 23 Feb 2016 17:26:07 +0000 (18:26 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EditFromSelectionWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java

index 08efabd7e04984d573c125d7fd6a3c27dbe96c55..8340b243f3316ddd7316e10baa53b7f72cfb0c8f 100644 (file)
@@ -89,8 +89,14 @@ public class EditFromSelectionWizard extends Wizard implements
                CdmFormFactory formFactory = selectionElement.getFormFactory();
                CdmBase entity = (CdmBase) HibernateProxyHelper
                                .deproxy(selectionElement.getEntity());
-               IService<CdmBase> service = CdmStore.getService(entity);
-               rootElement = service.load(entity.getUuid());
+               //check if entity has already been persisted
+               if(entity.getId()==0){
+                       rootElement = entity;
+               }
+               else{
+                       IService<CdmBase> service = CdmStore.getService(entity);
+                       rootElement = service.load(entity.getUuid());
+               }
                if (rootElement.isInstanceOf(Reference.class)) {
                        addPage(new ReferenceWizardPage(formFactory,
                                        selectionElement.getConversationHolder(),
index c4e708be4e800d7d7a2f674de5d0ec765fcd504c..b04c73d4d50137a543d024706ac06d20fa39b280 100644 (file)
@@ -421,18 +421,20 @@ public class EntitySelectionElement<T extends CdmBase> extends
                /** {@inheritDoc} */
                @Override
                public void widgetSelected(SelectionEvent e) {
-
-               IService<T> service = CdmStore.getService(entity);
-               T loadedEntity = service.load(entity.getUuid());
-            if (loadedEntity==null){
-                   MessageDialog.openInformation(null,"Save changes", "You have made changes that must be saved before this query can be executed");
-                   return;
-               }
                        WizardDialog dialog = new WizardDialog(selectionElement.getShell(),
                                        new EditFromSelectionWizard(selectionElement));
                        if (dialog.open() == IStatus.OK) {
-
                                selectionElement.updateFromWizard();
+                               //if the edited entity has already been persisted
+                               //but the transient entity is still set in this 
+                               //EntitySelectionElement, re-load it and set it
+                               IService<T> service = CdmStore.getService(entity);
+                               if(entity.getId()==0){
+                                       T loadedEntity = service.load(entity.getUuid());
+                                       if(loadedEntity!=null){
+                                               setEntity(loadedEntity);
+                                       }
+                               }
                        }
                }
        }