1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor.name.e4.handler;
|
11
|
|
12
|
import javax.inject.Named;
|
13
|
|
14
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
15
|
import org.eclipse.e4.core.di.annotations.Execute;
|
16
|
import org.eclipse.e4.ui.di.UISynchronize;
|
17
|
import org.eclipse.e4.ui.model.application.MApplication;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
20
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
21
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
22
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
23
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
24
|
import org.eclipse.swt.widgets.Display;
|
25
|
import org.eclipse.swt.widgets.Shell;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
31
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
32
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
33
|
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
|
34
|
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
|
35
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
36
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
37
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
38
|
|
39
|
/**
|
40
|
*
|
41
|
* @author pplitzner
|
42
|
* @since Aug 28, 2017
|
43
|
*
|
44
|
*/
|
45
|
public class SwapSynonymAndAcceptedHandlerE4 implements IPostOperationEnabled {
|
46
|
|
47
|
private TaxonNameEditorE4 editor;
|
48
|
private Taxon taxon;
|
49
|
private EPartService partService;
|
50
|
private MPart activePart;
|
51
|
private MApplication application;
|
52
|
private EModelService modelService;
|
53
|
|
54
|
@Execute
|
55
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
56
|
@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
|
57
|
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, MHandledMenuItem menuItem, EPartService partService,
|
58
|
EModelService modelService, MApplication application,
|
59
|
UISynchronize sync) {
|
60
|
|
61
|
this.activePart = activePart;
|
62
|
this.modelService = modelService;
|
63
|
this.application = application;
|
64
|
this.partService = partService;
|
65
|
|
66
|
editor = (TaxonNameEditorE4) activePart.getObject();
|
67
|
|
68
|
Synonym synonym = (Synonym) selection.getFirstElement();
|
69
|
|
70
|
// Force user to save taxon - not really necessary though, is it?
|
71
|
if (!EditorUtil.forceUserSaveE4Editor(editor, shell)) {
|
72
|
return;
|
73
|
}
|
74
|
|
75
|
SwapSynonymAndAcceptedOperation operation = new SwapSynonymAndAcceptedOperation(menuItem.getLocalizedLabel(),
|
76
|
editor.getUndoContext(), editor.getTaxon(), synonym, this, editor.getEditorInput());
|
77
|
|
78
|
AbstractUtility.executeOperation(operation, sync);
|
79
|
|
80
|
}
|
81
|
|
82
|
@CanExecute
|
83
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
84
|
MHandledMenuItem menuItem){
|
85
|
boolean canExecute = false;
|
86
|
Object selectedElement = selection.getFirstElement();
|
87
|
canExecute =
|
88
|
NameEditorMenuPropertyTester.isSynonym(selectedElement);
|
89
|
menuItem.setVisible(canExecute);
|
90
|
return canExecute;
|
91
|
}
|
92
|
|
93
|
@Override
|
94
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
95
|
// Redraw existing editor
|
96
|
// ((IPostOperationEnabled) editor).postOperation(null);
|
97
|
|
98
|
editor.save(AbstractUtility.getMonitor());
|
99
|
partService.hidePart(activePart);
|
100
|
|
101
|
if (objectAffectedByOperation instanceof Taxon) {
|
102
|
taxon = (Taxon) objectAffectedByOperation;
|
103
|
}
|
104
|
return true;
|
105
|
}
|
106
|
|
107
|
@Override
|
108
|
public boolean onComplete() {
|
109
|
Display display = Display.getCurrent();
|
110
|
display.asyncExec(new Runnable() {
|
111
|
@Override
|
112
|
public void run() {
|
113
|
try {
|
114
|
EditorUtil.openTaxonBaseE4(taxon.getUuid(), modelService, partService, application);
|
115
|
} catch (Exception e) {
|
116
|
MessagingUtils.warningDialog(Messages.SwapSynonymAndAcceptedHandler_COULD_NOT_OPEN, this,
|
117
|
e.getMessage());
|
118
|
}
|
119
|
|
120
|
}
|
121
|
});
|
122
|
return true;
|
123
|
}
|
124
|
}
|