Project

General

Profile

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

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.core.commands.operations.AbstractOperation;
14
import org.eclipse.e4.core.di.annotations.CanExecute;
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
import org.eclipse.jface.viewers.TreeSelection;
20
import org.eclipse.swt.widgets.Shell;
21

    
22
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
23
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetUnplacedOperation;
24

    
25
/**
26
 * @author k.luther
27
 * @since 11.10.2018
28
 *
29
 */
30
public class RemoveUnplacedHandler extends UnplacedHandler {
31
    @Override
32
    public AbstractOperation prepareOperation(IStructuredSelection selection,
33
            Shell shell,
34
            MPart activePart,
35
            MHandledMenuItem menuItem) {
36
        SetUnplacedOperation operation =
37
                new SetUnplacedOperation(getTrigger(),
38
                        true,
39
                        taxonNodes,
40
                        false);
41

    
42
        return operation;
43
    }
44

    
45
    @CanExecute
46
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
47
        boolean canExecute = !selection.isEmpty();
48
        Object[] array = selection.toArray();
49
        for (Object object : array) {
50
            canExecute &= (object instanceof TaxonNodeDto) && (((TaxonNodeDto)object).getUuid() != null) && ((TaxonNodeDto)object).isUnplaced();
51
        }
52
        menuItem.setVisible(canExecute);
53
        return canExecute;
54
    }
55
}
(14-14/18)