Search in sources :

Example 11 with ActionGroup

use of org.eclipse.che.ide.api.action.ActionGroup in project che by eclipse.

the class Utils method renderActionGroup.

/**
     * Returns the list of visible action group.
     *
     * @param group
     *         action group
     * @param presentationFactory
     *         presentation factory
     * @param actionManager
     *         action manager
     * @param perspectiveManager
     *         perspective manager
     * @return list of visible action group
     */
public static List<VisibleActionGroup> renderActionGroup(@NotNull ActionGroup group, PresentationFactory presentationFactory, ActionManager actionManager, PerspectiveManager perspectiveManager) {
    Presentation presentation = presentationFactory.getPresentation(group);
    ActionEvent event = new ActionEvent(presentation, actionManager, perspectiveManager);
    if (!presentation.isVisible()) {
        // don't process invisible groups
        return null;
    }
    Action[] children = group.getChildren(event);
    List<VisibleActionGroup> currentVisibleActionGroupList = new ArrayList<>();
    List<Action> currentActionList = new ArrayList<>();
    String currentGroupId = actionManager.getId(group);
    for (Action child : children) {
        if (child == null) {
            Log.error(Utils.class, "action is null: group=" + group + " group id=" + currentGroupId);
            continue;
        }
        presentation = presentationFactory.getPresentation(child);
        child.update(new ActionEvent(presentation, actionManager, perspectiveManager));
        if (!presentation.isVisible()) {
            // don't create invisible items in the menu
            continue;
        }
        if (child instanceof ActionGroup) {
            ActionGroup actionGroup = (ActionGroup) child;
            if (actionGroup.isPopup()) {
                // popup menu has its own presentation
                if (actionGroup.disableIfNoVisibleChildren()) {
                    final boolean visibleChildren = hasVisibleChildren(actionGroup, presentationFactory, actionManager, perspectiveManager);
                    if (actionGroup.hideIfNoVisibleChildren() && !visibleChildren) {
                        continue;
                    }
                    presentation.setEnabled(actionGroup.canBePerformed() || visibleChildren);
                }
                currentActionList.add(child);
            } else {
                List<VisibleActionGroup> newVisibleActionGroupList = renderActionGroup((ActionGroup) child, presentationFactory, actionManager, perspectiveManager);
                currentVisibleActionGroupList.addAll(newVisibleActionGroupList);
            }
        } else if (child instanceof Separator) {
            if ((((Separator) child).getText() != null) || (!currentActionList.isEmpty() && !(currentActionList.get(currentActionList.size() - 1) instanceof Separator))) {
                currentActionList.add(child);
            }
        } else {
            currentActionList.add(child);
        }
    }
    currentVisibleActionGroupList.add(0, new VisibleActionGroup(currentGroupId, currentActionList));
    return currentVisibleActionGroupList;
}
Also used : Action(org.eclipse.che.ide.api.action.Action) ActionGroup(org.eclipse.che.ide.api.action.ActionGroup) ActionEvent(org.eclipse.che.ide.api.action.ActionEvent) ArrayList(java.util.ArrayList) Presentation(org.eclipse.che.ide.api.action.Presentation) Separator(org.eclipse.che.ide.api.action.Separator)

Example 12 with ActionGroup

use of org.eclipse.che.ide.api.action.ActionGroup in project che by eclipse.

the class PopupMenu method openSubPopup.

private void openSubPopup(final Element tableRowElement) {
    if (tableRowElement == null) {
        return;
    }
    if (openedSubPopup != null) {
        if (tableRowElement == subPopupAnchor) {
            return;
        }
        openedSubPopup.closePopup();
    }
    if (subPopupAnchor != null) {
        Element e = subPopupAnchor;
        subPopupAnchor = null;
        setStyleNormal(e);
    }
    subPopupAnchor = tableRowElement;
    setStyleHovered(subPopupAnchor);
    int itemIndex = Integer.parseInt(tableRowElement.getAttribute("item-index"));
    Action menuItem = list.get(itemIndex);
    String idPrefix = itemIdPrefix;
    if (idPrefix != null) {
        idPrefix += "/" + presentationFactory.getPresentation(menuItem).getText();
    }
    openedSubPopup = new PopupMenu((ActionGroup) menuItem, actionManager, managerProvider, presentationFactory, lockLayer, actionSelectedHandler, keyBindingAgent, idPrefix);
    final int HORIZONTAL_OFFSET = 3;
    final int VERTICAL_OFFSET = 1;
    openedSubPopup.getElement().getStyle().setVisibility(Visibility.HIDDEN);
    lockLayer.add(openedSubPopup, 0, 0);
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            int left = getAbsoluteLeft() + getOffsetWidth() - HORIZONTAL_OFFSET;
            int top = tableRowElement.getAbsoluteTop() - lockLayer.getTopOffset() - VERTICAL_OFFSET;
            if (left + openedSubPopup.getOffsetWidth() > Window.getClientWidth()) {
                if (left > openedSubPopup.getOffsetWidth()) {
                    left = getAbsoluteLeft() - openedSubPopup.getOffsetWidth() + HORIZONTAL_OFFSET;
                } else {
                    int diff = left + openedSubPopup.getOffsetWidth() - Window.getClientWidth();
                    left -= diff;
                }
            }
            if (top + openedSubPopup.getOffsetHeight() > Window.getClientHeight()) {
                if (top > openedSubPopup.getOffsetHeight()) {
                    top = tableRowElement.getAbsoluteTop() - openedSubPopup.getOffsetHeight() + VERTICAL_OFFSET;
                } else {
                    int diff = top + openedSubPopup.getOffsetHeight() - Window.getClientHeight();
                    top -= diff;
                }
            }
            openedSubPopup.getElement().getStyle().setLeft(left, Unit.PX);
            openedSubPopup.getElement().getStyle().setTop(top, Unit.PX);
            openedSubPopup.getElement().getStyle().setVisibility(Visibility.VISIBLE);
        }
    });
}
Also used : ToggleAction(org.eclipse.che.ide.api.action.ToggleAction) Action(org.eclipse.che.ide.api.action.Action) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ActionGroup(org.eclipse.che.ide.api.action.ActionGroup) Element(com.google.gwt.dom.client.Element)

Example 13 with ActionGroup

use of org.eclipse.che.ide.api.action.ActionGroup in project che by eclipse.

the class ContextMenu method show.

/**
     * Shows a content menu and moves it to specified position.
     *
     * @param x
     *         x coordinate
     * @param y
     *         y coordinate
     */
public void show(final int x, final int y) {
    hide();
    ActionGroup actions = updateActions();
    lockLayer = new MenuLockLayer(this);
    popupMenu = new PopupMenu(actions, actionManager, managerProvider, presentationFactory, lockLayer, this, keyBindingAgent, "contextMenu");
    popupMenu.getElement().getStyle().setProperty("opacity", "0");
    popupMenu.getElement().getStyle().setProperty("transition", "opacity 0.5s ease");
    lockLayer.add(popupMenu);
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            popupMenu.getElement().getStyle().setProperty("opacity", "1");
            updateMenuPosition(popupMenu, x, y);
        }
    });
}
Also used : MenuLockLayer(org.eclipse.che.ide.ui.toolbar.MenuLockLayer) ActionGroup(org.eclipse.che.ide.api.action.ActionGroup) DefaultActionGroup(org.eclipse.che.ide.api.action.DefaultActionGroup) Scheduler(com.google.gwt.core.client.Scheduler) PopupMenu(org.eclipse.che.ide.ui.toolbar.PopupMenu)

Example 14 with ActionGroup

use of org.eclipse.che.ide.api.action.ActionGroup in project che by eclipse.

the class StatusPanelGroupViewImpl method expandActionGroup.

private void expandActionGroup(String actionGroupId, final List<Action> newVisibleActions, ActionManager actionManager) {
    final ActionGroup mainActionGroup = (ActionGroup) actionManager.getAction(actionGroupId);
    if (mainActionGroup == null)
        return;
    expandActionGroup(newVisibleActions, actionManager, mainActionGroup);
}
Also used : ActionGroup(org.eclipse.che.ide.api.action.ActionGroup)

Aggregations

ActionGroup (org.eclipse.che.ide.api.action.ActionGroup)14 Action (org.eclipse.che.ide.api.action.Action)10 Presentation (org.eclipse.che.ide.api.action.Presentation)7 ActionEvent (org.eclipse.che.ide.api.action.ActionEvent)5 DefaultActionGroup (org.eclipse.che.ide.api.action.DefaultActionGroup)4 Separator (org.eclipse.che.ide.api.action.Separator)4 ToggleAction (org.eclipse.che.ide.api.action.ToggleAction)4 Element (com.google.gwt.dom.client.Element)2 Widget (com.google.gwt.user.client.ui.Widget)2 CustomComponentAction (org.eclipse.che.ide.api.action.CustomComponentAction)2 Scheduler (com.google.gwt.core.client.Scheduler)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 Image (com.google.gwt.user.client.ui.Image)1 Label (com.google.gwt.user.client.ui.Label)1 ArrayList (java.util.ArrayList)1 MenuLockLayer (org.eclipse.che.ide.ui.toolbar.MenuLockLayer)1 PopupMenu (org.eclipse.che.ide.ui.toolbar.PopupMenu)1 SVGImage (org.vectomatic.dom.svg.ui.SVGImage)1