ref #6595 Set visibility of context menu items in name editor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / e4 / handler / DeleteAllEmptyNamesHandlerE4.java
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.name.e4.handler;
11
12 import javax.inject.Named;
13
14 import org.eclipse.e4.core.di.annotations.CanExecute;
15 import org.eclipse.e4.core.di.annotations.Execute;
16 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
17 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
18 import org.eclipse.e4.ui.services.IServiceConstants;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.swt.widgets.Shell;
21
22 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
23 import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupedContainerE4;
24
25 /**
26 *
27 * @author pplitzner
28 * @since Aug 28, 2017
29 *
30 */
31 public class DeleteAllEmptyNamesHandlerE4 extends DeleteTaxonBaseHandlerE4 {
32
33 @Override
34 @Execute
35 public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
36 @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selectedElement,
37 @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
38 MHandledMenuItem menuItem) {
39
40 editor = (TaxonNameEditorE4) activePart.getObject();
41
42 for(AbstractGroupedContainerE4 containerWithEmptyName : editor.getEmptyContainers()){
43 editor.removeGroup(containerWithEmptyName.getGroup());
44 doExecute(menuItem.getLocalizedLabel(), shell, editor, containerWithEmptyName.getData());
45 }
46
47 }
48
49 @Override
50 @CanExecute
51 public boolean canExecute(
52 @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
53 @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
54 MHandledMenuItem menuItem){
55
56 editor = (TaxonNameEditorE4) activePart.getObject();
57
58 boolean canExecute = false;
59 Object selectedElement = selection.getFirstElement();
60 canExecute = editor.checkForEmptyNames();
61 menuItem.setVisible(canExecute);
62 return canExecute;
63 }
64
65 }