Example usage for org.eclipse.jface.action MenuManager isEnabled

List of usage examples for org.eclipse.jface.action MenuManager isEnabled

Introduction

In this page you can find the example usage for org.eclipse.jface.action MenuManager isEnabled.

Prototype

@Override
public boolean isEnabled() 

Source Link

Document

Returns whether this menu should be enabled or not.

Usage

From source file:org.eclipse.epf.diagram.core.actions.DiagramActionsService.java

License:Open Source License

public void createAlignMenu(IMenuManager menu, boolean canModify) {
    // create a new menu manager for the cascading menu

    IContributionItem formatMenu = menu.find(ActionIds.MENU_FORMAT);

    MenuManager alignMenuManager = null;
    if (alignMenuManager == null) {
        alignMenuManager = new MenuManager(DiagramCoreResources.AbstractDiagramEditor_alignMenu_text) { //$NON-NLS-1$

            public boolean isEnabled() {
                int total = 0;
                // enable the menu only if 2 or more nodes or node
                // containers
                // are selected
                List editParts = graphicalViewer.getSelectedEditParts();
                // need at least two things selected to align
                if (editParts.size() > 1) {
                    for (int a = 0; a < editParts.size(); a++) {
                        EditPart editPart = (EditPart) editParts.get(a);
                        // we can align nodes and containers
                        if (editPart instanceof ShapeNodeEditPart) {
                            // add up the elements we need, there may be
                            // more
                            // elements selected (links, etc.)
                            total++;/* ww  w  .  j ava 2  s  .  co m*/
                            if (total > 1) {
                                // we only need to know there is more than
                                // 1, so
                                // we can stop here
                                break;
                            }
                        }
                    }
                }
                return total > 1;
            }
        };
    }
    if (formatMenu != null && formatMenu instanceof IMenuManager && alignMenuManager.isEnabled() && canModify) {
        IContributionItem item = ((IMenuManager) formatMenu).find(ActionIds.MENU_ALIGN);
        if (item != null && item instanceof IMenuManager) {
            IMenuManager alignMenu = (IMenuManager) item;
            alignMenu.add(getActionRegistry().getAction(DiagramActionsService.ALIGN_HORZ_AVERAGE));
            alignMenu.add(getActionRegistry().getAction(DiagramActionsService.ALIGN_HORZ_FIRST_SELECTED));
            alignMenu.add(getActionRegistry().getAction(DiagramActionsService.ALIGN_VERT_AVERAGE));
            alignMenu.add(getActionRegistry().getAction(DiagramActionsService.ALIGN_VERT_FIRST_SELECTED));
        }
    } else {
        alignMenuManager.add(getActionRegistry().getAction(DiagramActionsService.ALIGN_HORZ_AVERAGE));
        alignMenuManager.add(getActionRegistry().getAction(DiagramActionsService.ALIGN_HORZ_FIRST_SELECTED));
        alignMenuManager.add(getActionRegistry().getAction(DiagramActionsService.ALIGN_VERT_AVERAGE));
        alignMenuManager.add(getActionRegistry().getAction(DiagramActionsService.ALIGN_VERT_FIRST_SELECTED));
        if (alignMenuManager.isEnabled() && canModify) {
            menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, new Separator());
            menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, alignMenuManager);
            menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, new Separator());
        }
    }
}