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.l10n.Messages;
|
24
|
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
|
25
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
26
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
27
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
28
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
29
|
|
30
|
public class MoveSynonymToAnotherAcceptedTaxonHandler extends AbstractHandler implements IPostOperationEnabled {
|
31
|
private static final Logger logger = Logger
|
32
|
.getLogger(MoveSynonymToAnotherAcceptedTaxonHandler.class);
|
33
|
private MultiPageTaxonEditor editor;
|
34
|
|
35
|
@Override
|
36
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
37
|
editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event);
|
38
|
Shell shell = HandlerUtil.getActiveShell(event);
|
39
|
IEditorInput input = editor.getEditorInput();
|
40
|
// Get synonym from selection before possible save dialog
|
41
|
// because the selection will be null if save dialog is shown
|
42
|
StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
|
43
|
|
44
|
if (!EditorUtil.forceUserSave(editor, shell)) {
|
45
|
return null;
|
46
|
}
|
47
|
|
48
|
if (!(input instanceof TaxonEditorInput)) {
|
49
|
logger.error("Editor input is not TaxonEditorInput"); //$NON-NLS-1$
|
50
|
return null;
|
51
|
}
|
52
|
|
53
|
if (selection==null || !(selection.getFirstElement() instanceof Synonym)) {
|
54
|
MessagingUtils.warningDialog(Messages.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION, this, Messages.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION_MESSAGE);
|
55
|
logger.error("Selection does not contain a Synonym"); //$NON-NLS-1$
|
56
|
return null;
|
57
|
}
|
58
|
|
59
|
Synonym synonym = (Synonym) selection.getFirstElement();
|
60
|
Taxon oldParent = ((TaxonEditorInput)input).getTaxon();
|
61
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
62
|
excludeTaxa.add(oldParent.getUuid());
|
63
|
|
64
|
|
65
|
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), Messages.MoveSynonymToAnotherAcceptedTaxonHandler_SELECT_ACC_TAXON, excludeTaxa, null, ((TaxonEditorInput)input).getTaxonNode().getClassification());
|
66
|
|
67
|
if(newParentNode!=null){
|
68
|
MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation(Messages.MoveSynonymToAnotherAcceptedTaxonHandler_CHANGE_ACC_TAXON, EditorUtil.getUndoContext(),
|
69
|
oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor);
|
70
|
|
71
|
AbstractUtility.executeOperation(operation);
|
72
|
|
73
|
}
|
74
|
return null;
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
79
|
// TODO Auto-generated method stub
|
80
|
return false;
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
public boolean onComplete() {
|
85
|
// TODO Auto-generated method stub
|
86
|
return false;
|
87
|
}
|
88
|
|
89
|
|
90
|
|
91
|
}
|