Project

General

Profile

Download (2.36 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.common.NotDefinedException;
15
import org.eclipse.core.commands.operations.IUndoContext;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

    
19
import eu.etaxonomy.cdm.model.common.TermBase;
20
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
21
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
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 CreateDefinedTermHandler extends AbstractHandler {
33

    
34
	@Override
35
	public Object execute(ExecutionEvent event) throws ExecutionException {
36
	    boolean addTermAsKindOf =
37
	            event.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm")?true:false;
38

    
39
		IPostOperationEnabled editor = (IPostOperationEnabled) HandlerUtil
40
				.getActiveEditor(event);
41

    
42
		if (editor instanceof DefinedTermEditor){
43
			DefinedTermEditor dfe = (DefinedTermEditor) editor;
44
			IStructuredSelection selection = (IStructuredSelection) HandlerUtil
45
					.getCurrentSelection(event);
46
			if (selection.getFirstElement() instanceof TermBase) {
47
				try {
48
					String label = event.getCommand().getName();
49
					IUndoContext undoContext = StoreUtil.getUndoContext();
50

    
51
					TermBase termBase = (TermBase) selection.getFirstElement();
52

    
53
					AbstractPostOperation operation =
54
							new CreateDefinedTermOperation(label,
55
									undoContext,
56
									termBase,
57
									dfe.getDefinedTermEditorInput(),
58
									editor, addTermAsKindOf);
59

    
60
				} catch (NotDefinedException e) {
61
					MessagingUtils.error(getClass(), e);
62
				}
63
			}
64
		}
65

    
66
		return null;
67
	}
68

    
69
	}
(1-1/4)