ref #6595 Set visibility of context menu items in name editor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / handler / CreateMisapplicationHandler.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.editor.name.handler;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.core.commands.AbstractHandler;
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.core.commands.common.NotDefinedException;
17
18 import eu.etaxonomy.cdm.model.name.TaxonName;
19 import eu.etaxonomy.cdm.model.taxon.Taxon;
20 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
21 import eu.etaxonomy.taxeditor.editor.EditorUtil;
22 import eu.etaxonomy.taxeditor.editor.Page;
23 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
24 import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
25 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
26 import eu.etaxonomy.taxeditor.parser.ParseHandler;
27
28 /**
29 * <p>CreateMisapplicationHandler class.</p>
30 *
31 * @author n.hoffmann
32 * @created 16.04.2009
33 */
34 public class CreateMisapplicationHandler extends AbstractHandler {
35 private static final Logger logger = Logger
36 .getLogger(CreateMisapplicationHandler.class);
37
38 /** {@inheritDoc} */
39 public Object execute(ExecutionEvent event) throws ExecutionException {
40 TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
41 Page.NAME);
42
43
44 TaxonName conceptName = ParseHandler.createEmptyName();
45 Taxon concept = Taxon.NewInstance(conceptName, null);
46
47 TaxonRelationshipType type = TaxonRelationshipType.MISAPPLIED_NAME_FOR();
48
49 AbstractPostOperation<?> operation;
50 try {
51 operation = new CreateConceptRelationOperation(event.getCommand().getName(),
52 editor.getUndoContext(), editor.getTaxon(), concept, type, editor);
53 EditorUtil.executeOperation(operation);
54 } catch (NotDefinedException e) {
55 logger.warn("Command name not set"); //$NON-NLS-1$
56 }
57
58 return null;
59 }
60 }