Search in sources :

Example 21 with Action

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

the class SubPanelViewImpl method onMenuItemSelected.

@Override
public void onMenuItemSelected(MenuItem menuItem) {
    final Object data = menuItem.getData();
    if (data instanceof Tab) {
        final WidgetToShow widget = tabs2Widgets.get(data);
        if (widget != null) {
            activateWidget(widget);
            delegate.onWidgetFocused(widget.getWidget());
        }
    } else if (data instanceof Action) {
        ((Action) data).actionPerformed(null);
    }
}
Also used : RemoveAllWidgetsInPaneAction(org.eclipse.che.ide.ui.multisplitpanel.actions.RemoveAllWidgetsInPaneAction) SplitHorizontallyAction(org.eclipse.che.ide.ui.multisplitpanel.actions.SplitHorizontallyAction) Action(org.eclipse.che.ide.api.action.Action) ClosePaneAction(org.eclipse.che.ide.ui.multisplitpanel.actions.ClosePaneAction) SplitVerticallyAction(org.eclipse.che.ide.ui.multisplitpanel.actions.SplitVerticallyAction) Tab(org.eclipse.che.ide.ui.multisplitpanel.tab.Tab) WidgetToShow(org.eclipse.che.ide.ui.multisplitpanel.WidgetToShow)

Example 22 with Action

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

the class PopupMenu method redraw.

/** Render Popup Menu component. */
private void redraw() {
    String idPrefix = itemIdPrefix;
    if (idPrefix == null) {
        idPrefix = "";
    } else {
        idPrefix += "/";
    }
    table = new PopupMenuTable();
    table.setStyleName(POPUP_RESOURCES.popup().popupMenuTable());
    table.setCellPadding(0);
    table.setCellSpacing(0);
    for (int i = 0; i < list.size(); i++) {
        Action menuItem = list.get(i);
        if (menuItem instanceof Separator) {
            final String separatorText = ((Separator) menuItem).getText();
            if (separatorText == null) {
                table.getCellFormatter().setStyleName(i, 0, POPUP_RESOURCES.popup().popupMenuDelimiter());
            } else {
                table.setWidget(i, 0, new Label(separatorText));
                table.getCellFormatter().setStyleName(i, 0, POPUP_RESOURCES.popup().popupMenuTextDelimiter());
            }
            table.getFlexCellFormatter().setColSpan(i, 0, hasCheckedItems ? 5 : 4);
        } else {
            Presentation presentation = presentationFactory.getPresentation(menuItem);
            if (presentation.getImageResource() != null) {
                Image image = new Image(presentation.getImageResource());
                table.setWidget(i, 0, image);
            } else if (presentation.getSVGResource() != null) {
                SVGImage image = new SVGImage(presentation.getSVGResource());
                table.setWidget(i, 0, image);
            } else if (presentation.getHTMLResource() != null) {
                table.setHTML(i, 0, presentation.getHTMLResource());
            }
            table.getCellFormatter().setStyleName(i, 0, presentation.isEnabled() ? POPUP_RESOURCES.popup().popupMenuIconField() : POPUP_RESOURCES.popup().popupMenuIconFieldDisabled());
            int work = 1;
            if (hasCheckedItems) {
                if (menuItem instanceof ToggleAction) {
                    ToggleAction toggleAction = (ToggleAction) menuItem;
                    ActionEvent e = new ActionEvent(presentationFactory.getPresentation(toggleAction), actionManager, managerProvider.get());
                    if (toggleAction.isSelected(e)) {
                        // Temporary solution
                        table.setHTML(i, work, "<i class=\"fa fa-check\"></i>");
                    }
                    table.getCellFormatter().setStyleName(i, work, presentation.isEnabled() ? POPUP_RESOURCES.popup().popupMenuCheckField() : POPUP_RESOURCES.popup().popupMenuCheckFieldDisabled());
                } else {
                    table.setHTML(i, work, "");
                }
                work++;
            }
            table.setHTML(i, work, "<nobr id=\"" + idPrefix + presentation.getText() + "\">" + presentation.getText() + "</nobr>");
            table.getCellFormatter().setStyleName(i, work, presentation.isEnabled() ? POPUP_RESOURCES.popup().popupMenuTitleField() : POPUP_RESOURCES.popup().popupMenuTitleFieldDisabled());
            if (showTooltips) {
                Tooltip.create((elemental.dom.Element) table.getCellFormatter().getElement(i, work), BOTTOM, MIDDLE, presentation.getText());
            }
            work++;
            String hotKey = KeyMapUtil.getShortcutText(keyBindingAgent.getKeyBinding(actionManager.getId(menuItem)));
            if (hotKey == null) {
                hotKey = "&nbsp;";
            } else {
                hotKey = "<nobr>&nbsp;" + hotKey + "&nbsp;</nobr>";
            }
            table.setHTML(i, work, hotKey);
            table.getCellFormatter().setStyleName(i, work, presentation.isEnabled() ? POPUP_RESOURCES.popup().popupMenuHotKeyField() : POPUP_RESOURCES.popup().popupMenuHotKeyFieldDisabled());
            work++;
            if (menuItem instanceof ActionGroup && !(((ActionGroup) menuItem).canBePerformed() && !Utils.hasVisibleChildren((ActionGroup) menuItem, presentationFactory, actionManager, managerProvider.get()))) {
                table.setWidget(i, work, new SVGImage(POPUP_RESOURCES.subMenu()));
                table.getCellFormatter().setStyleName(i, work, presentation.isEnabled() ? POPUP_RESOURCES.popup().popupMenuSubMenuField() : POPUP_RESOURCES.popup().popupMenuSubMenuFieldDisabled());
            } else {
                table.getCellFormatter().setStyleName(i, work, presentation.isEnabled() ? POPUP_RESOURCES.popup().popupMenuSubMenuField() : POPUP_RESOURCES.popup().popupMenuSubMenuFieldDisabled());
            }
            work++;
            table.getRowFormatter().getElement(i).setAttribute("item-index", Integer.toString(i));
            table.getRowFormatter().getElement(i).setAttribute("item-enabled", Boolean.toString(presentation.isEnabled()));
            String actionId = actionManager.getId(menuItem);
            String debugId;
            if (actionId == null) {
                debugId = idPrefix + menuItem.getTemplatePresentation().getText();
            } else {
                debugId = idPrefix + actionId;
            }
            UIObject.ensureDebugId(table.getRowFormatter().getElement(i), debugId);
        }
    }
    popupMenuPanel.add(table);
}
Also used : ToggleAction(org.eclipse.che.ide.api.action.ToggleAction) Action(org.eclipse.che.ide.api.action.Action) ActionEvent(org.eclipse.che.ide.api.action.ActionEvent) Label(com.google.gwt.user.client.ui.Label) Presentation(org.eclipse.che.ide.api.action.Presentation) Image(com.google.gwt.user.client.ui.Image) SVGImage(org.vectomatic.dom.svg.ui.SVGImage) SVGImage(org.vectomatic.dom.svg.ui.SVGImage) ActionGroup(org.eclipse.che.ide.api.action.ActionGroup) ToggleAction(org.eclipse.che.ide.api.action.ToggleAction) Separator(org.eclipse.che.ide.api.action.Separator)

Example 23 with Action

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

the class PopupMenu method onRowClicked.

/**
     * Handle Mouse Click
     *
     * @param tr
     */
protected void onRowClicked(Element tr) {
    if (!isRowEnabled(tr) || tr == subPopupAnchor) {
        return;
    }
    int itemIndex = Integer.parseInt(tr.getAttribute("item-index"));
    Action menuItem = list.get(itemIndex);
    if (menuItem instanceof ActionGroup && (!((ActionGroup) menuItem).canBePerformed() && Utils.hasVisibleChildren((ActionGroup) menuItem, presentationFactory, actionManager, managerProvider.get()))) {
        openSubPopup(tr);
    } else {
        if (actionSelectedHandler != null) {
            actionSelectedHandler.onActionSelected(menuItem);
        }
        ActionEvent e = new ActionEvent(presentationFactory.getPresentation(menuItem), actionManager, managerProvider.get());
        menuItem.actionPerformed(e);
    }
}
Also used : ToggleAction(org.eclipse.che.ide.api.action.ToggleAction) Action(org.eclipse.che.ide.api.action.Action) ActionGroup(org.eclipse.che.ide.api.action.ActionGroup) ActionEvent(org.eclipse.che.ide.api.action.ActionEvent)

Example 24 with Action

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

the class Utils method hasVisibleChildren.

/**
     * Returns true if action group has visible children.
     *
     * @param group
     *         action group
     * @param factory
     *         presentation factory
     * @param actionManager
     *         action manager
     * @param perspectiveManager
     *         perspective manager
     * @return boolean
     */
public static boolean hasVisibleChildren(ActionGroup group, PresentationFactory factory, ActionManager actionManager, PerspectiveManager perspectiveManager) {
    ActionEvent event = new ActionEvent(factory.getPresentation(group), actionManager, perspectiveManager);
    for (Action anAction : group.getChildren(event)) {
        if (anAction == null) {
            Log.error(Utils.class, "Null action found in group " + group + ", " + factory.getPresentation(group));
            continue;
        }
        if (anAction instanceof Separator) {
            continue;
        }
        final Presentation presentation = factory.getPresentation(anAction);
        anAction.update(new ActionEvent(presentation, actionManager, perspectiveManager));
        if (anAction instanceof ActionGroup) {
            ActionGroup childGroup = (ActionGroup) anAction;
            // popup menu must be visible itself
            if (childGroup.isPopup()) {
                if (!presentation.isVisible()) {
                    continue;
                }
            }
            if (hasVisibleChildren(childGroup, factory, actionManager, perspectiveManager)) {
                return true;
            }
        } else if (presentation.isVisible()) {
            return true;
        }
    }
    return false;
}
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) Presentation(org.eclipse.che.ide.api.action.Presentation) Separator(org.eclipse.che.ide.api.action.Separator)

Example 25 with Action

use of org.eclipse.che.ide.api.action.Action 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)

Aggregations

Action (org.eclipse.che.ide.api.action.Action)32 ActionEvent (org.eclipse.che.ide.api.action.ActionEvent)10 ActionGroup (org.eclipse.che.ide.api.action.ActionGroup)10 DefaultActionGroup (org.eclipse.che.ide.api.action.DefaultActionGroup)10 Presentation (org.eclipse.che.ide.api.action.Presentation)10 Separator (org.eclipse.che.ide.api.action.Separator)5 ToggleAction (org.eclipse.che.ide.api.action.ToggleAction)5 ArrayList (java.util.ArrayList)4 CustomComponentAction (org.eclipse.che.ide.api.action.CustomComponentAction)4 CreateProjectAction (org.eclipse.che.ide.actions.CreateProjectAction)2 ImportProjectAction (org.eclipse.che.ide.actions.ImportProjectAction)2 PromisableAction (org.eclipse.che.ide.api.action.PromisableAction)2 SplitHorizontallyAction (org.eclipse.che.ide.part.editor.actions.SplitHorizontallyAction)2 SplitVerticallyAction (org.eclipse.che.ide.part.editor.actions.SplitVerticallyAction)2 Test (org.junit.Test)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 DivElement (com.google.gwt.dom.client.DivElement)1 Element (com.google.gwt.dom.client.Element)1 RegExp (com.google.gwt.regexp.shared.RegExp)1