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
.di
.UISynchronize
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
17 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
18 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
22 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
23 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
24 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.SynonymDeletionConfigurator
;
26 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonBaseDeletionConfigurator
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
28 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
33 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
34 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
35 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
36 import eu
.etaxonomy
.taxeditor
.editor
.name
.handler
.NameEditorMenuPropertyTester
;
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
.store
.CdmStore
;
41 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.deleteConfigurator
.DeleteConfiguratorDialog
;
49 public class DeleteTaxonBaseHandlerE4
implements IPostOperationEnabled
{
51 protected TaxonNameEditorE4 editor
;
54 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
55 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
56 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
,
57 MHandledMenuItem menuItem
,
60 editor
= (TaxonNameEditorE4
) activePart
.getObject();
62 doExecute(menuItem
.getLocalizedLabel(), shell
, editor
, selection
.getFirstElement(), sync
);
66 protected void doExecute(String commandName
, Shell shell
, TaxonNameEditorE4 editor
, Object selectedElement
,
68 AbstractPostOperation operation
= null;
70 if (selectedElement
instanceof TaxonBase
){
71 if (((TaxonBase
)selectedElement
).getId() == 0){
72 if (selectedElement
instanceof Taxon
&&((Taxon
) selectedElement
).isMisapplication() ) {
73 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
74 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.PRO_PARTE_MISAPPLIED_NAME_FOR());
75 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.PARTIAL_MISAPPLIED_NAME_FOR());
76 } else if (selectedElement
instanceof Taxon
&&((Taxon
) selectedElement
).isProparteSynonym()) {
77 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.PRO_PARTE_SYNONYM_FOR());
78 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.PARTIAL_SYNONYM_FOR());
79 } else if (selectedElement
instanceof Synonym
){
80 editor
.getTaxon().removeSynonym((Synonym
)selectedElement
);
88 TaxonBaseDeletionConfigurator deleteConfig
;
89 ICdmRepository controller
;
91 controller
= CdmStore
.getCurrentApplicationConfiguration();
93 ITaxonService service
= controller
.getTaxonService();
96 if(selectedElement
instanceof Synonym
){
97 deleteConfig
= new SynonymDeletionConfigurator();
98 if(! DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, shell
, Messages
.DeleteTaxonBaseHandler_CONFIRM_DELETION
, Messages
.DeleteTaxonBaseHandler_REALLY_DELETE_SYNONYM
)){
102 // operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), deleteConfig, editor.getTaxon(), (Synonym) selectedElement,this, editor, editor.getEditorInput());
106 else if(selectedElement
instanceof Taxon
&& (((Taxon
) selectedElement
).isMisapplication() || ((Taxon
) selectedElement
).isProparteSynonym())){
107 deleteConfig
= new TaxonDeletionConfigurator();
108 if(! DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, shell
, Messages
.DeleteTaxonBaseHandler_CONFIRM_DELETION
, Messages
.DeleteTaxonBaseHandler_REALLY_DELETE_MISAPPLICATION
)){
112 // operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), deleteConfig, editor.getTaxon(), (Taxon) selectedElement,this, editor, editor.getEditorInput());
113 // editor.getEditorInput().addSynonymToDelete((TaxonBase)selectedElement,deleteConfig);
115 throw new IllegalArgumentException(Messages
.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT
);
117 result
= service
.isDeletable(((TaxonBase
)selectedElement
).getUuid(), deleteConfig
);
118 // AbstractUtility.executeOperation(operation, sync);
119 // = ((DeleteTaxonBaseOperation)operation).getResult();
121 if (result
.isError()){
122 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteDerivateOperation_DELETE_FAILED
, TaxeditorEditorPlugin
.PLUGIN_ID
);
123 } else if (selectedElement
instanceof Synonym
){
124 editor
.getEditorInput().addTaxonBaseToDelete((TaxonBase
)selectedElement
,deleteConfig
);
125 editor
.getTaxon().removeSynonym((Synonym
)selectedElement
);
127 if (!result
.getExceptions().isEmpty()){
128 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
130 } else if (selectedElement
instanceof Taxon
){
131 if (selectedElement
instanceof Taxon
&&((Taxon
) selectedElement
).isProparteSynonym() ) {
132 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.PRO_PARTE_SYNONYM_FOR());
134 editor
.getTaxon().removeTaxon((Taxon
)selectedElement
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
136 editor
.getEditorInput().addTaxonBaseToDelete((TaxonBase
)selectedElement
,deleteConfig
);
138 if ( !result
.getExceptions().isEmpty()){
139 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, Messages
.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
148 public boolean canExecute(
149 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
150 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
151 MHandledMenuItem menuItem
){
152 boolean canExecute
= false;
153 Object selectedElement
= selection
.getFirstElement();
155 NameEditorMenuPropertyTester
.isSynonym(selectedElement
)
156 || NameEditorMenuPropertyTester
.isMisapplication(selectedElement
)
157 || NameEditorMenuPropertyTester
.isRelatedConcept(selectedElement
);
158 menuItem
.setVisible(canExecute
);
163 public boolean postOperation(CdmBase objectAffectedByOperation
) {
169 public boolean onComplete() {