Search in sources :

Example 11 with GroupAction

use of org.whole.lang.actions.model.GroupAction in project whole by wholeplatform.

the class ActionsUIContentAssistVisitor method allLanguages.

protected boolean allLanguages(IEntity entity) {
    if (!Matcher.match(ActionsEntityDescriptorEnum.URI, entity))
        return false;
    ActionsEntityFactory aef = ActionsEntityFactory.instance;
    GroupAction languagesGroup = aef.createGroupAction();
    Actions actions = aef.createActions(0);
    String actualLanguageURI = DataTypeUtils.getAsPersistenceString(entity);
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
        String uri = languageKit.getURI();
        if (uri.equals(actualLanguageURI))
            continue;
        URI prototype = aef.createURI(uri);
        actions.wAdd(createReplaceTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
    }
    languagesGroup.setActions(actions);
    return mergeResult(languagesGroup);
}
Also used : GroupAction(org.whole.lang.actions.model.GroupAction) Actions(org.whole.lang.actions.model.Actions) URI(org.whole.lang.actions.model.URI) ActionsEntityFactory(org.whole.lang.actions.factories.ActionsEntityFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 12 with GroupAction

use of org.whole.lang.actions.model.GroupAction in project whole by wholeplatform.

the class FramesContentAssistVisitor method allEntityTypes.

private boolean allEntityTypes(IEntity entity, EntityDescriptor<?> type) {
    if (!EntityUtils.hasParent(entity))
        return false;
    boolean subtypeTest = false;
    ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
    GroupAction languagesGroup = aef.createGroupAction();
    languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
    languagesGroup.getText().setValue("frames.languages");
    Actions actions = aef.createActions(0);
    FramesEntityFactory fef = FramesEntityFactory.instance;
    String actualLanguageURI = "";
    String actualEntityName = "";
    EntityDescriptor<?> actualED = null;
    EntityDescriptor<?> targetED = type;
    try {
        actualED = CommonsDataTypePersistenceParser.parseEntityDescriptor(entity.wStringValue());
        actualLanguageURI = actualED.getLanguageKit().getURI();
        actualEntityName = actualED.getName();
    } catch (Exception e) {
        if (DataTypeUtils.getDataKind(entity).isString())
            actualEntityName = entity.wStringValue();
    }
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
        if (languageKit.getURI().equals(actualLanguageURI))
            continue;
        EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
        EntityDescriptor<?> ed = null;
        if (actualEntityName.length() > 0)
            ed = edEnum.valueOf(actualEntityName);
        if (ed == null) {
            if (subtypeTest)
                ed = edEnum.valueOf(0);
            else {
                Iterator<EntityDescriptor<?>> iterator = edEnum.values().iterator();
                EntityDescriptor<?> nextED;
                while (ed == null && iterator.hasNext()) if (!(nextED = iterator.next()).isAbstract())
                    ed = nextED;
                if (ed == null)
                    continue;
            }
        }
        IEntity prototype = fef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
        actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
    }
    languagesGroup.setActions(actions);
    boolean addedLanguages = EntityUtils.isResolver(entity) ? mergeResult(targetED, languagesGroup) : mergeResult(languagesGroup);
    if (actualED != null) {
        GroupAction typenamesGroup = aef.createGroupAction();
        typenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
        typenamesGroup.getText().setValue(subtypeTest ? "frames.subtypenames" : "frames.typenames");
        actions = aef.createActions(0);
        EntityDescriptorEnum edEnum = actualED.getEntityDescriptorEnum();
        List<EntityDescriptor<?>> eds = new ArrayList<EntityDescriptor<?>>(edEnum.values());
        Collections.sort(eds, EnumValueImpl.getByNameComparator());
        for (EntityDescriptor<?> ed : eds) {
            if (ed.equals(actualED) || (!subtypeTest && ed.isAbstract()))
                continue;
            IEntity prototype = fef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
            actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ed.getName()));
        }
        typenamesGroup.setActions(actions);
        addedLanguages |= EntityUtils.isResolver(entity) ? mergeResult(targetED, typenamesGroup) : mergeResult(typenamesGroup);
    }
    return addedLanguages;
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) Actions(org.whole.lang.actions.model.Actions) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) ILanguageKit(org.whole.lang.reflect.ILanguageKit) GroupAction(org.whole.lang.actions.model.GroupAction) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) FramesEntityFactory(org.whole.lang.frames.factories.FramesEntityFactory) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)

Example 13 with GroupAction

use of org.whole.lang.actions.model.GroupAction 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)

Example 14 with GroupAction

use of org.whole.lang.actions.model.GroupAction in project whole by wholeplatform.

the class WorkflowsIDEContentAssistVisitor method chooseClass.

protected boolean chooseClass(IEntity entity) {
    if (!WorkflowsUtils.isClassNameInJavaActivity(entity))
        return false;
    ReplaceWithClassNameAction action = new ReplaceWithClassNameAction((IEclipseContext) getBindings().wGetValue("eclipse#eclipseContext"), WorkflowsEntityDescriptorEnum.StringLiteral, entity.wStringValue(), "Select class...");
    ActionsEntityFactory aef = ActionsEntityFactory.instance;
    GroupAction customGroup = aef.createGroupAction();
    customGroup.setFillStrategy(aef.createFlat());
    customGroup.getText().setValue("workflows.custom");
    customGroup.setActions(aef.createActions(aef.createCustomAction(action)));
    return EntityUtils.isResolver(entity) ? mergeResult(StringLiteral, customGroup) : mergeResult(customGroup);
}
Also used : ReplaceWithClassNameAction(org.whole.lang.ui.actions.ReplaceWithClassNameAction) GroupAction(org.whole.lang.actions.model.GroupAction) ActionsEntityFactory(org.whole.lang.actions.factories.ActionsEntityFactory)

Example 15 with GroupAction

use of org.whole.lang.actions.model.GroupAction in project whole by wholeplatform.

the class WorkflowsIDEContentAssistVisitor method chooseResource.

protected boolean chooseResource(IEntity entity) {
    Object customAction = null;
    if (WorkflowsUtils.isResourceInPersistenceActivity(entity)) {
        PersistenceActivity parent = (PersistenceActivity) entity.wGetParent();
        Expression expression = parent.getPersistence();
        IPersistenceKit persistenceKit = Matcher.match(WorkflowsEntityDescriptorEnum.StringLiteral, expression) ? (ReflectionFactory.hasPersistenceKit(expression.wStringValue()) ? ReflectionFactory.getPersistenceKit(expression.wStringValue()) : null) : ReflectionFactory.getDefaultPersistenceKit();
        customAction = new ReplaceWithResourceAndPersistenceAction((IEclipseContext) getBindings().wGetValue("eclipse#eclipseContext"), WorkflowsEntityDescriptorEnum.StringLiteral, entity.wStringValue(), persistenceKit, "Select resource...") {

            protected boolean isLoading(IEntity entity) {
                return Matcher.match(WorkflowsEntityDescriptorEnum.LoadModel, entity.wGetParent());
            }

            protected ResourceKind getResourceKind(IEntity selectedEntity) {
                switch(selectedEntity.wGetParent().wGet(WorkflowsFeatureDescriptorEnum.resourceKind).wEnumValue().getOrdinal()) {
                    default:
                    case ResourceKindEnum.WORKSPACE_ord:
                        return ResourceKind.WORKSPACE;
                    case ResourceKindEnum.FILE_SYSTEM_ord:
                        return ResourceKind.FILE_SYSTEM;
                    case ResourceKindEnum.CLASSPATH_ord:
                        return ResourceKind.CLASSPATH;
                    case ResourceKindEnum.URL_ord:
                        return ResourceKind.URL;
                }
            }

            protected void performReplacePersistence(IEntity parent) {
                ((PersistenceActivity) parent).setPersistence(WorkflowsEntityFactory.instance.createStringLiteral(persistenceKit.getId()));
            }
        };
    } else if (WorkflowsUtils.isResourceInArtifactsActivity(entity)) {
        customAction = new ReplaceWithResourceAction((IEclipseContext) getBindings().wGetValue("eclipse#eclipseContext"), WorkflowsEntityDescriptorEnum.StringLiteral, entity.wStringValue(), "Select resource...") {

            protected boolean isLoading(IEntity entity) {
                return Matcher.match(WorkflowsEntityDescriptorEnum.LoadArtifacts, entity.wGetParent());
            }

            protected ResourceKind getResourceKind(IEntity selectedEntity) {
                switch(selectedEntity.wGetParent().wGet(WorkflowsFeatureDescriptorEnum.rootResourceKind).wEnumValue().getOrdinal()) {
                    default:
                    case ResourceKindEnum.WORKSPACE_ord:
                        return ResourceKind.WORKSPACE;
                    case ResourceKindEnum.FILE_SYSTEM_ord:
                        return ResourceKind.FILE_SYSTEM;
                    case ResourceKindEnum.CLASSPATH_ord:
                        return ResourceKind.CLASSPATH;
                    case ResourceKindEnum.URL_ord:
                        return ResourceKind.URL;
                }
            }
        };
    } else
        return false;
    ActionsEntityFactory aef = ActionsEntityFactory.instance;
    GroupAction customGroup = aef.createGroupAction();
    customGroup.setFillStrategy(aef.createFlat());
    customGroup.getText().setValue("workflows.custom");
    customGroup.setActions(aef.createActions(aef.createCustomAction(customAction)));
    return EntityUtils.isResolver(entity) ? mergeResult(StringLiteral, customGroup) : mergeResult(customGroup);
}
Also used : ReplaceWithResourceAction(org.whole.lang.ui.actions.ReplaceWithResourceAction) GroupAction(org.whole.lang.actions.model.GroupAction) PersistenceActivity(org.whole.lang.workflows.model.PersistenceActivity) ReplaceWithResourceAndPersistenceAction(org.whole.lang.ui.actions.ReplaceWithResourceAndPersistenceAction) Expression(org.whole.lang.workflows.model.Expression) IEntity(org.whole.lang.model.IEntity) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) ActionsEntityFactory(org.whole.lang.actions.factories.ActionsEntityFactory)

Aggregations

GroupAction (org.whole.lang.actions.model.GroupAction)15 Actions (org.whole.lang.actions.model.Actions)11 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)7 IEntity (org.whole.lang.model.IEntity)7 ILanguageKit (org.whole.lang.reflect.ILanguageKit)7 ArrayList (java.util.ArrayList)5 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)4 ActionsEntityFactory (org.whole.lang.actions.factories.ActionsEntityFactory)3 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)3 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)3 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)2 WorkflowsEntityFactory (org.whole.lang.workflows.factories.WorkflowsEntityFactory)2 StringLiteral (org.whole.lang.workflows.model.StringLiteral)2 StringLiteral (org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum.StringLiteral)2 Method (java.lang.reflect.Method)1 TreeSet (java.util.TreeSet)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 IAction (org.eclipse.jface.action.IAction)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 Action (org.whole.lang.actions.model.Action)1