Project

General

Profile

Download (1.68 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.termtree.e4.handler;
10

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.e4.core.di.annotations.CanExecute;
14
import org.eclipse.e4.core.di.annotations.Optional;
15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
17
import org.eclipse.e4.ui.services.IServiceConstants;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19

    
20
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
21
import eu.etaxonomy.taxeditor.termtree.e4.ITermTreeEditor;
22

    
23
/**
24
 * @author pplitzner
25
 * @since Jul 12, 2017
26
 */
27
public class AddChildTermHandler extends AbstractAddTermHandler{
28

    
29
    @CanExecute
30
    public boolean canExecute(
31
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
32
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
33
            MHandledMenuItem menuItem) {
34
        boolean canExecute = false;
35
        canExecute = thisPart.getObject() instanceof ITermTreeEditor
36
                && selection!=null
37
                && selection.size()==1
38
                && selection.getFirstElement() instanceof TermNodeDto
39
                && !((TermNodeDto)selection.getFirstElement()).getTree().isFlat();
40
        menuItem.setVisible(canExecute);
41
        return canExecute;
42
    }
43

    
44
    @Override
45
    protected TermNodeDto getParent(IStructuredSelection selection) {
46
        return (TermNodeDto)selection.getFirstElement();
47
    }
48
}
(2-2/11)