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.ui.basic.MPart;
|
18
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
23
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
24
|
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
|
25
|
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation;
|
26
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
27
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
28
|
|
29
|
/**
|
30
|
*
|
31
|
* @author pplitzner
|
32
|
* @since Aug 28, 2017
|
33
|
*
|
34
|
*/
|
35
|
public class ChangeToSynonymHandlerE4 {
|
36
|
|
37
|
@Execute
|
38
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
39
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
40
|
MHandledMenuItem menuItem,
|
41
|
UISynchronize sync) {
|
42
|
|
43
|
TaxonNameEditorE4 editor = (TaxonNameEditorE4) activePart.getObject();
|
44
|
|
45
|
|
46
|
Taxon concept = (Taxon) selection.getFirstElement();
|
47
|
|
48
|
AbstractPostOperation operation;
|
49
|
operation = new ChangeConceptToSynonymOperation(menuItem.getLocalizedLabel(),
|
50
|
editor.getUndoContext(), editor.getTaxon(), concept, null, editor);
|
51
|
|
52
|
AbstractUtility.executeOperation(operation, sync);
|
53
|
|
54
|
}
|
55
|
|
56
|
@CanExecute
|
57
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
58
|
MHandledMenuItem menuItem){
|
59
|
boolean canExecute = false;
|
60
|
if(selection.size()==1){
|
61
|
Object selectedElement = selection.getFirstElement();
|
62
|
canExecute = !NameEditorMenuPropertyTester.isSynonym(selectedElement);
|
63
|
}
|
64
|
menuItem.setVisible(canExecute);
|
65
|
return canExecute;
|
66
|
}
|
67
|
|
68
|
}
|