Project

General

Profile

Download (3.47 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.apache.log4j.Logger;
12
import org.eclipse.core.commands.AbstractHandler;
13
import org.eclipse.core.commands.ExecutionEvent;
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.commands.IHandler;
16
import org.eclipse.core.commands.common.NotDefinedException;
17
import org.eclipse.core.commands.operations.IUndoableOperation;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.ui.handlers.HandlerUtil;
21

    
22
import eu.etaxonomy.cdm.model.taxon.Synonym;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.taxeditor.editor.EditorUtil;
25
import eu.etaxonomy.taxeditor.editor.Page;
26
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
27
import eu.etaxonomy.taxeditor.propertysheet.name.ConceptPropertySource;
28
import eu.etaxonomy.taxeditor.propertysheet.name.MisapplicationPropertySource;
29
import eu.etaxonomy.taxeditor.propertysheet.name.SynonymPropertySource;
30
import eu.etaxonomy.taxeditor.propertysheet.name.TaxonBasePropertySource;
31
import eu.etaxonomy.taxeditor.store.operations.DeleteConceptRelationOperation;
32
import eu.etaxonomy.taxeditor.store.operations.DeleteMisapplicationOperation;
33
import eu.etaxonomy.taxeditor.store.operations.DeleteSynonymOperation;
34

    
35
/**
36
 * 
37
 * @author n.hoffmann
38
 * @created 21.04.2009
39
 * @version 1.0
40
 */
41
public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler {
42
	private static final Logger logger = Logger
43
								.getLogger(DeleteTaxonBaseHandler.class);
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46
	 */
47
	public Object execute(ExecutionEvent event) throws ExecutionException {
48
		TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
49
				Page.NAME);
50
		ISelection menuSelection = HandlerUtil.getActiveMenuSelection(event);
51
		
52
		TaxonBasePropertySource taxonBasePropertySource = (TaxonBasePropertySource) ((StructuredSelection) menuSelection).getFirstElement();
53
		
54
		IUndoableOperation operation = null;
55
		String commandName = null;
56
		
57
		try{
58
			commandName = event.getCommand().getName();
59
		}catch (NotDefinedException e) {
60
			logger.warn("Command name not set");
61
		}
62
		
63
		// synonym
64
		if(taxonBasePropertySource instanceof SynonymPropertySource){
65
			Synonym synonym = (Synonym) taxonBasePropertySource.getTaxonBase();
66
			operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), editor.getTaxon(), synonym, editor);
67
		}
68
		
69
		// misapplication
70
		if(taxonBasePropertySource instanceof MisapplicationPropertySource){
71
			Taxon misapplication = (Taxon) taxonBasePropertySource.getTaxonBase();
72
			operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor
73
					.getTaxon(), misapplication, editor);
74
		}
75
		
76
		// concept relation
77
		if(taxonBasePropertySource instanceof ConceptPropertySource){
78
			Taxon concept = (Taxon) taxonBasePropertySource.getTaxonBase();
79
			operation = new DeleteConceptRelationOperation(commandName, editor.getUndoContext(), editor.getTaxon(), concept, editor);
80
		}
81
				
82
		EditorUtil.executeOperation(operation);
83
		
84
		return null;
85
	}
86

    
87
}
(15-15/18)