1
|
/**
|
2
|
* Copyright (C) 2009 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
|
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
|
10
|
|
11
|
import javax.inject.Named;
|
12
|
|
13
|
import org.eclipse.core.runtime.IStatus;
|
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.TreeSelection;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
23
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
24
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
25
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
|
26
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.CopyOperation;
|
27
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
28
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
29
|
|
30
|
/**
|
31
|
*
|
32
|
* @author pplitzner
|
33
|
* @date 05.09.2017
|
34
|
*
|
35
|
*/
|
36
|
public class CopyHandlerE4 {
|
37
|
|
38
|
@Execute
|
39
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
|
40
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
41
|
MHandledMenuItem menuItem,
|
42
|
UISynchronize sync) {
|
43
|
|
44
|
TaxonNavigatorE4 taxonNavigator = (TaxonNavigatorE4) activePart.getObject();
|
45
|
|
46
|
if(selection.size() == 1) {
|
47
|
Object selectedObject = selection.getFirstElement();
|
48
|
if (selectedObject instanceof TaxonNodeDto) {
|
49
|
AbstractPostOperation operation = new CopyOperation(menuItem.getLocalizedLabel(), StoreUtil.getUndoContext(),
|
50
|
(TaxonNodeDto)selectedObject, taxonNavigator);
|
51
|
IStatus status = AbstractUtility.executeOperation(operation, sync);
|
52
|
}
|
53
|
}
|
54
|
}
|
55
|
|
56
|
@CanExecute
|
57
|
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
|
58
|
boolean canExecute = false;
|
59
|
canExecute = selection.getFirstElement() instanceof ITaxonTreeNode;
|
60
|
menuItem.setVisible(canExecute);
|
61
|
return canExecute;
|
62
|
}
|
63
|
|
64
|
}
|