Search in sources :

Example 11 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor 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 12 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class HandlersBehavior method replaceEntity.

public static void replaceEntity(IBindingManager bm) {
    IEntity focusEntity = bm.wGet("focusEntity");
    EntityDescriptor<?> ed = (EntityDescriptor<?>) bm.wGetValue("entityDescriptor");
    if (bm.wIsSet("featureDescriptor"))
        focusEntity = focusEntity.wGet((FeatureDescriptor) bm.wGetValue("featureDescriptor"));
    IEntity replacement = GenericEntityFactory.instance.create(ed);
    transformer.transform(focusEntity.wGetAdaptee(false), replacement);
    focusEntity.wGetParent().wSet(focusEntity, replacement);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IEntity(org.whole.lang.model.IEntity)

Example 13 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class HandlersBehavior method addEntity.

public static void addEntity(IBindingManager bm) {
    IEntity focusEntity = bm.wGet("focusEntity");
    EntityDescriptor<?> ed = (EntityDescriptor<?>) bm.wGetValue("entityDescriptor");
    if (bm.wIsSet("featureDescriptor"))
        focusEntity = focusEntity.wGet((FeatureDescriptor) bm.wGetValue("featureDescriptor"));
    IEntity child = GenericEntityFactory.instance.create(ed);
    // FIXME make configurable
    if (CommonsEntityDescriptorEnum.Variable.isLanguageSupertypeOf(ed))
        child.wGet(CommonsFeatureDescriptorEnum.varType).wSetValue(focusEntity.wGetEntityDescriptor(0));
    if (bm.wIsSet("hilightPosition"))
        focusEntity.wAdd(bm.wIntValue("hilightPosition"), child);
    else
        focusEntity.wAdd(child);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IEntity(org.whole.lang.model.IEntity)

Example 14 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class WorkflowsUIContentAssistVisitor method allEntityTypes.

protected boolean allEntityTypes(IEntity entity) {
    if (!WorkflowsUtils.isEntityTypeInCreateEntity(entity))
        return false;
    ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
    GroupAction languagesGroup = aef.createGroupAction();
    languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
    languagesGroup.getText().setValue("workflows.languages");
    Actions actions = aef.createActions(0);
    WorkflowsEntityFactory wef = WorkflowsEntityFactory.instance;
    String actualLanguageURI = "";
    String actualEntityName = "";
    EntityDescriptor<?> actualED = null;
    try {
        if (Matcher.matchImpl(StringLiteral, entity)) {
            StringLiteral literal = (StringLiteral) entity;
            actualED = CommonsDataTypePersistenceParser.parseEntityDescriptor(literal.getValue());
            actualLanguageURI = actualED.getLanguageKit().getURI();
            actualEntityName = actualED.getName();
        }
    } catch (Exception e) {
    }
    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)
            ed = edEnum.valueOf(0);
        StringLiteral prototype = wef.createStringLiteral(CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
        actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
    }
    languagesGroup.setActions(actions);
    boolean adeddLanguages = EntityUtils.isResolver(entity) ? mergeResult(StringLiteral, languagesGroup) : mergeResult(languagesGroup);
    if (actualED != null) {
        GroupAction typenamesGroup = aef.createGroupAction();
        typenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
        typenamesGroup.getText().setValue("workflows.typenames");
        actions = aef.createActions(0);
        EntityDescriptorEnum edEnum = actualED.getEntityDescriptorEnum();
        List<EntityDescriptor<?>> eds = new ArrayList<EntityDescriptor<?>>(edEnum.values());
        Collections.sort(eds, new Comparator<EntityDescriptor<?>>() {

            public int compare(EntityDescriptor<?> ed1, EntityDescriptor<?> ed2) {
                return ed1.getName().compareTo(ed2.getName());
            }
        });
        for (EntityDescriptor<?> ed : eds) {
            if (ed.equals(actualED))
                continue;
            StringLiteral prototype = wef.createStringLiteral(CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
            actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ed.getName()));
        }
        typenamesGroup.setActions(actions);
        adeddLanguages |= EntityUtils.isResolver(entity) ? mergeResult(StringLiteral, typenamesGroup) : mergeResult(typenamesGroup);
    }
    return adeddLanguages;
}
Also used : WorkflowsEntityFactory(org.whole.lang.workflows.factories.WorkflowsEntityFactory) WorkflowsEntityDescriptorEnum(org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum) EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) Actions(org.whole.lang.actions.model.Actions) ArrayList(java.util.ArrayList) ILanguageKit(org.whole.lang.reflect.ILanguageKit) GroupAction(org.whole.lang.actions.model.GroupAction) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) StringLiteral(org.whole.lang.workflows.model.StringLiteral) StringLiteral(org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum.StringLiteral) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)

Example 15 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class QueriesUtils method sort.

public static IEntity sort(IEntity entity) {
    if (entity.wGetEntityDescriptor().getCompositeKind().isOrdered()) {
        List<IEntity> entityList = (List<IEntity>) entity;
        IEntity[] array = entityList.toArray(new IEntity[entity.wSize()]);
        entityList.clear();
        Arrays.sort(array, new Comparator<IEntity>() {

            public int compare(IEntity e1, IEntity e2) {
                IEntity e1Adaptee = e1.wGetAdaptee(false);
                IEntity e2Adaptee = e2.wGetAdaptee(false);
                EntityDescriptor<?> e1Ed = e1Adaptee.wGetEntityDescriptor();
                EntityDescriptor<?> e2Ed = e2Adaptee.wGetEntityDescriptor();
                if (e1Ed != e2Ed)
                    return 0;
                switch(e1Ed.getEntityKind()) {
                    case DATA:
                        return DataTypeUtils.compare(e1Adaptee, e2Adaptee);
                    default:
                    case COMPOSITE:
                        return 0;
                    case SIMPLE:
                        boolean idBased = false;
                        List<FeatureDescriptor> entityFeatureDescriptors = e1Ed.getEntityFeatureDescriptors();
                        for (FeatureDescriptor fd : entityFeatureDescriptors) {
                            if (fd.isId()) {
                                idBased = true;
                                int result = compare(e1Adaptee.wGet(fd), e2Adaptee.wGet(fd));
                                if (result != 0)
                                    return result;
                            }
                        }
                        if (idBased)
                            return 0;
                        for (FeatureDescriptor fd : entityFeatureDescriptors) {
                            int result = compare(e1Adaptee.wGet(fd), e2Adaptee.wGet(fd));
                            if (result != 0)
                                return result;
                        }
                        return 0;
                }
            }
        });
        for (IEntity child : array) entity.wAdd(child);
        return entity;
    } else
        return entity;
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) List(java.util.List)

Aggregations

EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)29 IEntity (org.whole.lang.model.IEntity)13 ArrayList (java.util.ArrayList)9 ILanguageKit (org.whole.lang.reflect.ILanguageKit)7 HashMap (java.util.HashMap)5 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)5 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)4 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)4 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)4 Actions (org.whole.lang.actions.model.Actions)3 GroupAction (org.whole.lang.actions.model.GroupAction)3 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)3 Comparator (java.util.Comparator)2 HashSet (java.util.HashSet)2 List (java.util.List)2 IAction (org.eclipse.jface.action.IAction)2 Test (org.junit.Test)2 Database (org.whole.lang.rdb.model.Database)2