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.model.application.ui.basic.MPart;
|
21
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
22
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
|
23
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
24
|
import org.eclipse.jface.viewers.ISelection;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
27
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
28
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
29
|
import eu.etaxonomy.taxeditor.editor.view.concept.operation.DeleteConceptRelationOperation;
|
30
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
31
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
32
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
33
|
|
34
|
/**
|
35
|
*
|
36
|
* @author pplitzner
|
37
|
* @date 21.08.2017
|
38
|
*
|
39
|
*/
|
40
|
public class DeleteConceptRelationHandlerE4 {
|
41
|
|
42
|
@Execute
|
43
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
44
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object selection, MMenuItem menuItem) {
|
45
|
|
46
|
TaxonNameEditorE4 editor = null;
|
47
|
|
48
|
ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
|
49
|
|
50
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
|
51
|
if(e4WrappedPart instanceof TaxonNameEditorE4){
|
52
|
editor = (TaxonNameEditorE4) e4WrappedPart;
|
53
|
|
54
|
Set<TaxonRelationship> relations = new HashSet<TaxonRelationship>();
|
55
|
|
56
|
|
57
|
// FIXME E4 multiple selection
|
58
|
// while (iterator.hasNext()){
|
59
|
if(selection instanceof TaxonRelationship){
|
60
|
relations.add((TaxonRelationship) selection);
|
61
|
}
|
62
|
// }
|
63
|
|
64
|
//editor should not be null because this is already checked in canExecute
|
65
|
AbstractPostOperation operation = new DeleteConceptRelationOperation(menuItem.getLocalizedLabel(),
|
66
|
editor.getUndoContext(), editor.getTaxon(), relations, conceptView);
|
67
|
AbstractUtility.executeOperation(operation);
|
68
|
}
|
69
|
}
|
70
|
|
71
|
@CanExecute
|
72
|
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
73
|
MHandledMenuItem menuItem){
|
74
|
boolean canExecute = false;
|
75
|
ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
|
76
|
|
77
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
|
78
|
if(e4WrappedPart instanceof TaxonNameEditorE4){
|
79
|
ISelection selection = conceptView.getViewer().getSelection();
|
80
|
canExecute = selection!=null && !selection.isEmpty();
|
81
|
menuItem.setVisible(canExecute);
|
82
|
}
|
83
|
return canExecute;
|
84
|
}
|
85
|
}
|