1
|
package eu.etaxonomy.taxeditor.editor.name.e4.handler;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.List;
|
5
|
import java.util.UUID;
|
6
|
|
7
|
import javax.inject.Named;
|
8
|
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
11
|
import org.eclipse.e4.core.di.annotations.Execute;
|
12
|
import org.eclipse.e4.ui.di.UISynchronize;
|
13
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
14
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
15
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
16
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
17
|
import org.eclipse.swt.widgets.Shell;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
20
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
22
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
23
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
24
|
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
|
25
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
26
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
27
|
import eu.etaxonomy.taxeditor.editor.name.e4.operation.MoveSynonymToAnotherAcceptedTaxonOperationE4;
|
28
|
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
|
29
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
30
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
32
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
33
|
|
34
|
public class MoveSynonymToAnotherAcceptedTaxonHandlerE4 implements IPostOperationEnabled{
|
35
|
private static final Logger logger = Logger
|
36
|
.getLogger(MoveSynonymToAnotherAcceptedTaxonHandlerE4.class);
|
37
|
|
38
|
private TaxonNameEditorE4 editor;
|
39
|
|
40
|
@Execute
|
41
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
42
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
43
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
44
|
UISynchronize sync) {
|
45
|
|
46
|
editor = (TaxonNameEditorE4) activePart.getObject();
|
47
|
|
48
|
TaxonEditorInputE4 input = editor.getEditorInput();
|
49
|
|
50
|
if (!EditorUtil.forceUserSaveE4Editor(editor, shell)) {
|
51
|
return ;
|
52
|
}
|
53
|
|
54
|
if (selection==null || !(selection.getFirstElement() instanceof Synonym)) {
|
55
|
MessagingUtils.warningDialog(Messages.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION, this, Messages.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION_MESSAGE);
|
56
|
logger.error("Selection does not contain a Synonym"); //$NON-NLS-1$
|
57
|
return ;
|
58
|
}
|
59
|
|
60
|
Synonym synonym = (Synonym) selection.getFirstElement();
|
61
|
Taxon oldParent = input.getTaxon();
|
62
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
63
|
excludeTaxa.add(oldParent.getUuid());
|
64
|
|
65
|
|
66
|
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(shell, editor.getConversationHolder(), Messages.MoveSynonymToAnotherAcceptedTaxonHandler_SELECT_ACC_TAXON, excludeTaxa, input.getTaxonNode(), input.getTaxonNode().getClassification());
|
67
|
|
68
|
if(newParentNode!=null){
|
69
|
MoveSynonymToAnotherAcceptedTaxonOperationE4 operation = new MoveSynonymToAnotherAcceptedTaxonOperationE4(Messages.MoveSynonymToAnotherAcceptedTaxonHandler_CHANGE_ACC_TAXON, EditorUtil.getUndoContext(),
|
70
|
synonym.getUuid(), newParentNode.getTaxon(), editor, editor);
|
71
|
|
72
|
AbstractUtility.executeOperation(operation, sync);
|
73
|
}
|
74
|
}
|
75
|
|
76
|
@CanExecute
|
77
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
78
|
MHandledMenuItem menuItem){
|
79
|
boolean canExecute = false;
|
80
|
Object selectedElement = selection.getFirstElement();
|
81
|
canExecute =
|
82
|
NameEditorMenuPropertyTester.isSynonym(selectedElement)
|
83
|
&& NameEditorMenuPropertyTester.isNotHomotypicSynonymOfAcceptedTaxon(selectedElement);
|
84
|
|
85
|
menuItem.setVisible(canExecute);
|
86
|
return canExecute;
|
87
|
}
|
88
|
|
89
|
@Override
|
90
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
91
|
editor.redraw();
|
92
|
return false;
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public boolean onComplete() {
|
97
|
return false;
|
98
|
}
|
99
|
|
100
|
}
|