1
|
|
2
|
package eu.etaxonomy.taxeditor.featuretree.e4.handler;
|
3
|
|
4
|
import javax.inject.Named;
|
5
|
|
6
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
7
|
import org.eclipse.e4.core.di.annotations.Execute;
|
8
|
import org.eclipse.e4.core.di.annotations.Optional;
|
9
|
import org.eclipse.e4.ui.di.UISynchronize;
|
10
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
11
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
12
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
13
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
14
|
import org.eclipse.jface.viewers.ISelection;
|
15
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
18
|
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
|
19
|
import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddFeatureOperation;
|
20
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
21
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
22
|
|
23
|
public class PasteFeatureHandler {
|
24
|
|
25
|
@Execute
|
26
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
|
27
|
@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, UISynchronize sync){
|
28
|
IFeatureTreeEditor editor = (IFeatureTreeEditor)part.getObject();
|
29
|
|
30
|
if (StoreUtil.promptCheckIsDirty(editor)) {
|
31
|
return;
|
32
|
}
|
33
|
|
34
|
ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
|
35
|
FeatureNode parentNode = (FeatureNode) selection.getFirstElement();
|
36
|
FeatureNode copiedNode = (FeatureNode) ((IStructuredSelection)clipBoardSelection).getFirstElement();
|
37
|
|
38
|
AddFeatureOperation operation = new AddFeatureOperation(copiedNode.getFeature(), parentNode, editor, editor);
|
39
|
AbstractUtility.executeOperation(operation, sync);
|
40
|
}
|
41
|
|
42
|
@CanExecute
|
43
|
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
|
44
|
MHandledMenuItem menuItem){
|
45
|
boolean canExecute = false;
|
46
|
ISelection transferSelection = LocalSelectionTransfer.getTransfer().getSelection();
|
47
|
canExecute = selection!=null
|
48
|
&& selection.size()==1
|
49
|
&& selection.getFirstElement() instanceof FeatureNode
|
50
|
&& transferSelection instanceof IStructuredSelection
|
51
|
&& ((IStructuredSelection)transferSelection).size()==1
|
52
|
&& ((IStructuredSelection)transferSelection).getFirstElement() instanceof FeatureNode;
|
53
|
menuItem.setVisible(canExecute);
|
54
|
return canExecute;
|
55
|
}
|
56
|
|
57
|
}
|