Project

General

Profile

Download (3.3 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.editor.view.concept.e4.handler;
11

    
12
import java.util.HashSet;
13
import java.util.Set;
14

    
15
import javax.inject.Named;
16

    
17
import org.eclipse.e4.core.di.annotations.CanExecute;
18
import org.eclipse.e4.core.di.annotations.Execute;
19
import org.eclipse.e4.core.di.annotations.Optional;
20
import org.eclipse.e4.ui.di.UISynchronize;
21
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
22
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
23
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
24
import org.eclipse.e4.ui.services.IServiceConstants;
25
import org.eclipse.jface.viewers.ISelection;
26

    
27
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
28
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
29
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
30
import eu.etaxonomy.taxeditor.editor.view.concept.operation.DeleteConceptRelationOperation;
31
import eu.etaxonomy.taxeditor.model.AbstractUtility;
32
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
33
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
34

    
35
/**
36
 *
37
 * @author pplitzner
38
 * @date 21.08.2017
39
 *
40
 */
41
public class DeleteConceptRelationHandlerE4 {
42

    
43
    @Execute
44
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
45
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object selection, MMenuItem menuItem,
46
            UISynchronize sync) {
47

    
48
        TaxonNameEditorE4 editor = null;
49

    
50
        ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
51

    
52
        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
53
        if(e4WrappedPart instanceof TaxonNameEditorE4){
54
            editor = (TaxonNameEditorE4) e4WrappedPart;
55

    
56
            Set<TaxonRelationship> relations = new HashSet<TaxonRelationship>();
57

    
58

    
59
            // FIXME E4 multiple selection
60
            //			while (iterator.hasNext()){
61
            if(selection instanceof TaxonRelationship){
62
                relations.add((TaxonRelationship) selection);
63
            }
64
            //			}
65

    
66
            //editor should not be null because this is already checked in canExecute
67
            AbstractPostOperation operation = new DeleteConceptRelationOperation(menuItem.getLocalizedLabel(),
68
                    editor.getUndoContext(), editor.getTaxon(), relations, conceptView);
69
            AbstractUtility.executeOperation(operation, sync);
70
        }
71
    }
72

    
73
	@CanExecute
74
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart,
75
            MHandledMenuItem menuItem){
76
        boolean canExecute = false;
77
        ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
78

    
79
        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
80
        if(e4WrappedPart instanceof TaxonNameEditorE4){
81
            ISelection selection = conceptView.getViewer().getSelection();
82
            canExecute = selection!=null && !selection.isEmpty();
83
            menuItem.setVisible(canExecute);
84
        }
85
        return canExecute;
86
    }
87
}
(2-2/4)