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
.e4
.handler
;
11 import javax
.inject
.Named
;
13 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
14 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
15 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
16 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
17 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import org
.eclipse
.swt
.widgets
.Shell
;
20 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
21 import eu
.etaxonomy
.cdm
.api
.service
.config
.SynonymDeletionConfigurator
;
22 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
28 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
29 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
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
.operation
.AbstractPostOperation
;
37 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
38 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.deleteConfigurator
.DeleteConfiguratorDialog
;
46 public class DeleteTaxonBaseHandlerE4
implements IPostOperationEnabled
{
48 protected TaxonNameEditorE4 editor
;
51 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
52 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
53 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
,
54 MHandledMenuItem menuItem
) {
56 editor
= (TaxonNameEditorE4
) activePart
.getObject();
58 doExecute(menuItem
.getLocalizedLabel(), shell
, editor
, selection
.getFirstElement());
62 protected void doExecute(String commandName
, Shell shell
, TaxonNameEditorE4 editor
, Object selectedElement
) {
63 AbstractPostOperation operation
= null;
65 if (selectedElement
instanceof TaxonBase
){
66 if (((TaxonBase
)selectedElement
).getId() == 0){
67 if (selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()) {
68 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
70 } else if (selectedElement
instanceof Synonym
){
71 editor
.getTaxon().removeSynonym((Synonym
)selectedElement
);
81 if(selectedElement
instanceof Synonym
){
82 SynonymDeletionConfigurator deleteConfig
= new SynonymDeletionConfigurator();
83 if(! DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, shell
, Messages
.DeleteTaxonBaseHandler_CONFIRM_DELETION
, Messages
.DeleteTaxonBaseHandler_REALLY_DELETE_SYNONYM
)){
86 operation
= new DeleteSynonymOperation(commandName
, editor
.getUndoContext(), deleteConfig
, editor
.getTaxon(), (Synonym
) selectedElement
,this, editor
, editor
.getEditorInput());
90 else if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()){
91 TaxonDeletionConfigurator deleteConfig
= new TaxonDeletionConfigurator();
92 if(! DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, shell
, Messages
.DeleteTaxonBaseHandler_CONFIRM_DELETION
, Messages
.DeleteTaxonBaseHandler_REALLY_DELETE_MISAPPLICATION
)){
95 operation
= new DeleteMisapplicationOperation(commandName
, editor
.getUndoContext(), deleteConfig
, editor
.getTaxon(), (Taxon
) selectedElement
,this, editor
, editor
.getEditorInput());
97 throw new IllegalArgumentException(Messages
.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT
);
100 AbstractUtility
.executeOperation(operation
);
101 DeleteResult result
= ((DeleteTaxonBaseOperation
)operation
).getResult();
103 if (result
.isError()){
104 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteDerivateOperation_DELETE_FAILED
, TaxeditorEditorPlugin
.PLUGIN_ID
);
105 } else if (selectedElement
instanceof Synonym
){
106 this.editor
.redraw();
107 if (!result
.getExceptions().isEmpty()){
108 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
110 } else if (selectedElement
instanceof Taxon
&& !result
.getExceptions().isEmpty()){
111 this.editor
.redraw();
112 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
120 public boolean postOperation(CdmBase objectAffectedByOperation
) {
126 public boolean onComplete() {