ba294b8ae55cac3adb2528f14588aa302348b33d
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / media / handler / AddImageGalleryHandler.java
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.forms.editor.FormEditor;
14 import org.eclipse.ui.handlers.HandlerUtil;
15
16 import eu.etaxonomy.cdm.model.taxon.Taxon;
17 import eu.etaxonomy.taxeditor.editor.EditorUtil;
18 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
19 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
20 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
21 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
22
23 /**
24 * <p>AddImageGalleryHandler class.</p>
25 *
26 * @author p.ciardelli
27 * @version $Id: $
28 */
29 public class AddImageGalleryHandler extends AbstractHandler {
30
31 /* (non-Javadoc)
32 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
33 */
34 /** {@inheritDoc} */
35 public Object execute(ExecutionEvent event) throws ExecutionException {
36 IWorkbenchPart part = HandlerUtil.getActivePart(event);
37 IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
38
39
40 IEditorPart editor = HandlerUtil.getActiveEditor(event);
41 if (editor instanceof FormEditor) {
42 editor = ((FormEditor) editor).getActiveEditor();
43 }
44 IEditorInput input = editor.getEditorInput();
45 if (input instanceof TaxonEditorInput) {
46 Taxon taxon = ((TaxonEditorInput) input).getTaxon();
47 AbstractPostOperation operation;
48 try {
49 // TODO use undo context specific to editor
50 operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(),
51 EditorUtil.getUndoContext(), taxon, postOperationEnabled, true);
52 EditorUtil.executeOperation(operation);
53 } catch (NotDefinedException e) {
54 EditorUtil.warn(getClass(), "Command name not set.");
55 }
56 }
57 return null;
58 }
59
60 }