Search in sources :

Example 1 with IItemContainer

use of org.whole.lang.ui.menu.IItemContainer in project whole by wholeplatform.

the class ActionsE4InterpreterVisitor method visit.

@Override
public void visit(GroupAction entity) {
    IItemContainer<IAction, ImageDescriptor> container = (IItemContainer<IAction, ImageDescriptor>) getBindings().wGetValue("itemContainer");
    String groupName = stringEvaluate(entity.getText());
    IFillMenuStrategy strategy;
    FillStrategy fillStrategy = entity.getFillStrategy();
    if (Matcher.match(Hierarchical, fillStrategy))
        strategy = createFillMenuStrategy((Hierarchical) fillStrategy, groupName);
    else
        strategy = FlatFillMenuStrategy.instance(groupName);
    if (EntityUtils.hasParent(entity) && Matcher.match(SeparatedAction, entity.wGetParent()))
        container.addSeparator(groupName);
    else
        container.addGroupMarker(groupName);
    getBindings().wEnterScope();
    getBindings().wDefValue("fillMenuStrategy", strategy);
    lazyEvaluate(entity.getActions());
    getBindings().wExitScope();
    setResult(null);
}
Also used : FillStrategy(org.whole.lang.actions.model.FillStrategy) IAction(org.eclipse.jface.action.IAction) IItemContainer(org.whole.lang.ui.menu.IItemContainer) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IFillMenuStrategy(org.whole.lang.ui.menu.IFillMenuStrategy)

Example 2 with IItemContainer

use of org.whole.lang.ui.menu.IItemContainer in project whole by wholeplatform.

the class ActionsE4InterpreterVisitor method visit.

@Override
public void visit(SubgroupAction entity) {
    IItemContainer<IAction, ImageDescriptor> container = (IItemContainer<IAction, ImageDescriptor>) getBindings().wGetValue("itemContainer");
    String groupName = stringEvaluate(entity.getText());
    IFillMenuStrategy strategy;
    FillStrategy fillStrategy = entity.getFillStrategy();
    if (Matcher.match(Hierarchical, fillStrategy))
        strategy = createFillMenuStrategy((Hierarchical) fillStrategy);
    else
        strategy = FlatFillMenuStrategy.instance();
    IItemContainer<IAction, ImageDescriptor> subContainer = container.addIntoSubContainer(groupName, null);
    getBindings().wEnterScope();
    getBindings().wDefValue("itemContainer", subContainer);
    getBindings().wDefValue("fillMenuStrategy", strategy);
    lazyEvaluate(entity.getActions());
    getBindings().wExitScope();
    setResult(null);
}
Also used : FillStrategy(org.whole.lang.actions.model.FillStrategy) IAction(org.eclipse.jface.action.IAction) IItemContainer(org.whole.lang.ui.menu.IItemContainer) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IFillMenuStrategy(org.whole.lang.ui.menu.IFillMenuStrategy)

Example 3 with IItemContainer

use of org.whole.lang.ui.menu.IItemContainer in project whole by wholeplatform.

the class ActionsE4InterpreterVisitor method visit.

@Override
public void visit(Actions entity) {
    IItemContainer<IAction, ImageDescriptor> container = (IItemContainer<IAction, ImageDescriptor>) getBindings().wGetValue("itemContainer");
    IFillMenuStrategy strategy = (IFillMenuStrategy) getBindings().wGetValue("fillMenuStrategy");
    int size = entity.wSize();
    List<IAction> contributions = new ArrayList<IAction>();
    for (int i = 0; i < size; i++) {
        Action action = (Action) entity.wGet(i);
        if (Matcher.isAssignableAsIsFrom(GroupAction, action)) {
            // FIXME, add a boolean modifier to GroupAction and SubGroupAction
            if (strategy instanceof HierarchicalFillMenuStrategy)
                Collections.sort(contributions, ActionsComparator.instance());
            IAction[] actions = contributions.toArray(new IAction[contributions.size()]);
            strategy.fillMenu(container, ActionSet.create(actions), 0, actions.length);
            contributions.clear();
        }
        IEntity result = evaluate(action);
        if (result == null)
            continue;
        IUpdatableAction updatableAction = (IUpdatableAction) result.wGetValue();
        updatableAction.update();
        if (updatableAction.isEnabled())
            contributions.add(updatableAction);
    }
    // FIXME, add a sort boolean feature to GroupAction and SubGroupAction
    if (strategy instanceof HierarchicalFillMenuStrategy)
        Collections.sort(contributions, ActionsComparator.instance());
    IAction[] actions = contributions.toArray(new IAction[contributions.size()]);
    strategy.fillMenu(container, ActionSet.create(actions), 0, actions.length);
}
Also used : SeparatedAction(org.whole.lang.actions.model.SeparatedAction) IAction(org.eclipse.jface.action.IAction) TemplateAction(org.whole.lang.actions.model.TemplateAction) SubgroupAction(org.whole.lang.actions.model.SubgroupAction) GroupAction(org.whole.lang.actions.model.GroupAction) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) CustomAction(org.whole.lang.actions.model.CustomAction) Action(org.whole.lang.actions.model.Action) PerformAction(org.whole.lang.actions.model.PerformAction) IAction(org.eclipse.jface.action.IAction) IEntity(org.whole.lang.model.IEntity) IItemContainer(org.whole.lang.ui.menu.IItemContainer) ArrayList(java.util.ArrayList) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) IFillMenuStrategy(org.whole.lang.ui.menu.IFillMenuStrategy) HierarchicalFillMenuStrategy(org.whole.lang.ui.menu.HierarchicalFillMenuStrategy) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Aggregations

IAction (org.eclipse.jface.action.IAction)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 IFillMenuStrategy (org.whole.lang.ui.menu.IFillMenuStrategy)3 IItemContainer (org.whole.lang.ui.menu.IItemContainer)3 FillStrategy (org.whole.lang.actions.model.FillStrategy)2 ArrayList (java.util.ArrayList)1 Action (org.whole.lang.actions.model.Action)1 CustomAction (org.whole.lang.actions.model.CustomAction)1 GroupAction (org.whole.lang.actions.model.GroupAction)1 PerformAction (org.whole.lang.actions.model.PerformAction)1 SeparatedAction (org.whole.lang.actions.model.SeparatedAction)1 SubgroupAction (org.whole.lang.actions.model.SubgroupAction)1 TemplateAction (org.whole.lang.actions.model.TemplateAction)1 IEntity (org.whole.lang.model.IEntity)1 IUpdatableAction (org.whole.lang.ui.actions.IUpdatableAction)1 HierarchicalFillMenuStrategy (org.whole.lang.ui.menu.HierarchicalFillMenuStrategy)1