Project

General

Profile

Download (2.17 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.editor.descriptionnew.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.common.NotDefinedException;
16
import org.eclipse.core.commands.operations.IUndoableOperation;
17
import org.eclipse.ui.IEditorInput;
18
import org.eclipse.ui.IEditorPart;
19
import org.eclipse.ui.handlers.HandlerUtil;
20

    
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22
import eu.etaxonomy.taxeditor.editor.EditorUtil;
23
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
24
import eu.etaxonomy.taxeditor.editor.description.handler.CreateDescriptionElementHandler;
25
import eu.etaxonomy.taxeditor.operations.CreateTaxonDescriptionOperation;
26
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
27

    
28
/**
29
 * @author p.ciardelli
30
 * @created 11.08.2009
31
 * @version 1.0
32
 */
33
public class AddDescriptionHandler extends AbstractHandler {
34
	private static final Logger logger = Logger
35
			.getLogger(CreateDescriptionElementHandler.class);
36

    
37
	/* (non-Javadoc)
38
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
39
	 */
40
	public Object execute(ExecutionEvent event) throws ExecutionException {
41
		
42
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
43
		IEditorInput input = editor.getEditorInput();
44
		if (input instanceof TaxonEditorInput) {
45
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();	
46
			IUndoableOperation operation;
47
			try {
48
				// TODO use undo context specific to editor
49
				operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), 
50
						EditorUtil.getUndoContext(), taxon, (IPostOperationEnabled) editor);
51
				EditorUtil.executeOperation(operation);
52
			} catch (NotDefinedException e) {
53
				logger.warn("Command name not set");
54
			}
55
		} 
56
		return null;
57
	}
58

    
59
}
(1-1/2)