Search in sources :

Example 21 with EntityDescriptor

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

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

the class DataTypePersistenceKit method doReadModel.

@Override
protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    EntityDescriptor<?> ed = null;
    IBindingManager bindings = pp.getBindings();
    if (bindings.wIsSet("entityDescriptor"))
        ed = (EntityDescriptor<?>) bindings.wGetValue("entityDescriptor");
    else if (bindings.wIsSet("entityDescriptorName")) {
        String edName = bindings.wStringValue("entityDescriptorName");
        ed = CommonsDataTypePersistenceParser.parseEntityDescriptor(edName);
    }
    String data = StringUtils.readAsString(pp.getInputStream(), pp.getEncoding());
    if (ed != null)
        return DataTypeUtils.createFromPersistenceString(ed, data);
    else
        return BindingManagerFactory.instance.createValue(data);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 23 with EntityDescriptor

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

the class HandlersBehavior method canAddEntity.

public static boolean canAddEntity(IBindingManager bm) {
    if (!isValidFocusEntityPart(bm))
        return false;
    IEntity focusEntity = bm.wGet("focusEntity");
    EntityDescriptor<?> ed = (EntityDescriptor<?>) bm.wGetValue("entityDescriptor");
    if (bm.wIsSet("featureDescriptor"))
        focusEntity = focusEntity.wGet((FeatureDescriptor) bm.wGetValue("featureDescriptor"));
    return EntityUtils.isAddable(focusEntity, ed);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IEntity(org.whole.lang.model.IEntity)

Example 24 with EntityDescriptor

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

the class HandlersBehavior method canReplaceEntity.

public static boolean canReplaceEntity(IBindingManager bm) {
    if (!isValidFocusEntityPart(bm))
        return false;
    IEntity primarySelectedEntity = bm.wGet("focusEntity");
    EntityDescriptor<?> ed = (EntityDescriptor<?>) bm.wGetValue("entityDescriptor");
    if (bm.wIsSet("featureDescriptor"))
        primarySelectedEntity = primarySelectedEntity.wGet((FeatureDescriptor) bm.wGetValue("featureDescriptor"));
    return EntityUtils.isReplaceable(primarySelectedEntity, ed);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IEntity(org.whole.lang.model.IEntity)

Example 25 with EntityDescriptor

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

the class EntityDescriptorEnumBuilder method addMapEntity.

@SuppressWarnings("unchecked")
public void addMapEntity(String eType, String name, Set<String> modifiers, String keyType, String valueType) {
    String eName = StringUtils.toSimpleName(eType);
    String eName_Ord = eName + "_ord";
    String oldType = entities.put(eName, eType);
    if (oldType == null) {
        // public static final int [eName_ord] = [nextOrdinal];
        FieldDeclaration fieldDecl = newFieldDeclaration("int", eName_Ord, newLiteral(nextOrdinal));
        // assume ModifierKeyword.PRIVATE_KEYWORD
        fieldDecl.modifiers().remove(0);
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
        addBodyDeclaration(nextOrdinal++, fieldDecl);
        // public static final EntityDescriptor<eName> [eName] = (EntityDescriptor<eName>) instance.valueOf([eName_ord]);
        fieldDecl = newFieldDeclaration(newParameterizedType(EntityDescriptor.class.getName(), eName), newVariableDeclarationFragment(eName, newCastExpression(newParameterizedType(EntityDescriptor.class.getName(), eName), newMethodInvocation("instance", "valueOf", ast.newSimpleName(eName_Ord)))));
        // assume ModifierKeyword.PRIVATE_KEYWORD
        fieldDecl.modifiers().remove(0);
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
        addBodyDeclaration(nextOrdinal * 2, fieldDecl);
    } else if (oldType.equals(eType))
        return;
    // putMapEntity([eName_ord], "[eName]", [eType].class, ElementType_ord);
    MethodInvocation callExp = newMethodInvocation("putMapEntity");
    callExp.arguments().add(ast.newSimpleName(eName_Ord));
    callExp.arguments().add(newLiteral(name));
    if (!eName.equals(name))
        callExp.arguments().add(newLiteral(eName));
    callExp.arguments().add(newTypeLiteral(eType));
    callExp.arguments().add(newLiteral(modifiers != null && modifiers.contains("RELATIONSHIP")));
    // newEnumSetOfExpression(EntityModifiers.class.getName(), modifiers));
    callExp.arguments().add(ast.newSimpleName(generator.entityResolverSimpleName(keyType) + "_ord"));
    callExp.arguments().add(ast.newSimpleName(generator.entityResolverSimpleName(valueType) + "_ord"));
    ExpressionStatement expStm = newExpressionStatement(callExp);
    initEntityDescriptors.getBody().statements().add(expStm);
    etypeExpressionMap.put(eType, expStm);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

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