Project

General

Profile

Download (2.08 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.definedterm.handler;
10

    
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.IHandler;
15
import org.eclipse.core.commands.common.NotDefinedException;
16
import org.eclipse.core.commands.operations.IUndoContext;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

    
19
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
20
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateTermVocabularyOperation;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
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
				MessagingUtils.error(getClass(), e);
58
			}			
59
		}
60
		return null;
61
	}
62
}
(2-2/4)