Project

General

Profile

Download (1.61 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
2

    
3
import javax.inject.Named;
4

    
5
import org.eclipse.e4.core.di.annotations.CanExecute;
6
import org.eclipse.e4.core.di.annotations.Execute;
7
import org.eclipse.e4.core.di.annotations.Optional;
8
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
9
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
10
import org.eclipse.e4.ui.services.IServiceConstants;
11
import org.eclipse.jface.util.LocalSelectionTransfer;
12
import org.eclipse.jface.viewers.IStructuredSelection;
13
import org.eclipse.jface.viewers.TreeNode;
14

    
15
import eu.etaxonomy.cdm.model.molecular.SingleRead;
16
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
17

    
18
public class SingleReadCopyToClipboardHandler {
19

    
20
    @Execute
21
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
22
        DerivateView derivateView = (DerivateView)part.getObject();
23
        LocalSelectionTransfer.getTransfer().setSelection(selection);
24
        derivateView.updateLabelCache();
25
        derivateView.refreshTree();
26
    }
27

    
28
    @CanExecute
29
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
30
            MHandledMenuItem menuItem){
31
        boolean canExecute = false;
32
        canExecute = selection!=null
33
                && selection.size()==1
34
                && selection.getFirstElement() instanceof TreeNode
35
                && ((TreeNode) selection.getFirstElement()).getValue() instanceof SingleRead;
36
        menuItem.setVisible(canExecute);
37
        return canExecute;
38
    }
39
}
(16-16/18)