1
|
package eu.etaxonomy.taxeditor.editor.name.handler;
|
2
|
|
3
|
import java.util.UUID;
|
4
|
|
5
|
import org.apache.log4j.Logger;
|
6
|
import org.eclipse.core.commands.AbstractHandler;
|
7
|
import org.eclipse.core.commands.ExecutionEvent;
|
8
|
import org.eclipse.core.commands.ExecutionException;
|
9
|
import org.eclipse.core.commands.common.NotDefinedException;
|
10
|
import org.eclipse.core.commands.operations.IUndoContext;
|
11
|
import org.eclipse.jface.dialogs.MessageDialog;
|
12
|
import org.eclipse.jface.viewers.StructuredSelection;
|
13
|
import org.eclipse.swt.widgets.Shell;
|
14
|
import org.eclipse.ui.IEditorInput;
|
15
|
import org.eclipse.ui.handlers.HandlerUtil;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
18
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
19
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
20
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
22
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
23
|
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
|
24
|
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
|
25
|
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
|
26
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
27
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
28
|
|
29
|
public class MoveSynonymToAnotherAcceptedTaxonHandler extends AbstractHandler implements IPostOperationEnabled {
|
30
|
private static final Logger logger = Logger
|
31
|
.getLogger(MoveSynonymToAnotherAcceptedTaxonHandler.class);
|
32
|
private MultiPageTaxonEditor editor;
|
33
|
|
34
|
@Override
|
35
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
36
|
editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event);
|
37
|
Shell shell = HandlerUtil.getActiveShell(event);
|
38
|
IEditorInput input = editor.getEditorInput();
|
39
|
if (!EditorUtil.forceUserSave(editor, shell)) {
|
40
|
return null;
|
41
|
}
|
42
|
|
43
|
if (!(input instanceof TaxonEditorInput)) {
|
44
|
logger.error("Editor input is not TaxonEditorInput");
|
45
|
return null;
|
46
|
}
|
47
|
|
48
|
// Get synonym from selection
|
49
|
StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
|
50
|
if (!(selection.getFirstElement() instanceof Synonym)) {
|
51
|
logger.error("Selection does not contain a Synonym");
|
52
|
return null;
|
53
|
}
|
54
|
|
55
|
Synonym synonym = (Synonym) selection.getFirstElement();
|
56
|
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select new accepted taxon", null, null, null);
|
57
|
Taxon oldParent = ((TaxonEditorInput)input).getTaxon();
|
58
|
|
59
|
MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil.getUndoContext(),
|
60
|
oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor);
|
61
|
|
62
|
EditorUtil.executeOperation(operation);
|
63
|
|
64
|
|
65
|
return null;
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
70
|
// TODO Auto-generated method stub
|
71
|
return false;
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public boolean onComplete() {
|
76
|
// TODO Auto-generated method stub
|
77
|
return false;
|
78
|
}
|
79
|
|
80
|
|
81
|
|
82
|
}
|