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
.jface
.dialogs
.MessageDialog
;
17 import org
.eclipse
.swt
.widgets
.Display
;
18 import org
.eclipse
.ui
.IWorkbenchPage
;
19 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
21 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
22 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.Messages
;
27 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteMisapplicationOperation
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteSynonymOperation
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteTaxonOperation
;
32 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
33 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
34 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
35 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
36 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
43 public class DeleteTaxonBaseHandler
extends AbstractHandler
implements IHandler
, IPostOperationEnabled
{
45 TaxonNameEditor editor
;
48 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
49 editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
51 Object selectedElement
= EditorUtil
.getSelection(event
).getFirstElement();
53 doExecute(event
, editor
, selectedElement
);
58 protected void doExecute(ExecutionEvent event
, TaxonNameEditor editor
, Object selectedElement
) {
59 AbstractPostOperation operation
= null;
60 String commandName
= null;
63 commandName
= event
.getCommand().getName();
64 } catch (NotDefinedException e
) {
65 MessagingUtils
.error(getClass(), e
);
69 if(selectedElement
instanceof Synonym
){
70 operation
= new DeleteSynonymOperation(commandName
, editor
.getUndoContext(), editor
.getTaxon(), (Synonym
) selectedElement
, editor
);
73 else if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()){
74 operation
= new DeleteMisapplicationOperation(commandName
, editor
.getUndoContext(), editor
75 .getTaxon(), (Taxon
) selectedElement
, editor
);
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
)){
83 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
85 operation
= new DeleteTaxonOperation(commandName
,
86 editor
.getUndoContext(),
87 (Taxon
) selectedElement
,
88 new TaxonDeletionConfigurator(),
93 (ICdmEntitySessionEnabled
)editor
.getEditorInput());
98 throw new IllegalArgumentException(Messages
.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT
);
101 AbstractUtility
.executeOperation(operation
);
105 public boolean postOperation(CdmBase objectAffectedByOperation
) {
106 Display
.getDefault().asyncExec(new Runnable(){
110 AbstractUtility
.close(editor
.getMultiPageTaxonEditor());
117 public boolean onComplete() {
118 // TODO Auto-generated method stub