Project

General

Profile

Download (2.48 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.featuretree.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.Execute;
15
import org.eclipse.e4.core.di.annotations.Optional;
16
import org.eclipse.e4.ui.di.UISynchronize;
17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21

    
22
import eu.etaxonomy.cdm.model.term.TermTree;
23
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
24
import eu.etaxonomy.taxeditor.featuretree.e4.operation.RemoveFeatureTreeOperation;
25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
26
import eu.etaxonomy.taxeditor.store.StoreUtil;
27

    
28
/**
29
 * @author pplitzner
30
 * @since Jul 12, 2017
31
 *
32
 */
33
public class RemoveFeatureTreeHandler {
34

    
35
    @Execute
36
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
37
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection, UISynchronize sync){
38
        IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
39

    
40
        if (StoreUtil.promptCheckIsDirty(editor)) {
41
            return;
42
        }
43
        if(!StoreUtil.confirmDelete()){
44
            return;
45
        }
46

    
47
        for (Object selectedObject : selection.toArray()) {
48
        	TermTree featureTree = (TermTree) selectedObject;
49
            RemoveFeatureTreeOperation operation = new RemoveFeatureTreeOperation(featureTree, editor, editor);
50
            AbstractUtility.executeOperation(operation, sync);
51
        }
52
    }
53

    
54
    @CanExecute
55
    public boolean canExecute(
56
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
57
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
58
            MHandledMenuItem menuItem) {
59
        boolean canExecute = selection!=null && !selection.isEmpty();
60
        if(canExecute){
61
            for(Object object:selection.toArray()){
62
                canExecute &= object instanceof TermTree;
63
            }
64
        }
65
        canExecute &= thisPart.getObject() instanceof IFeatureTreeEditor;
66
        menuItem.setVisible(canExecute);
67
        return canExecute;
68
    }
69

    
70
}
(9-9/9)