Project

General

Profile

Download (1.8 KB) Statistics
| Branch: | Tag: | Revision:
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.model.application.ui.basic.MPart;
10
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
11
import org.eclipse.e4.ui.services.IServiceConstants;
12
import org.eclipse.jface.util.LocalSelectionTransfer;
13
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.jface.viewers.IStructuredSelection;
15

    
16
import eu.etaxonomy.cdm.model.description.FeatureNode;
17
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
18

    
19
public class PasteFeatureHandler {
20

    
21
    @Execute
22
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
23
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
24
        FeatureTreeEditor editor = (FeatureTreeEditor)part.getObject();
25
        editor.paste(selection);
26
    }
27

    
28
    @CanExecute
29
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
30
            @Named(IServiceConstants.ACTIVE_PART) MPart part,
31
            MHandledMenuItem menuItem){
32
        boolean canExecute = false;
33
        ISelection transferSelection = LocalSelectionTransfer.getTransfer().getSelection();
34
        canExecute = part.getObject() instanceof FeatureTreeEditor
35
                && selection!=null
36
                && selection.size()==1
37
                && transferSelection instanceof IStructuredSelection
38
                && ((IStructuredSelection)transferSelection).size()==1
39
                && ((IStructuredSelection)transferSelection).getFirstElement() instanceof FeatureNode;
40
        menuItem.setVisible(canExecute);
41
        return canExecute;
42
    }
43

    
44
}
(7-7/9)