use of org.eclipse.che.ide.api.action.ActionGroup in project che by eclipse.
the class ToolbarViewImpl method createToolbarPart.
/**
* Creates a toolbar part widget.
*
* @return widget
*/
private Widget createToolbarPart(List<Utils.VisibleActionGroup> visibleActionGroupList) {
FlowPanel toolbarPart = new FlowPanel();
if (addSeparatorFirst) {
final Widget firstDelimiter = createDelimiter();
toolbarPart.add(firstDelimiter);
}
for (Utils.VisibleActionGroup visibleActionGroup : visibleActionGroupList) {
List<Action> actions = visibleActionGroup.getActionList();
if (actions == null || actions.size() == 0) {
continue;
}
FlowPanel actionGroupPanel = new FlowPanel();
actionGroupPanel.setStyleName(toolbarResources.toolbar().toolbarActionGroupPanel());
toolbarPart.add(actionGroupPanel);
for (Action action : actions) {
if (action instanceof Separator) {
int actionIndex = actions.indexOf(action);
if (actionIndex > 0 && actionIndex < actions.size() - 1) {
final Widget delimiter = createDelimiter();
actionGroupPanel.add(delimiter);
}
} else if (action instanceof CustomComponentAction) {
Presentation presentation = presentationFactory.getPresentation(action);
Widget customComponent = ((CustomComponentAction) action).createCustomComponent(presentation);
actionGroupPanel.add(customComponent);
} else if (action instanceof ActionGroup && ((ActionGroup) action).isPopup()) {
ActionPopupButton button = new ActionPopupButton((ActionGroup) action, actionManager, keyBindingAgent, presentationFactory, managerProvider, toolbarResources);
actionGroupPanel.add(button);
} else {
final ActionButton button = createToolbarButton(action);
actionGroupPanel.add(button);
}
}
}
return toolbarPart;
}
use of org.eclipse.che.ide.api.action.ActionGroup in project che by eclipse.
the class DropDownWidgetImpl method updateActions.
/**
* Refresh the list of visible actions.
*/
private void updateActions() {
actions.removeAll();
ActionGroup mainActionGroup = (ActionGroup) actionManager.getAction(actionGroupId);
if (mainActionGroup == null) {
return;
}
Action[] children = mainActionGroup.getChildren(null);
for (Action action : children) {
Presentation presentation = presentationFactory.getPresentation(action);
ActionEvent e = new ActionEvent(presentation, actionManager, managerProvider.get());
action.update(e);
if (presentation.isVisible()) {
actions.add(action);
}
}
}
use of org.eclipse.che.ide.api.action.ActionGroup 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 = " ";
} 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);
}
use of org.eclipse.che.ide.api.action.ActionGroup 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);
}
}
use of org.eclipse.che.ide.api.action.ActionGroup 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;
}
Aggregations