I18n of login and data source view
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / handler / DeleteTaxonBaseHandler.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
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;
20
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;
37
38 /**
39 * @author n.hoffmann
40 * @created 21.04.2009
41 * @version 1.0
42 */
43 public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler, IPostOperationEnabled {
44
45 TaxonNameEditor editor;
46 /** {@inheritDoc} */
47 @Override
48 public Object execute(ExecutionEvent event) throws ExecutionException {
49 editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
50
51 Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
52
53 doExecute(event, editor, selectedElement);
54
55 return null;
56 }
57
58 protected void doExecute(ExecutionEvent event, TaxonNameEditor editor, Object selectedElement) {
59 AbstractPostOperation operation = null;
60 String commandName = null;
61
62 try {
63 commandName = event.getCommand().getName();
64 } catch (NotDefinedException e) {
65 MessagingUtils.error(getClass(), e);
66 }
67
68 // synonym
69 if(selectedElement instanceof Synonym){
70 operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
71 }
72 // misapplication
73 else if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
74 operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor
75 .getTaxon(), (Taxon) selectedElement, editor);
76 }
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)){
80 return ;
81 }
82
83 IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
84
85 operation = new DeleteTaxonOperation(commandName,
86 editor.getUndoContext(),
87 (Taxon) selectedElement,
88 new TaxonDeletionConfigurator(),
89 null,
90 activePage,
91 this,
92 editor,
93 (ICdmEntitySessionEnabled)editor.getEditorInput());
94 //editor.dispose();
95
96 }
97 else {
98 throw new IllegalArgumentException(Messages.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT);
99 }
100
101 AbstractUtility.executeOperation(operation);
102 }
103
104 @Override
105 public boolean postOperation(CdmBase objectAffectedByOperation) {
106 Display.getDefault().asyncExec(new Runnable(){
107
108 @Override
109 public void run() {
110 AbstractUtility.close(editor.getMultiPageTaxonEditor());
111 }
112 });
113 return true;
114 }
115
116 @Override
117 public boolean onComplete() {
118 // TODO Auto-generated method stub
119 return false;
120 }
121
122 }