Moved all logging and dialog functionality to the new class MessagingUtils.
[taxeditor.git] / eu.etaxonomy.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.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.model.MessagingUtils;
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
37 IWorkbenchPart part = HandlerUtil.getActivePart(event);
38 IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
39
40
41 IEditorPart editor = HandlerUtil.getActiveEditor(event);
42 IEditorInput input = editor.getEditorInput();
43 if (input instanceof TaxonEditorInput) {
44 Taxon taxon = ((TaxonEditorInput) input).getTaxon();
45 AbstractPostOperation operation;
46 try {
47 // TODO use undo context specific to editor
48 operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(),
49 EditorUtil.getUndoContext(), taxon, postOperationEnabled, true);
50 EditorUtil.executeOperation(operation);
51 } catch (NotDefinedException e) {
52 MessagingUtils.warn(getClass(), "Command name not set.");
53 }
54 }
55 return null;
56 }
57
58 }