+ 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);
+ }