Merge branch 'release/3.12.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / handler / CreateHomotypicSynonymHandler.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.eclipse.core.commands.AbstractHandler;
13 import org.eclipse.core.commands.ExecutionEvent;
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.IHandler;
16 import org.eclipse.core.commands.common.NotDefinedException;
17
18 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
19 import eu.etaxonomy.cdm.model.name.NonViralName;
20 import eu.etaxonomy.cdm.model.taxon.Taxon;
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.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
25 import eu.etaxonomy.taxeditor.model.MessagingUtils;
26 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
27 import eu.etaxonomy.taxeditor.parser.ParseHandler;
28
29 /**
30 * <p>CreateHomotypicSynonymHandler class.</p>
31 *
32 * @author n.hoffmann
33 * @created 06.02.2009
34 * @version 1.0
35 */
36 public class CreateHomotypicSynonymHandler extends AbstractHandler implements
37 IHandler {
38
39 /* (non-Javadoc)
40 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
41 */
42 /** {@inheritDoc} */
43 @Override
44 public Object execute(ExecutionEvent event) throws ExecutionException {
45 TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
46 Page.NAME);
47 Taxon taxon = editor.getTaxon();
48 HomotypicalGroup group = taxon.getHomotypicGroup();
49 NonViralName newSynonymName = ParseHandler.createEmptyName();
50
51 AbstractPostOperation operation;
52 try {
53 operation = new CreateSynonymInExistingHomotypicalGroupOperation(event.getCommand().getName(),
54 editor.getUndoContext(), taxon, group, newSynonymName, editor);
55 EditorUtil.executeOperation(operation);
56 } catch (NotDefinedException e) {
57 MessagingUtils.error(getClass(), e);
58 }
59
60
61 return null;
62 }
63 }