Project

General

Profile

Download (2.12 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.view.uses.handler;
2

    
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.core.commands.common.NotDefinedException;
7
import org.eclipse.ui.IEditorInput;
8
import org.eclipse.ui.IEditorPart;
9
import org.eclipse.ui.IWorkbenchPart;
10
import org.eclipse.ui.forms.editor.FormEditor;
11
import org.eclipse.ui.handlers.HandlerUtil;
12

    
13
import eu.etaxonomy.cdm.model.taxon.Taxon;
14
import eu.etaxonomy.taxeditor.editor.EditorUtil;
15
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
16
import eu.etaxonomy.taxeditor.editor.view.uses.operation.CreateTaxonUseOperation;
17
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
18
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
19

    
20
/**
21
 * The context manager mediates context start/stop and workbench shutdowns to all registered listeners.
22
 *
23
 * @author a.theys	
24
 * @created mar 13, 2012
25
 * @version 1.0
26
 */
27
public class CreateUseHandler extends AbstractHandler {
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
30
	 */
31
	/** {@inheritDoc} */
32
	public Object execute(ExecutionEvent event) throws ExecutionException {
33
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
34
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
35
		
36
		
37
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
38
		if (editor instanceof FormEditor) {
39
			editor = ((FormEditor) editor).getActiveEditor();
40
		}
41
		IEditorInput input = editor.getEditorInput();
42
		if (input instanceof TaxonEditorInput) {
43
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();	
44
			AbstractPostOperation operation;
45
			try {
46
				operation = new CreateTaxonUseOperation(event.getCommand().getName(), 
47
						EditorUtil.getUndoContext(), taxon, postOperationEnabled);
48
				EditorUtil.executeOperation(operation);
49
			} catch (NotDefinedException e) {
50
				EditorUtil.warn(getClass(), "Command name not set.");
51
			}
52
		} 
53
		return null;
54
	}
55
}
(1-1/3)