Search in sources :

Example 1 with ToggleAction

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

Aggregations

Image (com.google.gwt.user.client.ui.Image)1 Label (com.google.gwt.user.client.ui.Label)1 Action (org.eclipse.che.ide.api.action.Action)1 ActionEvent (org.eclipse.che.ide.api.action.ActionEvent)1 ActionGroup (org.eclipse.che.ide.api.action.ActionGroup)1 Presentation (org.eclipse.che.ide.api.action.Presentation)1 Separator (org.eclipse.che.ide.api.action.Separator)1 ToggleAction (org.eclipse.che.ide.api.action.ToggleAction)1 SVGImage (org.vectomatic.dom.svg.ui.SVGImage)1