Search in sources :

Example 6 with IUpdatableAction

use of org.whole.lang.ui.actions.IUpdatableAction in project whole by wholeplatform.

the class EntityAssistCompositeContributionItem method createTextActions.

protected List<IAction> createTextActions(ILanguageKit lk, IEntity targetEntity) {
    List<IAction> textActions = new ArrayList<IAction>();
    IGEFEditorKit editorKit = (IGEFEditorKit) (targetEntity.wGetLanguageKit().equals(lk) ? ReflectionFactory.getEditorKit(targetEntity) : lk.getDefaultEditorKit());
    for (Object[] textAction : E4Utils.textActionsFor(lk, ((IGEFEditorKit) editorKit).getActionFactory().textActions())) {
        EntityDescriptor<?> ed = (EntityDescriptor<?>) textAction[1];
        if (Matcher.matchImpl(ed, targetEntity)) {
            @SuppressWarnings("unchecked") Class<IUpdatableAction> actionClass = (Class<IUpdatableAction>) textAction[2];
            try {
                IUpdatableAction action = actionClass.getConstructor(IEclipseContext.class).newInstance(contextProvider.getContext());
                action.update();
                if (action.isEnabled())
                    textActions.add(action);
            } catch (Exception e) {
            }
        }
    }
    return textActions;
}
Also used : IAction(org.eclipse.jface.action.IAction) ArrayList(java.util.ArrayList) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) MalformedURLException(java.net.MalformedURLException) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IGEFEditorKit(org.whole.lang.ui.editor.IGEFEditorKit)

Example 7 with IUpdatableAction

use of org.whole.lang.ui.actions.IUpdatableAction in project whole by wholeplatform.

the class JFaceMenuBuilder method addAddEntityItem.

public void addAddEntityItem(EntityDescriptor<?> ed) {
    IUpdatableAction action = actionRegistry.getAddEntityAction(ed);
    actionsToUpdate.add(action);
    addItem(action);
}
Also used : IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction)

Example 8 with IUpdatableAction

use of org.whole.lang.ui.actions.IUpdatableAction in project whole by wholeplatform.

the class JFaceMenuBuilder method addReplaceEntityItem.

public void addReplaceEntityItem(EntityDescriptor<?> ed) {
    IUpdatableAction action = actionRegistry.getReplaceEntityAction(ed);
    actionsToUpdate.add(action);
    addItem(action);
}
Also used : IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction)

Example 9 with IUpdatableAction

use of org.whole.lang.ui.actions.IUpdatableAction in project whole by wholeplatform.

the class JFaceMenuBuilder method addNotationsItem.

public void addNotationsItem() {
    IBindingManager bm = getBindings();
    IMenuManager menu = createMenu(NOTATION_LABEL, getNotationsVisibleWhen());
    addItem(menu);
    if (!HandlersBehavior.isValidFocusEntityPart(bm))
        return;
    IEntity focusEntity = bm.wGet("focusEntity");
    IEditorKit selectedEditorKit = focusEntity.wGetEditorKit();
    for (IEditorKit editorKit : ReflectionFactory.getEditorKits(focusEntity.wGetLanguageKit().getURI())) {
        if (!editorKit.canApply(focusEntity.wGetLanguageKit()))
            continue;
        IUpdatableAction action = actionRegistry.getSelectNotationAction(editorKit);
        action.setChecked(editorKit == selectedEditorKit);
        menu.add(action);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) IEditorKit(org.whole.lang.reflect.IEditorKit) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 10 with IUpdatableAction

use of org.whole.lang.ui.actions.IUpdatableAction 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

IUpdatableAction (org.whole.lang.ui.actions.IUpdatableAction)12 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 IAction (org.eclipse.jface.action.IAction)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 IEntity (org.whole.lang.model.IEntity)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)2 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 IEditorKit (org.whole.lang.reflect.IEditorKit)2 IGEFEditorKit (org.whole.lang.ui.editor.IGEFEditorKit)2 MalformedURLException (java.net.MalformedURLException)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 KeySequence (org.eclipse.jface.bindings.keys.KeySequence)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)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 GuardedAction (org.whole.lang.actions.model.GuardedAction)1