Project

General

Profile

Download (2.72 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 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

    
11
package eu.etaxonomy.taxeditor.editor.view.concept.handler;
12

    
13
import org.apache.log4j.Logger;
14
import org.eclipse.core.commands.AbstractHandler;
15
import org.eclipse.core.commands.ExecutionEvent;
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.commands.common.NotDefinedException;
18
import org.eclipse.swt.widgets.Event;
19
import org.eclipse.ui.IWorkbenchPart;
20
import org.eclipse.ui.handlers.HandlerUtil;
21

    
22
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
25
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
26
import eu.etaxonomy.taxeditor.editor.EditorUtil;
27
import eu.etaxonomy.taxeditor.editor.Page;
28
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
29
import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
31
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
32
import eu.etaxonomy.taxeditor.parser.ParseHandler;
33
import eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.TaxonBaseSelectionDialog;
34

    
35
/**
36
 * <p>CreateConceptRelationHandler class.</p>
37
 *
38
 * @author n.hoffmann
39
 * @created 16.04.2009
40
 * @version 1.0
41
 */
42
public class CreateConceptRelationHandler extends AbstractHandler {
43
	private static final Logger logger = Logger
44
			.getLogger(CreateConceptRelationHandler.class);
45

    
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
48
	 */
49
	/** {@inheritDoc} */
50
	public Object execute(ExecutionEvent event) throws ExecutionException {
51
		TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
52
				Page.NAME);
53
		
54
		Taxon relatedConcept = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), editor.getConversationHolder());
55
				
56
		TaxonRelationshipType type = (TaxonRelationshipType) ((Event)event.getTrigger()).data;
57
		
58
		IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
59
		IPostOperationEnabled postOperationEnabled = (activePart instanceof IPostOperationEnabled) ? (IPostOperationEnabled) activePart : null;
60
		
61
		try {
62
			AbstractPostOperation operation = new CreateConceptRelationOperation(event.getCommand().getName(), 
63
					editor.getUndoContext(), editor.getTaxon(), relatedConcept, type, postOperationEnabled);
64
			EditorUtil.executeOperation(operation);
65
		} catch (NotDefinedException e) {
66
			logger.warn("Command name not set");
67
		}
68
		
69
		return null;
70
	}
71
}
(5-5/8)