Project

General

Profile

Download (1.95 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.editor.view.media.handler;
5

    
6
import org.eclipse.core.commands.AbstractHandler;
7
import org.eclipse.core.commands.ExecutionEvent;
8
import org.eclipse.core.commands.ExecutionException;
9
import org.eclipse.core.commands.common.NotDefinedException;
10
import org.eclipse.ui.IEditorInput;
11
import org.eclipse.ui.IEditorPart;
12
import org.eclipse.ui.IWorkbenchPart;
13
import org.eclipse.ui.handlers.HandlerUtil;
14

    
15
import eu.etaxonomy.cdm.model.taxon.Taxon;
16
import eu.etaxonomy.taxeditor.editor.EditorUtil;
17
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
18
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
19
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
20
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
21

    
22
/**
23
 * <p>AddImageGalleryHandler class.</p>
24
 *
25
 * @author p.ciardelli
26
 * @version $Id: $
27
 */
28
public class AddImageGalleryHandler extends AbstractHandler {
29

    
30
	/* (non-Javadoc)
31
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
32
	 */
33
	/** {@inheritDoc} */
34
	public Object execute(ExecutionEvent event) throws ExecutionException {
35

    
36
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
37
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
38
		
39
		
40
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
41
		IEditorInput input = editor.getEditorInput();
42
		if (input instanceof TaxonEditorInput) {
43
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();	
44
			AbstractPostOperation operation;
45
			try {
46
				// TODO use undo context specific to editor
47
				operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), 
48
						EditorUtil.getUndoContext(), taxon, postOperationEnabled, true);
49
				EditorUtil.executeOperation(operation);
50
			} catch (NotDefinedException e) {
51
				EditorUtil.warn(getClass(), "Command name not set.");
52
			}
53
		} 
54
		return null;
55
	}
56

    
57
}
(1-1/5)