Revision afac11d7
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/e4/handler/DeleteConceptRelationHandlerE4.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.taxeditor.editor.view.concept.e4.handler; |
11 | 11 |
|
12 | 12 |
import java.util.HashSet; |
13 |
import java.util.Iterator; |
|
13 | 14 |
import java.util.Set; |
14 | 15 |
|
15 | 16 |
import javax.inject.Named; |
... | ... | |
22 | 23 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
23 | 24 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
24 | 25 |
import org.eclipse.e4.ui.services.IServiceConstants; |
25 |
import org.eclipse.jface.viewers.ISelection; |
|
26 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
26 | 27 |
|
27 | 28 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
28 | 29 |
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4; |
... | ... | |
42 | 43 |
|
43 | 44 |
@Execute |
44 | 45 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
45 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object selection, MMenuItem menuItem, |
|
46 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, |
|
47 |
MMenuItem menuItem, |
|
46 | 48 |
UISynchronize sync) { |
47 | 49 |
|
48 | 50 |
TaxonNameEditorE4 editor = null; |
... | ... | |
56 | 58 |
Set<TaxonRelationship> relations = new HashSet<TaxonRelationship>(); |
57 | 59 |
|
58 | 60 |
|
59 |
// FIXME E4 multiple selection |
|
60 |
// while (iterator.hasNext()){ |
|
61 |
if(selection instanceof TaxonRelationship){ |
|
62 |
relations.add((TaxonRelationship) selection); |
|
61 |
for (Iterator iterator = selection.iterator(); iterator.hasNext();){ |
|
62 |
Object object = iterator.next(); |
|
63 |
if(object instanceof TaxonRelationship){ |
|
64 |
relations.add((TaxonRelationship) object); |
|
65 |
} |
|
63 | 66 |
} |
64 |
// } |
|
65 | 67 |
|
66 | 68 |
//editor should not be null because this is already checked in canExecute |
67 | 69 |
AbstractPostOperation operation = new DeleteConceptRelationOperation(menuItem.getLocalizedLabel(), |
... | ... | |
71 | 73 |
} |
72 | 74 |
|
73 | 75 |
@CanExecute |
74 |
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
|
75 |
MHandledMenuItem menuItem){ |
|
76 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
|
|
77 |
MHandledMenuItem menuItem) {
|
|
76 | 78 |
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 |
} |
|
79 |
canExecute = selection != null && !selection.isEmpty(); |
|
80 |
menuItem.setVisible(canExecute); |
|
85 | 81 |
return canExecute; |
86 | 82 |
} |
87 | 83 |
} |
Also available in: Unified diff
ref #7010 Adapt concept view handlers for multiple selection