1 |
a7d1d751
|
Patrick Plitzner
|
/**
|
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 |
90cf660a
|
Patrick Plitzner
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
15 |
a7d1d751
|
Patrick Plitzner
|
import org.eclipse.e4.core.di.annotations.Execute;
|
16 |
b5b429af
|
Patrick Plitzner
|
import org.eclipse.e4.ui.di.UISynchronize;
|
17 |
a7d1d751
|
Patrick Plitzner
|
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 |
90cf660a
|
Patrick Plitzner
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21 |
a7d1d751
|
Patrick Plitzner
|
|
22 |
|
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
23 |
|
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
24 |
90cf660a
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
|
25 |
a7d1d751
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInNewGroupOperation;
|
26 |
|
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
27 |
|
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
28 |
|
|
import eu.etaxonomy.taxeditor.parser.ParseHandler;
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
*
|
32 |
|
|
* @author pplitzner
|
33 |
|
|
* @since Aug 28, 2017
|
34 |
|
|
*
|
35 |
|
|
*/
|
36 |
|
|
public class CreateHeterotypicSynonymHandlerE4 {
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
@Execute
|
40 |
|
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
41 |
b5b429af
|
Patrick Plitzner
|
MHandledMenuItem menuItem,
|
42 |
|
|
UISynchronize sync) {
|
43 |
a7d1d751
|
Patrick Plitzner
|
|
44 |
|
|
TaxonNameEditorE4 editor = (TaxonNameEditorE4) activePart.getObject();
|
45 |
|
|
|
46 |
|
|
TaxonName newSynonymName = ParseHandler.createEmptyName();
|
47 |
|
|
|
48 |
|
|
AbstractPostOperation<?> operation;
|
49 |
|
|
operation = new CreateSynonymInNewGroupOperation(menuItem.getLocalizedLabel(),
|
50 |
|
|
editor.getUndoContext(), editor.getTaxon(), newSynonymName, editor);
|
51 |
b5b429af
|
Patrick Plitzner
|
AbstractUtility.executeOperation(operation, sync);
|
52 |
a7d1d751
|
Patrick Plitzner
|
}
|
53 |
90cf660a
|
Patrick Plitzner
|
|
54 |
|
|
@CanExecute
|
55 |
|
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
56 |
|
|
MHandledMenuItem menuItem){
|
57 |
|
|
Object selectedElement = selection.getFirstElement();
|
58 |
|
|
boolean canExecute = NameEditorMenuPropertyTester.isAccepted(selectedElement);
|
59 |
|
|
return canExecute;
|
60 |
|
|
}
|
61 |
a7d1d751
|
Patrick Plitzner
|
}
|