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