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
.checklist
.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
.jface
.viewers
.ITreeSelection
;
20 import org
.eclipse
.jface
.viewers
.TreePath
;
21 import org
.eclipse
.swt
.widgets
.Event
;
22 import org
.eclipse
.ui
.IWorkbenchPart
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
26 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
27 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
28 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateDescriptionElementOperation
;
29 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 * <p>CreateDescriptionElementHandler class.</p>
41 public class CreateDescriptionElementHandler
extends AbstractHandler
{
47 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
53 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
54 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
58 DescriptionBase
<?
> description
= null;
60 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
61 Object selectedElement
= null;
62 if (selection
instanceof ITreeSelection
) {
63 TreePath
[] paths
= ((ITreeSelection
) selection
).getPaths();
64 selectedElement
= paths
[0].getFirstSegment();
66 else if (selection
instanceof IStructuredSelection
) {
67 selectedElement
= ((IStructuredSelection
) selection
).getFirstElement();
69 if (selectedElement
instanceof DescriptionBase
<?
>) {
70 description
= (DescriptionBase
<?
>) selectedElement
;
73 if (description
!= null) {
74 AbstractPostOperation operation
= null;
76 // TODO use undo context specific to editor
77 operation
= operationCreationInstance(event
.getCommand().getName(), event
, description
, postOperationEnabled
);
78 AbstractUtility
.executeOperation(operation
);
79 } catch (NotDefinedException e
) {
80 MessagingUtils
.warn(getClass(), "Command name not set");
83 MessagingUtils
.error(getClass(), new IllegalArgumentException("Could not determine the taxon description"));
91 * Added to make the Class more generic and limit the amount of code changes required
96 * @param postOperationEnabled
99 protected AbstractPostOperation
operationCreationInstance(String label
, ExecutionEvent event
, DescriptionBase
<?
> description
, IPostOperationEnabled postOperationEnabled
) {
100 Feature feature
= (Feature
) ((Event
) event
.getTrigger()).data
;
101 return new CreateDescriptionElementOperation(label
, EditorUtil
.getUndoContext(), description
, feature
, postOperationEnabled
);