Search in sources :

Example 1 with IUpdatableAction

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

the class ActionRegistry method registerWorkbenchAction.

protected void registerWorkbenchAction(String commandId) {
    IUpdatableAction action = getAction(commandId);
    ParameterizedCommand command = commandService.createCommand(commandId, null);
    viewer.getKeyHandler().put((KeySequence) bindingService.getBestSequenceFor(command), true, action);
}
Also used : IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 2 with IUpdatableAction

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

the class ActionRegistry method getReplaceEntityAction.

public IUpdatableAction getReplaceEntityAction(EntityDescriptor<?> ed, FeatureDescriptor fd) {
    String edUri = CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed);
    String fdUri = fd != null ? CommonsDataTypePersistenceParser.unparseFeatureDescriptor(fd) : null;
    Map<String, IUpdatableAction> actionMap = replaceActions.get(edUri);
    if (actionMap == null)
        replaceActions.put(edUri, actionMap = new HashMap<String, IUpdatableAction>());
    IUpdatableAction action = actionMap.get(fdUri);
    if (action == null) {
        String label = StringUtils.camelCaseToSpacedWords(ed.getName());
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put(ED_URI_PARAMETER_ID, edUri);
        parameters.put(FD_URI_PARAMETER_ID, fdUri);
        actionMap.put(edUri, action = actionFactory.createE4ActionAdapter(label, REPLACE_ICON_URI, REPLACE_COMMAND_ID, parameters));
    }
    return action;
}
Also used : HashMap(java.util.HashMap) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction)

Example 3 with IUpdatableAction

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

the class ActionRegistry method getAddEntityAction.

public IUpdatableAction getAddEntityAction(EntityDescriptor<?> ed, FeatureDescriptor fd) {
    String edUri = CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed);
    String fdUri = fd != null ? CommonsDataTypePersistenceParser.unparseFeatureDescriptor(fd) : null;
    Map<String, IUpdatableAction> actionMap = addActions.get(edUri);
    if (actionMap == null)
        addActions.put(edUri, actionMap = new HashMap<String, IUpdatableAction>());
    IUpdatableAction action = actionMap.get(fdUri);
    if (action == null) {
        String label = StringUtils.camelCaseToSpacedWords(ed.getName());
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put(ED_URI_PARAMETER_ID, edUri);
        parameters.put(FD_URI_PARAMETER_ID, fdUri);
        actionMap.put(edUri, action = actionFactory.createE4ActionAdapter(label, ADD_ICON_URI, ADD_COMMAND_ID, parameters));
    }
    return action;
}
Also used : HashMap(java.util.HashMap) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction)

Example 4 with IUpdatableAction

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

the class ContentAssistCompositeContributionItem method getItems.

protected IContributionItem[] getItems() {
    List<IContributionItem> items = new ArrayList<IContributionItem>();
    Object selection = contextProvider.getContext().get(ESelectionService.class).getSelection();
    if (!(selection instanceof IBindingManager))
        return new IContributionItem[0];
    IBindingManager bm = (IBindingManager) selection;
    IEntity focusEntity = bm.wGet("focusEntity");
    IEntity[] values = ContentAssistOperation.getContentAssist(focusEntity, bm);
    ActionListContainer container = ActionListContainer.create(items);
    if (values.length == 1 && !EntityUtils.isData(values[0])) {
        try {
            bm.wEnterScope();
            bm.wDefValue("context", contextProvider.getContext());
            bm.wDefValue("itemContainer", container);
            bm.wDefValue("fillMenuStrategy", FlatFillMenuStrategy.instance());
            InterpreterOperation.interpret(values[0], bm);
        } finally {
            bm.wExitScope();
        }
    } else if (values.length > 0) {
        IAction[] actions = new IAction[values.length];
        int actionsSize = 0;
        for (int i = 0; i < values.length; i++) {
            IEntity value = values[i];
            if (!Matcher.match(value, focusEntity)) {
                IUpdatableAction action = contextProvider.getActionRegistry().getActionFactory().createReplaceFragmentAction(DataTypeUtils.getAsPresentationString(value), BindingManagerFactory.instance.createSpecificValue(true), value);
                if (action.isEnabled())
                    actions[actionsSize++] = action;
            }
        }
        HierarchicalFillMenuStrategy.instance().fillMenu(container, ActionSet.create(actions), 0, actionsSize);
    }
    return items.toArray(new IContributionItem[items.size()]);
}
Also used : IEntity(org.whole.lang.model.IEntity) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction)

Example 5 with IUpdatableAction

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

the class ActionsCompositeContributionItem method getItems.

@Override
protected IContributionItem[] getItems() {
    Object selection = contextProvider.getContext().get(ESelectionService.class).getSelection();
    if (!(selection instanceof IBindingManager) || !((IBindingManager) selection).wIsSet("self"))
        return new IContributionItem[0];
    IBindingManager bm = (IBindingManager) selection;
    String languageURI = bm.wGet("self").wGetLanguageKit().getURI();
    Map<GuardedAction, String> actionsMap = new HashMap<GuardedAction, String>();
    IResourceRegistry<Resource> registry = ActionsRegistry.instance();
    for (IResource resource : registry.getResources(false)) {
        LanguageActionFactory actionsModule = resource.getEntity();
        URI targetLanguage = actionsModule.getTargetLanguage();
        if (DataTypeUtils.getDataKind(targetLanguage).isString() && !languageURI.equals(targetLanguage.getValue()))
            continue;
        for (GuardedAction guardedAction : Matcher.findAll(ActionsEntityDescriptorEnum.GuardedAction, getActions(actionsModule), false)) {
            String actionName = guardedAction.getName().getValue();
            String functionUri = resource.getURI() + '#' + actionName;
            actionsMap.put(guardedAction, functionUri);
        }
    }
    List<IAction> actions = new ArrayList<IAction>();
    List<GuardedAction> guardedActions = new ArrayList<GuardedAction>(actionsMap.keySet());
    Collections.sort(guardedActions, new Comparator<GuardedAction>() {

        public int compare(GuardedAction a1, GuardedAction a2) {
            return a1.getName().getValue().compareTo(a2.getName().getValue());
        }
    });
    for (GuardedAction guardedAction : guardedActions) {
        String actionName = guardedAction.getName().getValue();
        String functionUri = actionsMap.get(guardedAction);
        IUpdatableAction action = contextProvider.getActionRegistry().getActionFactory().createActionCallAction(actionName, isAnalyze(), guardedAction.getEnablerPredicate(), functionUri);
        action.update();
        actions.add(action);
    }
    List<IContributionItem> items = new ArrayList<IContributionItem>();
    HierarchicalFillMenuStrategy.instance().fillMenu(ActionListContainer.create(items), ActionSet.create(actions.toArray(new IAction[actions.size()])), 0, actions.size());
    return items.toArray(new IContributionItem[items.size()]);
}
Also used : LanguageActionFactory(org.whole.lang.actions.model.LanguageActionFactory) GuardedAction(org.whole.lang.actions.model.GuardedAction) IAction(org.eclipse.jface.action.IAction) HashMap(java.util.HashMap) IContributionItem(org.eclipse.jface.action.IContributionItem) Resource(org.whole.lang.resources.Resource) IResource(org.whole.lang.resources.IResource) ArrayList(java.util.ArrayList) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) URI(org.whole.lang.actions.model.URI) IBindingManager(org.whole.lang.bindings.IBindingManager) IResource(org.whole.lang.resources.IResource)

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