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
.api
.facade
.DerivedUnitFacade
;
25 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
26 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
27 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
28 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
30 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.derivedunit
.operation
.AddDerivedUnitMediaOperation
;
33 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.OccurrenceEditorInput
;
34 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
35 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
39 * @created Feb 7, 2011
42 public class AddDerivedUnitMediaHandler
extends AbstractHandler
{
45 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
48 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
49 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
50 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
53 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
54 IEditorInput input
= editor
.getEditorInput();
56 if(input
instanceof OccurrenceEditorInput
){
57 BulkEditor bulkEditor
= (BulkEditor
) editor
;
58 ISelection selection
= bulkEditor
.getSelectionProvider().getSelection();
60 if(selection
instanceof IStructuredSelection
){
61 Object element
= ((IStructuredSelection
) selection
).getFirstElement();
62 if(element
instanceof DerivedUnitBase
){
65 AbstractPostOperation operation
= new AddDerivedUnitMediaOperation(event
.getCommand().getName(), BulkEditorUtil
.getUndoContext(), (DerivedUnitBase
) element
, postOperationEnabled
);
66 BulkEditorUtil
.executeOperation(operation
);
67 } catch (NotDefinedException e
) {
68 BulkEditorUtil
.warn(getClass(), "Command name not set.");