3 * Copyright (C) 2009 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.
10 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.handler
;
12 import org
.eclipse
.core
.commands
.AbstractHandler
;
13 import org
.eclipse
.core
.commands
.ExecutionEvent
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.commands
.IHandler
;
16 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
21 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
22 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
24 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermEditor
;
25 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.operation
.CreateDefinedTermOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
35 public class CreateDefinedTermHandler
extends AbstractHandler
implements IHandler
{
41 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
45 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
46 IPostOperationEnabled editor
= (IPostOperationEnabled
) HandlerUtil
47 .getActiveEditor(event
);
49 if (editor
instanceof DefinedTermEditor
){
50 DefinedTermEditor dfe
= (DefinedTermEditor
) editor
;
51 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
52 .getCurrentSelection(event
);
53 if (selection
.getFirstElement() instanceof TermBase
) {
55 String label
= event
.getCommand().getName();
56 IUndoContext undoContext
= StoreUtil
.getUndoContext();
58 TermBase termBase
= (TermBase
) selection
.getFirstElement();
60 AbstractPostOperation operation
=
61 new CreateDefinedTermOperation(label
,
64 dfe
.getDefinedTermEditorInput(),
66 StoreUtil
.executeOperation(operation
);
68 } catch (NotDefinedException e
) {
69 StoreUtil
.error(getClass(), e
);