Project

General

Profile

Download (2.6 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.description.FeatureTree;
23
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
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
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
39

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

    
47
        for (Object selectedObject : selection.toArray()) {
48
            FeatureTree featureTree = (FeatureTree) selectedObject;
49
            RemoveFeatureTreeOperation operation = new RemoveFeatureTreeOperation(featureTree, editor, editor);
50
            AbstractUtility.executeOperation(operation, sync);
51
//            editor.getViewer().remove(featureTree);
52
//            editor.getRootEntities().remove(featureTree);
53
        }
54
    }
55

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

    
72
}
(8-8/8)