Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / e4 / handler / CopyTermHandler.java
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.viewers.IStructuredSelection;
13
14 import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
15 import eu.etaxonomy.taxeditor.featuretree.e4.TermTreeEditor;
16
17 public class CopyTermHandler {
18
19 @Execute
20 public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
21 @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
22 ((TermTreeEditor) part.getObject()).copy(selection);
23 }
24
25 @CanExecute
26 public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
27 @Named(IServiceConstants.ACTIVE_PART) MPart part,
28 MHandledMenuItem menuItem){
29 boolean canExecute = false;
30 canExecute =part.getObject() instanceof TermTreeEditor
31 && selection!=null
32 && selection.size()==1
33 && selection.getFirstElement() instanceof TermNodeDto;
34 menuItem.setVisible(canExecute);
35 return canExecute;
36 }
37
38 }