Project

General

Profile

Download (2.09 KB) Statistics
| Branch: | Tag: | Revision:
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.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
24
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26

    
27
/**
28
 * @author l.morris
29
 * @date 21 Dec 2011
30
 *
31
 */
32
public class CreateTermVocabularyHandler extends AbstractHandler implements
33
		IHandler {
34

    
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
37
	 */
38
	@Override
39
	public Object execute(ExecutionEvent event) throws ExecutionException {
40
		IPostOperationEnabled editor = (IPostOperationEnabled) HandlerUtil
41
				.getActiveEditor(event);
42

    
43
		if (editor instanceof DefinedTermEditor){
44
			DefinedTermEditor dfe = (DefinedTermEditor) editor;
45

    
46
			try {
47
				String label = event.getCommand().getName();
48
				IUndoContext undoContext = StoreUtil.getUndoContext();
49

    
50
				AbstractPostOperation operation = 
51
						new CreateTermVocabularyOperation(label, 
52
								undoContext, 
53
								dfe.getDefinedTermEditorInput(), 
54
								(DefinedTermEditor) editor);
55
				StoreUtil.executeOperation(operation);
56

    
57
			} catch (NotDefinedException e) {
58
				MessagingUtils.error(getClass(), e);
59
			}			
60
		}
61
		return null;
62
	}
63
}
(2-2/4)