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.IHandler;
|
17
|
import org.eclipse.core.commands.common.NotDefinedException;
|
18
|
import org.eclipse.jface.viewers.ISelection;
|
19
|
import org.eclipse.jface.viewers.StructuredSelection;
|
20
|
import org.eclipse.ui.handlers.HandlerUtil;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
23
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
24
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
25
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
26
|
import eu.etaxonomy.taxeditor.editor.Page;
|
27
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
28
|
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
|
29
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
30
|
import eu.etaxonomy.taxeditor.parser.ParseHandler;
|
31
|
|
32
|
/**
|
33
|
* <p>CreateSynonymInHomotypicalGroupHandler class.</p>
|
34
|
*
|
35
|
* @author n.hoffmann
|
36
|
* @created 21.04.2009
|
37
|
* @version 1.0
|
38
|
*/
|
39
|
public class CreateSynonymInHomotypicalGroupHandler extends AbstractHandler
|
40
|
implements IHandler {
|
41
|
private static final Logger logger = Logger
|
42
|
.getLogger(CreateSynonymInHomotypicalGroupHandler.class);
|
43
|
|
44
|
/* (non-Javadoc)
|
45
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
46
|
*/
|
47
|
/** {@inheritDoc} */
|
48
|
@Override
|
49
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
50
|
TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
|
51
|
Page.NAME);
|
52
|
ISelection menuSelection = HandlerUtil.getCurrentSelection(event);
|
53
|
|
54
|
Object selecteObject = ((StructuredSelection) menuSelection).getFirstElement();
|
55
|
|
56
|
if(! (selecteObject instanceof Synonym)){
|
57
|
return null;
|
58
|
}
|
59
|
|
60
|
|
61
|
Synonym synonym = (Synonym) selecteObject;
|
62
|
|
63
|
HomotypicalGroup group = synonym.getHomotypicGroup();
|
64
|
|
65
|
TaxonName newSynonymName = ParseHandler.createEmptyName();
|
66
|
|
67
|
AbstractPostOperation<?> operation;
|
68
|
|
69
|
try {
|
70
|
operation = new CreateSynonymInExistingHomotypicalGroupOperation(event.getCommand().getName(), editor.getUndoContext(),
|
71
|
editor.getTaxon(), group, newSynonymName, editor);
|
72
|
EditorUtil.executeOperation(operation);
|
73
|
} catch (NotDefinedException e) {
|
74
|
logger.warn("Command name not set"); //$NON-NLS-1$
|
75
|
}
|
76
|
|
77
|
return null;
|
78
|
}
|
79
|
}
|