Remove unused entity cloning
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 2 Dec 2015 16:40:53 +0000 (17:40 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 2 Dec 2015 16:40:53 +0000 (17:40 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java

index 32c20fd..75821c5 100644 (file)
@@ -8,7 +8,6 @@ import java.util.Observable;
 import java.util.Observer;
 
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -24,19 +23,7 @@ import org.springframework.security.core.GrantedAuthority;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.api.service.IAgentService;
-import eu.etaxonomy.cdm.api.service.ICollectionService;
-import eu.etaxonomy.cdm.api.service.INameService;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
-import eu.etaxonomy.cdm.api.service.IReferenceService;
-import eu.etaxonomy.cdm.api.service.IService;
-import eu.etaxonomy.cdm.api.service.IUserService;
-import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
-import eu.etaxonomy.cdm.api.service.molecular.IPrimerService;
 import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.model.agent.Institution;
-import eu.etaxonomy.cdm.model.agent.Person;
-import eu.etaxonomy.cdm.model.agent.Team;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Group;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
@@ -44,15 +31,9 @@ import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
 import eu.etaxonomy.cdm.model.common.User;
 import eu.etaxonomy.cdm.model.molecular.Amplification;
 import eu.etaxonomy.cdm.model.molecular.Primer;
-import eu.etaxonomy.cdm.model.name.NonViralName;
-import eu.etaxonomy.cdm.model.occurrence.Collection;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.ImageResources;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.Resources;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.LoginManager;
@@ -429,8 +410,6 @@ public class EntitySelectionElement<T extends ICdmBase> extends
 
        private class EditListener extends SelectionAdapter {
 
-        private static final String TRANSIENT_EDITING_WARNING_TEXT = "Warning: All changes for this element are directly reflected in the data base.\nThe \"Cancel\" button has no effect";
-        private static final String TRANSIENT_EDITING_WARNING_TITLE = "CDM element not yet saved.";
         private final EntitySelectionElement<T> selectionElement;
 
                public EditListener(EntitySelectionElement<T> selectionElement) {
@@ -440,80 +419,11 @@ public class EntitySelectionElement<T extends ICdmBase> extends
                /** {@inheritDoc} */
                @Override
                public void widgetSelected(SelectionEvent e) {
-                   T originalEntity = selectionElement.getEntity();
-                   T clonedEntity = null;
-                   IService<T> service = null;
-                   if(originalEntity instanceof CdmBase){
-                       //get corresponding service
-                       if(entity instanceof Reference<?>){
-                           service = (IService<T>) CdmStore.getService(IReferenceService.class);
-                       }
-                       else if (entity instanceof Team || entity instanceof Person || entity instanceof Institution) {
-                           service = (IService<T>) CdmStore.getService(IAgentService.class);
-                       }
-                       else if (entity instanceof NonViralName) {
-                           service = (IService<T>) CdmStore.getService(INameService.class);
-                       }
-                       else if (entity instanceof SpecimenOrObservationBase) {
-                           service = (IService<T>) CdmStore.getService(IOccurrenceService.class);
-                       }
-                       else if (entity instanceof Collection) {
-                           service = (IService<T>) CdmStore.getService(ICollectionService.class);
-                       }
-                       else if (entity instanceof User) {
-                           service = (IService<T>) CdmStore.getService(IUserService.class);
-                       }
-                       else if (entity instanceof Primer) {
-                           service = (IService<T>) CdmStore.getService(IPrimerService.class);
-                       }
-                       else if (entity instanceof Amplification) {
-                           service = (IService<T>) CdmStore.getService(IAmplificationService.class);
-                       }
-                       //check if original already exists in data base. If not then do not clone and all changes will be persisted directly -> Warning to user.
-                if(service !=null && service.find(originalEntity.getUuid())==null && originalEntity.getId() != 0){
-                    if(MessagingUtils.confirmDialog(TRANSIENT_EDITING_WARNING_TITLE, "["+originalEntity.getClass().getSimpleName()+"]"+originalEntity + " has to be saved before it can be edited. Save now?")){
-                        service.save(originalEntity);
-                        AbstractUtility.getActiveEditor().doSave(new NullProgressMonitor());
-                    }
-                    else{
-                        //transient CDM elements should not be edited to avoid merge conflicts
-                        // when the elements are cascaded
-                        return;
-                    }
-                }
-                else{
-                    //FIXME temporarily disabled cloning re-opening bug #2645 (EditFromSelectionWizard persists data even when canceled)
-//                    try {
-//                        //clone original
-//                        clonedEntity = (T) ((CdmBase) originalEntity).clone();
-//                    } catch (CloneNotSupportedException e1) {
-//                        MessagingUtils.warningDialog(TRANSIENT_EDITING_WARNING_TITLE, this, TRANSIENT_EDITING_WARNING_TEXT);
-//                    }
-                }
-
-                   }
-                   if(clonedEntity!=null){
-                       selectionElement.setEntity(clonedEntity);
-                   }
                        WizardDialog dialog = new WizardDialog(selectionElement.getShell(),
                                        new EditFromSelectionWizard(selectionElement));
                        if (dialog.open() == IStatus.OK) {
-                           if(service!=null && clonedEntity!=null){//check if cloning happened
-                               T editedClonedEntity = selectionElement.getEntity();
-                               editedClonedEntity.setId(originalEntity.getId());
-                               editedClonedEntity.setUuid(originalEntity.getUuid());
-
-                               //merge clone and original
-                               service.merge(editedClonedEntity);
-                               originalEntity = service.load(originalEntity.getUuid());
-
-                           }
-                           selectionElement.setEntity(originalEntity);
                                selectionElement.updateFromWizard();
                        }
-                       //be sure to reset to original in all cases
-                       selectionElement.setEntity(originalEntity);
-                       selectionElement.refresh();
                }
        }