3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.bulkeditor
.derivedunit
.handler
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.ui
.IEditorInput
;
20 import org
.eclipse
.ui
.IEditorPart
;
21 import org
.eclipse
.ui
.IWorkbenchPart
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
24 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
25 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
26 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
27 import eu
.etaxonomy
.taxeditor
.bulkeditor
.derivedunit
.operation
.AddDerivedUnitFacadeMediaOperation
;
28 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.OccurrenceEditorInput
;
29 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
30 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
34 * @created Feb 11, 2011
37 public abstract class AbstractAddDerivedUnitFacadeMediaHandler
extends AbstractHandler
{
40 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
43 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
44 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
45 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
48 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
49 IEditorInput input
= editor
.getEditorInput();
52 if(input
instanceof OccurrenceEditorInput
){
53 BulkEditor bulkEditor
= (BulkEditor
) editor
;
54 ISelection selection
= bulkEditor
.getSelectionProvider().getSelection();
56 if(selection
instanceof IStructuredSelection
){
57 Object element
= ((IStructuredSelection
) selection
).getFirstElement();
58 if(element
instanceof DerivedUnitBase
){
61 AbstractPostOperation operation
= new AddDerivedUnitFacadeMediaOperation(event
.getCommand().getName(), BulkEditorUtil
.getUndoContext(), (DerivedUnitBase
) element
, getMode(), postOperationEnabled
);
62 BulkEditorUtil
.executeOperation(operation
);
63 } catch (NotDefinedException e
) {
64 BulkEditorUtil
.warn(getClass(), "Command name not set.");
75 protected abstract int getMode();