Project

General

Profile

Download (2.45 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.jface.viewers.IStructuredSelection;
18
import org.eclipse.ui.handlers.HandlerUtil;
19

    
20
import eu.etaxonomy.cdm.model.common.TermBase;
21
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
22
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
23
import eu.etaxonomy.taxeditor.model.MessagingUtils;
24
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
25
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26
import eu.etaxonomy.taxeditor.store.StoreUtil;
27

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

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

    
47
		if (editor instanceof DefinedTermEditor){
48
			DefinedTermEditor dfe = (DefinedTermEditor) editor;
49
			IStructuredSelection selection = (IStructuredSelection) HandlerUtil
50
					.getCurrentSelection(event);
51
			if (selection.getFirstElement() instanceof TermBase) {
52
				try {
53
					String label = event.getCommand().getName();
54
					IUndoContext undoContext = StoreUtil.getUndoContext();
55

    
56
					TermBase termBase = (TermBase) selection.getFirstElement();
57

    
58
					AbstractPostOperation operation = 
59
							new CreateDefinedTermOperation(label, 
60
									undoContext, 
61
									termBase, 
62
									dfe.getDefinedTermEditorInput(),
63
									editor);
64
					StoreUtil.executeOperation(operation);
65

    
66
				} catch (NotDefinedException e) {
67
					MessagingUtils.error(getClass(), e);
68
				}
69
			}
70
		}
71

    
72
		return null;
73
	}
74

    
75
	}
(1-1/4)