2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.handler
;
11 import org
.eclipse
.core
.commands
.AbstractHandler
;
12 import org
.eclipse
.core
.commands
.ExecutionEvent
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.IHandler
;
15 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
16 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
18 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
19 import eu
.etaxonomy
.cdm
.api
.service
.config
.SynonymDeletionConfigurator
;
20 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
21 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
26 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
27 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
28 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
29 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteMisapplicationOperation
;
32 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteSynonymOperation
;
33 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteTaxonBaseOperation
;
34 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
35 import eu
.etaxonomy
.taxeditor
.model
.DeleteResultMessagingUtils
;
36 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
37 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
38 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
39 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
40 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.deleteConfigurator
.DeleteConfiguratorDialog
;
47 public class DeleteTaxonBaseHandler
extends AbstractHandler
implements IHandler
, IPostOperationEnabled
{
49 TaxonNameEditor editor
;
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
53 editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
55 Object selectedElement
= EditorUtil
.getSelection(event
).getFirstElement();
57 doExecute(event
, editor
, selectedElement
);
62 protected void doExecute(ExecutionEvent event
, TaxonNameEditor editor
, Object selectedElement
) {
63 AbstractPostOperation operation
= null;
64 String commandName
= null;
67 commandName
= event
.getCommand().getName();
68 } catch (NotDefinedException e
) {
69 MessagingUtils
.error(getClass(), e
);
71 if (selectedElement
instanceof TaxonBase
){
72 if (((TaxonBase
)selectedElement
).getId() == 0){
73 if (selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()) {
74 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
76 } else if (selectedElement
instanceof Synonym
){
77 editor
.getTaxon().removeSynonym((Synonym
)selectedElement
);
87 if(selectedElement
instanceof Synonym
){
88 SynonymDeletionConfigurator deleteConfig
= new SynonymDeletionConfigurator();
89 if(! DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, HandlerUtil
.getActiveShell(event
), Messages
.DeleteTaxonBaseHandler_CONFIRM_DELETION
, Messages
.DeleteTaxonBaseHandler_REALLY_DELETE_SYNONYM
)){
92 operation
= new DeleteSynonymOperation(commandName
, editor
.getUndoContext(), deleteConfig
, editor
.getTaxon(), (Synonym
) selectedElement
,this, editor
, (ICdmEntitySessionEnabled
)editor
.getEditorInput());
96 else if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()){
97 TaxonDeletionConfigurator deleteConfig
= new TaxonDeletionConfigurator();
98 if(! DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, HandlerUtil
.getActiveShell(event
), Messages
.DeleteTaxonBaseHandler_CONFIRM_DELETION
, Messages
.DeleteTaxonBaseHandler_REALLY_DELETE_MISAPPLICATION
)){
101 operation
= new DeleteMisapplicationOperation(commandName
, editor
.getUndoContext(), deleteConfig
, editor
.getTaxon(), (Taxon
) selectedElement
,this, editor
, (ICdmEntitySessionEnabled
)editor
.getEditorInput());
103 throw new IllegalArgumentException(Messages
.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT
);
106 AbstractUtility
.executeOperation(operation
);
107 DeleteResult result
= ((DeleteTaxonBaseOperation
)operation
).getResult();
109 if (result
.isError()){
110 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteDerivateOperation_DELETE_FAILED
, TaxeditorEditorPlugin
.PLUGIN_ID
);
111 } else if (selectedElement
instanceof Synonym
){
112 this.editor
.redraw();
113 if (!result
.getExceptions().isEmpty()){
114 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
116 } else if (selectedElement
instanceof Taxon
&& !result
.getExceptions().isEmpty()){
117 this.editor
.redraw();
118 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
126 public boolean postOperation(CdmBase objectAffectedByOperation
) {
132 public boolean onComplete() {