Project

General

Profile

Download (3.09 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.Iterator;
14
import java.util.Set;
15

    
16
import javax.inject.Named;
17

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

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

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

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

    
50
        TaxonNameEditorE4 editor = null;
51

    
52
        ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
53

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

    
58
            Set<TaxonRelationship> relations = new HashSet<TaxonRelationship>();
59

    
60

    
61
            for (Iterator iterator = selection.iterator(); iterator.hasNext();){
62
                Object object = iterator.next();
63
                if(object instanceof TaxonRelationship){
64
                    relations.add((TaxonRelationship) object);
65
                }
66
            }
67

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

    
75
	@CanExecute
76
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
77
            MHandledMenuItem menuItem) {
78
        boolean canExecute = false;
79
        canExecute = selection != null && !selection.isEmpty();
80
        menuItem.setVisible(canExecute);
81
        return canExecute;
82
    }
83
}
(2-2/4)