Project

General

Profile

Download (4.08 KB) Statistics
| Branch: | Tag: | Revision:
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.Page;
27
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
28
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteMisapplicationOperation;
29
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation;
30
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteTaxonOperation;
31
import eu.etaxonomy.taxeditor.model.AbstractUtility;
32
import eu.etaxonomy.taxeditor.model.MessagingUtils;
33
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
34
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
35

    
36
/**
37
 * <p>DeleteTaxonBaseHandler class.</p>
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
	/* (non-Javadoc)
47
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
48
	 */
49
	/** {@inheritDoc} */
50
	@Override
51
    public Object execute(ExecutionEvent event) throws ExecutionException {
52
		editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
53

    
54
		Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
55

    
56
		doExecute(event, editor, selectedElement);
57

    
58
		return null;
59
	}
60

    
61
	/**
62
	 * @param editor
63
	 * @param selectedElement
64
	 * @param operation
65
	 * @param commandName
66
	 */
67
	protected void doExecute(ExecutionEvent event, TaxonNameEditor editor, Object selectedElement) {
68
		AbstractPostOperation operation = null;
69
		String commandName = null;
70

    
71
		try {
72
			commandName = event.getCommand().getName();
73
		} catch (NotDefinedException e) {
74
			MessagingUtils.error(getClass(), e);
75
		}
76

    
77
		// synonym
78
		if(selectedElement instanceof Synonym){
79
			operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
80
		}
81
		// misapplication
82
		else if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
83
			operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor
84
					.getTaxon(), (Taxon) selectedElement, editor);
85
		}
86
		else if (selectedElement instanceof Taxon){
87
			//TODO: how to get the actual classification
88
			if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Are you sure you want to delete the selected taxon?")){
89
				return ;
90
			}
91

    
92
			IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
93

    
94
			operation = new DeleteTaxonOperation(commandName, editor.getUndoContext(),(Taxon) selectedElement, new TaxonDeletionConfigurator(), null, activePage, this, editor);
95
			//editor.dispose();
96

    
97
		}
98
		else {
99
			throw new IllegalArgumentException("Element has to be Synonym, Misapplication or Concept");
100
		}
101

    
102
		AbstractUtility.executeOperation(operation);
103
	}
104

    
105
	@Override
106
	public boolean postOperation(CdmBase objectAffectedByOperation) {
107
		Display.getDefault().asyncExec(new Runnable(){
108

    
109
			@Override
110
            public void run() {
111
				AbstractUtility.close(editor.getMultiPageTaxonEditor());
112
			}
113
		});
114
		return true;
115
	}
116

    
117
	@Override
118
	public boolean onComplete() {
119
		// TODO Auto-generated method stub
120
		return false;
121
	}
122

    
123
}
(10-10/15)