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
.editor
.view
.descriptive
.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
.swt
.widgets
.Event
;
20 import org
.eclipse
.ui
.IWorkbenchPart
;
21 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
24 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateDescriptionElementOperation
;
27 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
28 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
29 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
32 * <p>CreateDescriptionElementHandler class.</p>
38 public class CreateDescriptionElementHandler
extends AbstractHandler
{
44 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
49 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
50 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
51 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
55 DescriptionBase
<?
> description
= null;
57 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
58 if (selection
instanceof IStructuredSelection
) {
59 Object selectedElement
= ((IStructuredSelection
) selection
).getFirstElement();
60 if (selectedElement
instanceof DescriptionBase
<?
>) {
61 description
= (DescriptionBase
<?
>) selectedElement
;
65 if (description
!= null) {
66 AbstractPostOperation operation
= null;
68 // TODO use undo context specific to editor
69 operation
= operationCreationInstance(event
.getCommand().getName(), event
, description
, postOperationEnabled
);
70 AbstractUtility
.executeOperation(operation
);
71 } catch (NotDefinedException e
) {
72 AbstractUtility
.warn(getClass(), "Command name not set");
75 AbstractUtility
.error(getClass(), new IllegalArgumentException("Could not determine the taxon description"));
83 * Added to make the Class more generic and limit the amount of code changes required
88 * @param postOperationEnabled
91 protected AbstractPostOperation
operationCreationInstance(String label
, ExecutionEvent event
, DescriptionBase
<?
> description
, IPostOperationEnabled postOperationEnabled
) {
92 Feature feature
= (Feature
) ((Event
) event
.getTrigger()).data
;
93 return new CreateDescriptionElementOperation(label
, EditorUtil
.getUndoContext(), description
, feature
, postOperationEnabled
);