Revision cad985fd
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.bulkeditor.e4.handler; |
11 | 11 |
|
12 |
import java.util.Collections; |
|
12 |
import java.util.HashSet; |
|
13 |
import java.util.Iterator; |
|
13 | 14 |
|
14 | 15 |
import javax.inject.Named; |
15 | 16 |
|
... | ... | |
19 | 20 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
20 | 21 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
21 | 22 |
import org.eclipse.e4.ui.services.IServiceConstants; |
22 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
23 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
23 | 24 |
|
24 | 25 |
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity; |
25 | 26 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
... | ... | |
39 | 40 |
public class SetMarkerFlagHandlerE4 { |
40 | 41 |
|
41 | 42 |
@Execute |
42 |
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IAnnotatableEntity selection, |
|
43 |
@Named(IServiceConstants.ACTIVE_PART)MPart activePart, |
|
43 |
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, |
|
44 | 44 |
MHandledMenuItem menuItem, UISynchronize sync) { |
45 | 45 |
|
46 | 46 |
BulkEditorE4 editor = (BulkEditorE4) activePart.getObject(); |
47 | 47 |
MarkerType markerType = (MarkerType) menuItem.getTransientData().get(DynamicMarkerTypeEditingMenuE4.COMMAND_PARAMETER_MARKER_TYPE); |
48 | 48 |
boolean markerState = (boolean) menuItem.getTransientData().get(DynamicMarkerTypeEditingMenuE4.COMMAND_PARAMETER_MARKER_STATE); |
49 | 49 |
|
50 |
|
|
51 |
AbstractPostOperation operation = new SetMarkerFlagOperation("Set Marker", BulkEditorUtil.getUndoContext(), Collections.singleton(selection), markerType, markerState, editor);
|
|
50 |
IStructuredSelection selection = editor.getSelection(); |
|
51 |
AbstractPostOperation operation = new SetMarkerFlagOperation("Set Marker", BulkEditorUtil.getUndoContext(), new HashSet<>(selection.toList()), markerType, markerState, editor);
|
|
52 | 52 |
AbstractUtility.executeOperation(operation, sync); |
53 | 53 |
} |
54 | 54 |
|
... | ... | |
57 | 57 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, |
58 | 58 |
MHandledMenuItem menuItem){ |
59 | 59 |
boolean canExecute = false; |
60 |
StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection(); |
|
61 |
canExecute = !selection.isEmpty() && selection.getFirstElement() instanceof IAnnotatableEntity; |
|
60 |
IStructuredSelection selection = ((BulkEditorE4)activePart.getObject()).getSelection(); |
|
61 |
canExecute = !selection.isEmpty(); |
|
62 |
Iterator iterator = selection.iterator(); |
|
63 |
for(selection.iterator();iterator.hasNext();){ |
|
64 |
Object object = iterator.next(); |
|
65 |
if(!(object instanceof IAnnotatableEntity)){ |
|
66 |
canExecute = false; |
|
67 |
break; |
|
68 |
} |
|
69 |
} |
|
62 | 70 |
menuItem.setVisible(canExecute); |
63 | 71 |
return canExecute; |
64 | 72 |
} |
Also available in: Unified diff
ref #7010 Adapt bulk editor handlers for multiple selection