/** * Initialize popup menu. * * @param actionGroup action group * @param presentationFactory presentation factory * @param lockLayer lock layer, uses as root for attaching this popup menu * @param actionSelectedHandler handler for action selected event * @param keyBindingAgent agent for key binding * @param itemIdPrefix id prefix of the item */ private void initPopupMenu( ActionGroup actionGroup, PresentationFactory presentationFactory, MenuLockLayer lockLayer, ActionSelectedHandler actionSelectedHandler, KeyBindingAgent keyBindingAgent, String itemIdPrefix) { this.presentationFactory = presentationFactory; this.keyBindingAgent = keyBindingAgent; this.itemIdPrefix = itemIdPrefix; this.lockLayer = lockLayer; this.actionSelectedHandler = actionSelectedHandler; List<Utils.VisibleActionGroup> visibleActionGroupList = Utils.renderActionGroup( actionGroup, presentationFactory, actionManager, managerProvider.get()); list = new ArrayList<>(); for (Utils.VisibleActionGroup groupActions : visibleActionGroupList) { list.addAll(groupActions.getActionList()); } popupMenuPanel = new SimplePanel(); disableTextSelection(popupMenuPanel.getElement(), true); initWidget(popupMenuPanel); popupMenuPanel.addDomHandler( new MouseOutHandler() { @Override public void onMouseOut(MouseOutEvent event) { closeSubPopupTimer.cancel(); PopupMenu.this.setStyleNormal(hoveredTR); hoveredTR = null; if (subPopupAnchor != null) { setStyleHovered(subPopupAnchor); } } }, MouseOutEvent.getType()); popupMenuPanel.setStyleName(POPUP_RESOURCES.popup().popupMenuMain()); hasCheckedItems = hasCheckedItems(); }
static { POPUP_RESOURCES.popup().ensureInjected(); }
private void setStyleHovered(Element tr) { tr.setClassName(POPUP_RESOURCES.popup().popupMenuItemOver()); }
/** * Handling MouseOut event. * * @param row - element to be processed. */ protected void setStyleNormal(Element row) { if (row != null) { row.removeClassName(POPUP_RESOURCES.popup().popupMenuItemOver()); } }
/** 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 && 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()); 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 = " "; } else { hotKey = "<nobr> " + hotKey + " </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); }