Revision 1149ef6a
Added by Patrick Plitzner over 9 years ago
- when editing a CDM entity in an EditFromSelectionWizard the entity will be cloned before editing.
- when hitting "Finish" the entity will be merged with the original.
- when hitting "Cancel" the merging will not be made and the changes will be ignored -> this fixes #2645
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java | ||
---|---|---|
8 | 8 |
import java.util.Observer; |
9 | 9 |
|
10 | 10 |
import org.eclipse.core.runtime.IStatus; |
11 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
11 | 12 |
import org.eclipse.jface.wizard.WizardDialog; |
12 | 13 |
import org.eclipse.swt.SWT; |
13 | 14 |
import org.eclipse.swt.events.SelectionAdapter; |
... | ... | |
23 | 24 |
|
24 | 25 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
25 | 26 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
27 |
import eu.etaxonomy.cdm.api.service.IAgentService; |
|
28 |
import eu.etaxonomy.cdm.api.service.ICollectionService; |
|
29 |
import eu.etaxonomy.cdm.api.service.INameService; |
|
30 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
31 |
import eu.etaxonomy.cdm.api.service.IReferenceService; |
|
32 |
import eu.etaxonomy.cdm.api.service.IService; |
|
33 |
import eu.etaxonomy.cdm.api.service.IUserService; |
|
34 |
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService; |
|
35 |
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService; |
|
26 | 36 |
import eu.etaxonomy.cdm.common.CdmUtils; |
37 |
import eu.etaxonomy.cdm.model.agent.Institution; |
|
38 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
39 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
27 | 40 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
28 | 41 |
import eu.etaxonomy.cdm.model.common.Group; |
29 | 42 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
... | ... | |
31 | 44 |
import eu.etaxonomy.cdm.model.common.User; |
32 | 45 |
import eu.etaxonomy.cdm.model.molecular.Amplification; |
33 | 46 |
import eu.etaxonomy.cdm.model.molecular.Primer; |
47 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
|
48 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
|
49 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
50 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
34 | 51 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
35 | 52 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; |
53 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
36 | 54 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
55 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
37 | 56 |
import eu.etaxonomy.taxeditor.preference.Resources; |
38 | 57 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
39 | 58 |
import eu.etaxonomy.taxeditor.store.LoginManager; |
... | ... | |
158 | 177 |
} |
159 | 178 |
|
160 | 179 |
private void createControls(Composite parent, int style) { |
161 |
|
|
180 |
|
|
162 | 181 |
label = formFactory.createLabel(getLayoutComposite(), labelString, |
163 | 182 |
SWT.NULL); |
164 | 183 |
|
... | ... | |
405 | 424 |
|
406 | 425 |
private class EditListener extends SelectionAdapter { |
407 | 426 |
|
408 |
private final EntitySelectionElement<T> selectionElement; |
|
427 |
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"; |
|
428 |
private static final String TRANSIENT_EDITING_WARNING_TITLE = "CDM element not yet saved."; |
|
429 |
private final EntitySelectionElement<T> selectionElement; |
|
409 | 430 |
|
410 | 431 |
public EditListener(EntitySelectionElement<T> selectionElement) { |
411 | 432 |
this.selectionElement = selectionElement; |
... | ... | |
414 | 435 |
/** {@inheritDoc} */ |
415 | 436 |
@Override |
416 | 437 |
public void widgetSelected(SelectionEvent e) { |
438 |
T originalEntity = selectionElement.getEntity(); |
|
439 |
T clonedEntity = null; |
|
440 |
IService<T> service = null; |
|
441 |
if(originalEntity instanceof CdmBase){ |
|
442 |
//get corresponding service |
|
443 |
if(entity instanceof Reference<?>){ |
|
444 |
service = (IService<T>) CdmStore.getService(IReferenceService.class); |
|
445 |
} |
|
446 |
else if (entity instanceof Team || entity instanceof Person || entity instanceof Institution) { |
|
447 |
service = (IService<T>) CdmStore.getService(IAgentService.class); |
|
448 |
} |
|
449 |
else if (entity instanceof NonViralName) { |
|
450 |
service = (IService<T>) CdmStore.getService(INameService.class); |
|
451 |
} |
|
452 |
else if (entity instanceof SpecimenOrObservationBase) { |
|
453 |
service = (IService<T>) CdmStore.getService(IOccurrenceService.class); |
|
454 |
} |
|
455 |
else if (entity instanceof Collection) { |
|
456 |
service = (IService<T>) CdmStore.getService(ICollectionService.class); |
|
457 |
} |
|
458 |
else if (entity instanceof User) { |
|
459 |
service = (IService<T>) CdmStore.getService(IUserService.class); |
|
460 |
} |
|
461 |
else if (entity instanceof Primer) { |
|
462 |
service = (IService<T>) CdmStore.getService(IPrimerService.class); |
|
463 |
} |
|
464 |
else if (entity instanceof Amplification) { |
|
465 |
service = (IService<T>) CdmStore.getService(IAmplificationService.class); |
|
466 |
} |
|
467 |
//check if original already exists in data base. If not then do not clone and all changes will be persisted directly -> Warning to user. |
|
468 |
if(service !=null && service.find(originalEntity.getUuid())==null){ |
|
469 |
if(MessagingUtils.confirmDialog(TRANSIENT_EDITING_WARNING_TITLE, "["+originalEntity.getClass().getSimpleName()+"]"+originalEntity + " has to be saved before it can be edited. Save now?")){ |
|
470 |
service.save(originalEntity); |
|
471 |
AbstractUtility.getActiveEditor().doSave(new NullProgressMonitor()); |
|
472 |
} |
|
473 |
else{ |
|
474 |
//transient CDM elements should not be edited to avoid merge conflicts |
|
475 |
// when the elements are cascaded |
|
476 |
return; |
|
477 |
} |
|
478 |
} |
|
479 |
else{ |
|
480 |
try { |
|
481 |
//clone original |
|
482 |
clonedEntity = (T) ((CdmBase) originalEntity).clone(); |
|
483 |
} catch (CloneNotSupportedException e1) { |
|
484 |
MessagingUtils.warningDialog(TRANSIENT_EDITING_WARNING_TITLE, this, TRANSIENT_EDITING_WARNING_TEXT); |
|
485 |
} |
|
486 |
} |
|
487 |
|
|
488 |
} |
|
489 |
if(clonedEntity!=null){ |
|
490 |
selectionElement.setEntity(clonedEntity); |
|
491 |
} |
|
417 | 492 |
WizardDialog dialog = new WizardDialog(selectionElement.getShell(), |
418 | 493 |
new EditFromSelectionWizard(selectionElement)); |
419 | 494 |
if (dialog.open() == IStatus.OK) { |
495 |
if(service!=null && clonedEntity!=null){//check if cloning happened |
|
496 |
T editedClonedEntity = selectionElement.getEntity(); |
|
497 |
editedClonedEntity.setId(originalEntity.getId()); |
|
498 |
editedClonedEntity.setUuid(originalEntity.getUuid()); |
|
499 |
|
|
500 |
//merge clone and original |
|
501 |
service.merge(editedClonedEntity); |
|
502 |
originalEntity = service.load(originalEntity.getUuid()); |
|
503 |
|
|
504 |
} |
|
505 |
selectionElement.setEntity(originalEntity); |
|
420 | 506 |
selectionElement.updateFromWizard(); |
421 | 507 |
} |
508 |
//be sure to reset to original in all cases |
|
509 |
selectionElement.setEntity(originalEntity); |
|
422 | 510 |
} |
423 | 511 |
} |
424 | 512 |
|
Also available in: Unified diff