merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / editor / definedterm / handler / CreateTermVocabularyHandler.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.taxeditor.editor.definedterm.handler;
11
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.ui.handlers.HandlerUtil;
19
20 import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
21 import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateTermVocabularyOperation;
22 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
23 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24 import eu.etaxonomy.taxeditor.store.StoreUtil;
25
26 /**
27 * @author l.morris
28 * @date 21 Dec 2011
29 *
30 */
31 public class CreateTermVocabularyHandler extends AbstractHandler implements
32 IHandler {
33
34 /* (non-Javadoc)
35 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
36 */
37 @Override
38 public Object execute(ExecutionEvent event) throws ExecutionException {
39 IPostOperationEnabled editor = (IPostOperationEnabled) HandlerUtil
40 .getActiveEditor(event);
41
42 if (editor instanceof DefinedTermEditor){
43 DefinedTermEditor dfe = (DefinedTermEditor) editor;
44
45 try {
46 String label = event.getCommand().getName();
47 IUndoContext undoContext = StoreUtil.getUndoContext();
48
49 AbstractPostOperation operation =
50 new CreateTermVocabularyOperation(label,
51 undoContext,
52 dfe.getDefinedTermEditorInput(),
53 (DefinedTermEditor) editor);
54 StoreUtil.executeOperation(operation);
55
56 } catch (NotDefinedException e) {
57 StoreUtil.error(getClass(), e);
58 }
59 }
60 return null;
61 }
62 }