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
.CanExecute
;
14 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
15 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
17 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
21 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
22 import eu
.etaxonomy
.cdm
.api
.service
.config
.SynonymDeletionConfigurator
;
23 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
24 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
29 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
30 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
32 import eu
.etaxonomy
.taxeditor
.editor
.name
.handler
.NameEditorMenuPropertyTester
;
33 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteMisapplicationOperation
;
34 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteSynonymOperation
;
35 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteTaxonBaseOperation
;
36 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
37 import eu
.etaxonomy
.taxeditor
.model
.DeleteResultMessagingUtils
;
38 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
39 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
40 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.deleteConfigurator
.DeleteConfiguratorDialog
;
48 public class DeleteTaxonBaseHandlerE4
implements IPostOperationEnabled
{
50 protected TaxonNameEditorE4 editor
;
53 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
54 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
55 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
,
56 MHandledMenuItem menuItem
) {
58 editor
= (TaxonNameEditorE4
) activePart
.getObject();
60 doExecute(menuItem
.getLocalizedLabel(), shell
, editor
, selection
.getFirstElement());
64 protected void doExecute(String commandName
, Shell shell
, TaxonNameEditorE4 editor
, Object selectedElement
) {
65 AbstractPostOperation operation
= null;
67 if (selectedElement
instanceof TaxonBase
){
68 if (((TaxonBase
)selectedElement
).getId() == 0){
69 if (selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()) {
70 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
72 } else if (selectedElement
instanceof Synonym
){
73 editor
.getTaxon().removeSynonym((Synonym
)selectedElement
);
83 if(selectedElement
instanceof Synonym
){
84 SynonymDeletionConfigurator deleteConfig
= new SynonymDeletionConfigurator();
85 if(! DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, shell
, Messages
.DeleteTaxonBaseHandler_CONFIRM_DELETION
, Messages
.DeleteTaxonBaseHandler_REALLY_DELETE_SYNONYM
)){
88 operation
= new DeleteSynonymOperation(commandName
, editor
.getUndoContext(), deleteConfig
, editor
.getTaxon(), (Synonym
) selectedElement
,this, editor
, editor
.getEditorInput());
92 else if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()){
93 TaxonDeletionConfigurator deleteConfig
= new TaxonDeletionConfigurator();
94 if(! DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, shell
, Messages
.DeleteTaxonBaseHandler_CONFIRM_DELETION
, Messages
.DeleteTaxonBaseHandler_REALLY_DELETE_MISAPPLICATION
)){
97 operation
= new DeleteMisapplicationOperation(commandName
, editor
.getUndoContext(), deleteConfig
, editor
.getTaxon(), (Taxon
) selectedElement
,this, editor
, editor
.getEditorInput());
99 throw new IllegalArgumentException(Messages
.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT
);
102 AbstractUtility
.executeOperation(operation
);
103 DeleteResult result
= ((DeleteTaxonBaseOperation
)operation
).getResult();
105 if (result
.isError()){
106 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteDerivateOperation_DELETE_FAILED
, TaxeditorEditorPlugin
.PLUGIN_ID
);
107 } else if (selectedElement
instanceof Synonym
){
108 this.editor
.redraw();
109 if (!result
.getExceptions().isEmpty()){
110 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
112 } else if (selectedElement
instanceof Taxon
&& !result
.getExceptions().isEmpty()){
113 this.editor
.redraw();
114 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
120 public boolean canExecute(
121 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
122 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
123 MHandledMenuItem menuItem
){
124 boolean canExecute
= false;
125 Object selectedElement
= selection
.getFirstElement();
127 NameEditorMenuPropertyTester
.isSynonym(selectedElement
)
128 || NameEditorMenuPropertyTester
.isMisapplication(selectedElement
)
129 || NameEditorMenuPropertyTester
.isRelatedConcept(selectedElement
);
130 menuItem
.setVisible(canExecute
);
135 public boolean postOperation(CdmBase objectAffectedByOperation
) {
141 public boolean onComplete() {