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;
}
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);
}
});
}
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);
}
});
}
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);
}
Aggregations