Revision a6de10b5
Added by Katja Luther over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/Messages.java | ||
---|---|---|
39 | 39 |
public static String DeleteTaxonBaseHandler_CONFIRM_DELETION; |
40 | 40 |
public static String DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT; |
41 | 41 |
public static String DeleteTaxonBaseHandler_REALLY_DELETE_TAXON; |
42 |
public static String DeleteTaxonBaseHandler_REALLY_DELETE_SYNONYM; |
|
42 | 43 |
public static String DerivateDropListener_MOVE_TO; |
43 | 44 |
public static String DerivateView_DERIVATIVE_EDITOR; |
44 | 45 |
public static String DerivateView_SAVING_HIERARCHY; |
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 |
|
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteSynonymOperation.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.editor.name.operation; |
11 | 11 |
|
12 |
import java.util.Set; |
|
13 |
|
|
14 | 12 |
import org.eclipse.core.commands.ExecutionException; |
15 | 13 |
import org.eclipse.core.commands.operations.IUndoContext; |
16 | 14 |
import org.eclipse.core.runtime.IAdaptable; |
17 | 15 |
import org.eclipse.core.runtime.IProgressMonitor; |
18 | 16 |
import org.eclipse.core.runtime.IStatus; |
17 |
import org.eclipse.ui.IWorkbenchPage; |
|
19 | 18 |
|
20 | 19 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
20 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
21 | 21 |
import eu.etaxonomy.cdm.api.service.DeleteResult; |
22 | 22 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
23 |
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator; |
|
23 | 24 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
24 | 25 |
import eu.etaxonomy.cdm.model.taxon.SynonymType; |
25 | 26 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
26 |
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin; |
|
27 |
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils; |
|
28 |
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation; |
|
29 | 27 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
28 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
30 | 29 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
31 | 30 |
|
32 | 31 |
/** |
... | ... | |
35 | 34 |
* @author p.ciardelli |
36 | 35 |
* @created 14.01.2009 |
37 | 36 |
*/ |
38 |
public class DeleteSynonymOperation extends AbstractPostTaxonOperation {
|
|
37 |
public class DeleteSynonymOperation extends DeleteTaxonBaseOperation {
|
|
39 | 38 |
|
40 | 39 |
private final Synonym synonym; |
41 | 40 |
private SynonymType synonymType; |
42 | 41 |
|
42 |
|
|
43 | 43 |
/** |
44 | 44 |
* <p>Constructor for DeleteSynonymOperation.</p> |
45 | 45 |
* |
... | ... | |
49 | 49 |
* @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object. |
50 | 50 |
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object. |
51 | 51 |
*/ |
52 |
public DeleteSynonymOperation(String label, IUndoContext undoContext, |
|
53 |
Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled) { |
|
54 |
super(label, undoContext, taxon, postOperationEnabled);
|
|
52 |
public DeleteSynonymOperation(String label, IUndoContext undoContext, TaxonBaseDeletionConfigurator configurator,IWorkbenchPage activePage,
|
|
53 |
Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled,ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
|
|
54 |
super(label, undoContext, configurator, activePage, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
|
|
55 | 55 |
this.synonym = synonym; |
56 | 56 |
} |
57 | 57 |
|
... | ... | |
75 | 75 |
|
76 | 76 |
} else { |
77 | 77 |
//TODO: this should be moved to the handler, the operations should not contain ui code |
78 |
DeleteResult result = service.deleteSynonym(synonym.getUuid(), null); |
|
79 |
if (result.isError()){ |
|
80 |
DeleteResultMessagingUtils.messageDialogWithDetails(result, "Delete failed", TaxeditorEditorPlugin.PLUGIN_ID); |
|
81 |
} else if (!result.getUpdatedObjects().isEmpty()){ |
|
82 |
DeleteResultMessagingUtils.messageDialogWithDetails(result, "The Synonym could be deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin.PLUGIN_ID); |
|
83 |
} |
|
78 |
setResult(service.deleteSynonym(synonym.getUuid(), null)); |
|
79 |
|
|
84 | 80 |
} |
85 | 81 |
// taxon.removeSynonym(synonym); |
86 | 82 |
// CdmStore.getTaxonService().deleteSynonymRelationships(synonym); |
... | ... | |
111 | 107 |
// Redraw editor if exists |
112 | 108 |
return postExecute(synonym); |
113 | 109 |
} |
110 |
|
|
111 |
/** |
|
112 |
* @return the result |
|
113 |
*/ |
|
114 |
@Override |
|
115 |
public DeleteResult getResult() { |
|
116 |
return result; |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* @param result the result to set |
|
121 |
*/ |
|
122 |
public void setResult(DeleteResult result) { |
|
123 |
this.result = result; |
|
124 |
} |
|
114 | 125 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteTaxonBaseOperation.java | ||
---|---|---|
8 | 8 |
import org.eclipse.ui.IWorkbenchPage; |
9 | 9 |
|
10 | 10 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
11 |
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; |
|
11 |
import eu.etaxonomy.cdm.api.service.DeleteResult; |
|
12 |
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator; |
|
12 | 13 |
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation; |
13 | 14 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
14 | 15 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
15 | 16 |
|
16 | 17 |
public class DeleteTaxonBaseOperation extends AbstractPersistentPostOperation { |
17 | 18 |
|
18 |
protected TaxonDeletionConfigurator configurator; |
|
19 |
protected TaxonBaseDeletionConfigurator configurator; |
|
20 |
protected DeleteResult result; |
|
19 | 21 |
|
20 | 22 |
public DeleteTaxonBaseOperation(String label, |
21 | 23 |
IUndoContext undoContext, |
22 |
TaxonDeletionConfigurator configurator, |
|
24 |
TaxonBaseDeletionConfigurator configurator,
|
|
23 | 25 |
IWorkbenchPage activePage, |
24 | 26 |
IPostOperationEnabled postOperationEnabled, |
25 | 27 |
IConversationEnabled conversationEnabled, |
... | ... | |
49 | 51 |
// TODO Auto-generated method stub |
50 | 52 |
return null; |
51 | 53 |
} |
54 |
|
|
55 |
public DeleteResult getResult(){ |
|
56 |
return result; |
|
57 |
} |
|
52 | 58 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteTaxonOperation.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
14 | 14 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
15 |
import eu.etaxonomy.cdm.api.service.DeleteResult; |
|
16 | 15 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
17 | 16 |
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; |
18 | 17 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
19 | 18 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
20 | 19 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
21 |
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin; |
|
22 |
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils; |
|
23 | 20 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
24 | 21 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
25 | 22 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
... | ... | |
72 | 69 |
|
73 | 70 |
ITaxonService service = controller.getTaxonService(); |
74 | 71 |
|
75 |
DeleteResult result = service.deleteTaxon(element.getUuid(), configurator, classification.getUuid());
|
|
72 |
result = service.deleteTaxon(element.getUuid(), (TaxonDeletionConfigurator)configurator, classification.getUuid());
|
|
76 | 73 |
|
77 |
if (result.isError()){ |
|
78 |
DeleteResultMessagingUtils.messageDialogWithDetails(result, "Delete failed", TaxeditorEditorPlugin.PLUGIN_ID); |
|
79 |
} else if (!result.getUpdatedObjects().isEmpty()){ |
|
80 |
DeleteResultMessagingUtils.messageDialogWithDetails(result, "The Taxon was deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin.PLUGIN_ID); |
|
81 |
} |
|
74 |
|
|
82 | 75 |
|
83 | 76 |
monitor.worked(40); |
84 | 77 |
|
eu.etaxonomy.taxeditor.editor/src/test/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteSynonymOperationTest.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
16 | 16 |
import org.junit.BeforeClass; |
17 | 17 |
import org.junit.Test; |
18 | 18 |
|
19 |
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator; |
|
19 | 20 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
20 | 21 |
import eu.etaxonomy.cdm.model.taxon.SynonymType; |
21 | 22 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
... | ... | |
33 | 34 |
private static Synonym synonym; |
34 | 35 |
|
35 | 36 |
private static SynonymType synonymType; |
36 |
|
|
37 |
|
|
37 | 38 |
/** |
38 | 39 |
* @throws java.lang.Exception |
39 | 40 |
*/ |
... | ... | |
42 | 43 |
taxon = Taxon.NewInstance(null, null); |
43 | 44 |
synonym = Synonym.NewInstance(null, null); |
44 | 45 |
synonymType = SynonymType.SYNONYM_OF(); |
45 |
|
|
46 |
|
|
46 | 47 |
taxon.addSynonym(synonym, synonymType); |
47 |
|
|
48 |
operation = new DeleteSynonymOperation("", undoContext, taxon, synonym, postOperation); |
|
48 |
|
|
49 |
operation = new DeleteSynonymOperation("", undoContext, new SynonymDeletionConfigurator(), null, taxon,synonym, postOperation, null, null); |
|
50 |
|
|
49 | 51 |
} |
50 | 52 |
|
51 | 53 |
/** |
52 | 54 |
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. |
53 |
* @throws ExecutionException
|
|
55 |
* @throws ExecutionException |
|
54 | 56 |
*/ |
55 | 57 |
@Test |
56 | 58 |
public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException { |
57 | 59 |
operation.execute(monitor, info); |
58 |
|
|
60 |
|
|
59 | 61 |
Assert.assertTrue(taxon.getSynonyms().size() == 0); |
60 | 62 |
} |
61 | 63 |
|
62 | 64 |
/** |
63 | 65 |
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. |
64 |
* @throws ExecutionException
|
|
66 |
* @throws ExecutionException |
|
65 | 67 |
*/ |
66 | 68 |
@Test |
67 | 69 |
public void testUndoIProgressMonitorIAdaptable() throws ExecutionException { |
68 | 70 |
operation.undo(monitor, info); |
69 |
|
|
71 |
|
|
70 | 72 |
Assert.assertTrue(taxon.getSynonyms().size() > 0); |
71 | 73 |
Assert.assertEquals(synonym, taxon.getSynonyms().toArray(new Synonym[0])[0]); |
72 | 74 |
} |
73 | 75 |
|
74 | 76 |
/** |
75 | 77 |
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. |
76 |
* @throws ExecutionException
|
|
78 |
* @throws ExecutionException |
|
77 | 79 |
*/ |
78 | 80 |
@Test |
79 | 81 |
public void testRedoIProgressMonitorIAdaptable() throws ExecutionException { |
80 | 82 |
operation.redo(monitor, info); |
81 |
|
|
83 |
|
|
82 | 84 |
Assert.assertTrue(taxon.getSynonyms().size() == 0); |
83 | 85 |
} |
84 | 86 |
} |
Also available in: Unified diff
ref #6219: add warning that synonym is deleted immediately