Revision a6de10b5
Added by Katja Luther over 7 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java | ||
---|---|---|
14 | 14 |
import org.eclipse.core.commands.IHandler; |
15 | 15 |
import org.eclipse.core.commands.common.NotDefinedException; |
16 | 16 |
import org.eclipse.jface.dialogs.MessageDialog; |
17 |
import org.eclipse.swt.widgets.Display; |
|
18 | 17 |
import org.eclipse.ui.IWorkbenchPage; |
19 | 18 |
import org.eclipse.ui.handlers.HandlerUtil; |
20 | 19 |
|
21 |
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; |
|
20 |
import eu.etaxonomy.cdm.api.service.DeleteResult; |
|
21 |
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator; |
|
22 | 22 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
23 | 23 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
24 | 24 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
25 | 25 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
26 | 26 |
import eu.etaxonomy.taxeditor.editor.Messages; |
27 | 27 |
import eu.etaxonomy.taxeditor.editor.Page; |
28 |
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin; |
|
28 | 29 |
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor; |
29 | 30 |
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteMisapplicationOperation; |
30 | 31 |
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation; |
31 |
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteTaxonOperation; |
|
32 |
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteTaxonBaseOperation;
|
|
32 | 33 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
34 |
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils; |
|
33 | 35 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
34 | 36 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
35 | 37 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
... | ... | |
64 | 66 |
} catch (NotDefinedException e) { |
65 | 67 |
MessagingUtils.error(getClass(), e); |
66 | 68 |
} |
67 |
|
|
69 |
IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); |
|
68 | 70 |
// synonym |
69 | 71 |
if(selectedElement instanceof Synonym){ |
70 |
operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor); |
|
72 |
if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), Messages.DeleteTaxonBaseHandler_CONFIRM_DELETION, Messages.DeleteTaxonBaseHandler_REALLY_DELETE_SYNONYM)){ |
|
73 |
return ; |
|
74 |
} |
|
75 |
operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), new SynonymDeletionConfigurator(), activePage, editor.getTaxon(), (Synonym) selectedElement,this, editor, (ICdmEntitySessionEnabled)editor.getEditorInput()); |
|
76 |
|
|
71 | 77 |
} |
72 | 78 |
// misapplication |
73 | 79 |
else if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){ |
74 | 80 |
operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor |
75 | 81 |
.getTaxon(), (Taxon) selectedElement, editor); |
76 | 82 |
} |
77 |
else if (selectedElement instanceof Taxon){ |
|
78 |
//TODO: how to get the actual classification |
|
79 |
if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), Messages.DeleteTaxonBaseHandler_CONFIRM_DELETION, Messages.DeleteTaxonBaseHandler_REALLY_DELETE_TAXON)){ |
|
80 |
return ; |
|
81 |
} |
|
82 |
|
|
83 |
IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); |
|
84 |
|
|
85 |
operation = new DeleteTaxonOperation(commandName, |
|
86 |
editor.getUndoContext(), |
|
87 |
(Taxon) selectedElement, |
|
88 |
new TaxonDeletionConfigurator(), |
|
89 |
null, |
|
90 |
activePage, |
|
91 |
this, |
|
92 |
editor, |
|
93 |
(ICdmEntitySessionEnabled)editor.getEditorInput()); |
|
94 |
//editor.dispose(); |
|
95 |
|
|
96 |
} |
|
97 | 83 |
else { |
98 | 84 |
throw new IllegalArgumentException(Messages.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT); |
99 | 85 |
} |
100 | 86 |
|
101 | 87 |
AbstractUtility.executeOperation(operation); |
88 |
DeleteResult result = ((DeleteTaxonBaseOperation)operation).getResult(); |
|
89 |
if (result.isError()){ |
|
90 |
DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteDerivateOperation_DELETE_FAILED, TaxeditorEditorPlugin.PLUGIN_ID); |
|
91 |
} else if (selectedElement instanceof Synonym){ |
|
92 |
this.editor.redraw(); |
|
93 |
if (!result.getUpdatedObjects().isEmpty()){ |
|
94 |
DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID); |
|
95 |
} |
|
96 |
}else { |
|
97 |
if (!result.getUpdatedObjects().isEmpty()){ |
|
98 |
DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
@Override |
105 | 105 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
106 |
Display.getDefault().asyncExec(new Runnable(){ |
|
107 | 106 |
|
108 |
@Override |
|
109 |
public void run() { |
|
110 |
AbstractUtility.close(editor.getMultiPageTaxonEditor()); |
|
111 |
} |
|
112 |
}); |
|
113 | 107 |
return true; |
114 | 108 |
} |
115 | 109 |
|
116 | 110 |
@Override |
117 | 111 |
public boolean onComplete() { |
118 |
// TODO Auto-generated method stub |
|
112 |
|
|
119 | 113 |
return false; |
120 | 114 |
} |
121 | 115 |
|
Also available in: Unified diff
ref #6219: add warning that synonym is deleted immediately