1
|
package eu.etaxonomy.taxeditor.editor.name.handler;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.List;
|
5
|
import java.util.UUID;
|
6
|
|
7
|
import org.apache.log4j.Logger;
|
8
|
import org.eclipse.core.commands.AbstractHandler;
|
9
|
import org.eclipse.core.commands.ExecutionEvent;
|
10
|
import org.eclipse.core.commands.ExecutionException;
|
11
|
import org.eclipse.jface.viewers.StructuredSelection;
|
12
|
import org.eclipse.swt.widgets.Shell;
|
13
|
import org.eclipse.ui.IEditorInput;
|
14
|
import org.eclipse.ui.handlers.HandlerUtil;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
17
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
18
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
19
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
20
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
21
|
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
|
22
|
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
|
23
|
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
|
24
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
25
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
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
|
// Get synonym from selection before possible save dialog
|
40
|
// because the selection will be null if save dialog is shown
|
41
|
StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
|
42
|
|
43
|
if (!EditorUtil.forceUserSave(editor, shell)) {
|
44
|
return null;
|
45
|
}
|
46
|
|
47
|
if (!(input instanceof TaxonEditorInput)) {
|
48
|
logger.error("Editor input is not TaxonEditorInput");
|
49
|
return null;
|
50
|
}
|
51
|
|
52
|
if (selection==null || !(selection.getFirstElement() instanceof Synonym)) {
|
53
|
MessagingUtils.warningDialog("No selection", this, "No synonym selected");
|
54
|
logger.error("Selection does not contain a Synonym");
|
55
|
return null;
|
56
|
}
|
57
|
|
58
|
Synonym synonym = (Synonym) selection.getFirstElement();
|
59
|
Taxon oldParent = ((TaxonEditorInput)input).getTaxon();
|
60
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
61
|
excludeTaxa.add(oldParent.getUuid());
|
62
|
|
63
|
|
64
|
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select new accepted taxon", excludeTaxa, null, ((TaxonEditorInput)input).getTaxonNode().getClassification());
|
65
|
|
66
|
if(newParentNode!=null){
|
67
|
MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil.getUndoContext(),
|
68
|
oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor);
|
69
|
|
70
|
AbstractUtility.executeOperation(operation);
|
71
|
|
72
|
}
|
73
|
return null;
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
78
|
// TODO Auto-generated method stub
|
79
|
return false;
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public boolean onComplete() {
|
84
|
// TODO Auto-generated method stub
|
85
|
return false;
|
86
|
}
|
87
|
|
88
|
|
89
|
|
90
|
}
|