Search in sources :

Example 26 with ILanguageKit

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

the class PojoUtils method toDataEntity.

public static IEntity toDataEntity(Object fromObject, PrimitiveType type, Library library) {
    String edName = StringUtils.toUpperCap(type.wStringValue()) + "Data";
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(library.getLanguageURI().wStringValue());
    return GenericEntityFactory.instance(RegistryConfigurations.RESOLVER).create(languageKit.getEntityDescriptorEnum().valueOf(edName), fromObject);
}
Also used : ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 27 with ILanguageKit

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

the class GrammarBasedUIUtils method createCompositeFigure.

public static IEntityFigure createCompositeFigure(IEntity entity) {
    ILanguageKit lk = entity.wGetLanguageKit();
    EntityDescriptorEnum edEnum = lk.getEntityDescriptorEnum();
    FeatureDescriptorEnum fdEnum = lk.getFeatureDescriptorEnum();
    IEntity configuration = Matcher.findAncestor(edEnum.valueOf("CompositePart"), entity);
    IEntity multiline = configuration.wGet(fdEnum.valueOf("multiline"));
    boolean isMultiline = EntityUtils.safeBooleanValue(multiline, false);
    IEntity columns = configuration.wGet(fdEnum.valueOf("columns"));
    int columnsNum = EntityUtils.safeIntValue(columns, 0);
    IEntity separator = configuration.wGet(fdEnum.valueOf("separator"));
    IEntityFigure entityFigure;
    if (EntityUtils.isNotResolver(separator)) {
        String separatorText = GrammarBasedUIUtils.calculateSeparator(separator);
        CompositeFigure compositeFigure = isMultiline ? new StringSeparatedCompositeColumnFigure(separatorText, 10) : new StringSeparatedCompositeRowFigure(separatorText, 10);
        if (isMultiline)
            compositeFigure.getLayoutManager().withMinorAlignment(Alignment.LEADING);
        entityFigure = compositeFigure;
    } else if (columnsNum > 0) {
        TableFigure tableFigure = new TableFigure(columnsNum);
        tableFigure.setBorder(CompositePlaceHolderBorder.OPTIONAL_VERTICAL);
        entityFigure = tableFigure;
    } else
        entityFigure = new CompositeFigure(!isMultiline, true);
    return entityFigure;
}
Also used : CompositeFigure(org.whole.lang.ui.figures.CompositeFigure) StringSeparatedCompositeColumnFigure(org.whole.lang.ui.figures.StringSeparatedCompositeColumnFigure) IEntityFigure(org.whole.lang.ui.figures.IEntityFigure) TableFigure(org.whole.lang.ui.figures.TableFigure) EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) FeatureDescriptorEnum(org.whole.lang.reflect.FeatureDescriptorEnum) IEntity(org.whole.lang.model.IEntity) StringSeparatedCompositeRowFigure(org.whole.lang.ui.figures.StringSeparatedCompositeRowFigure) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 28 with ILanguageKit

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

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

the class AbstractByLanguageOperation method initVisitor.

@Override
protected IVisitor initVisitor(IEntity entity, int normalizedStage) {
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
    String languageUri = languageKit.getURI();
    IVisitor visitor = null;
    if (hasVisitor(languageUri))
        visitor = getVisitor(languageUri, normalizedStage);
    if (visitor == null)
        visitor = getDefaultVisitor(entity, normalizedStage);
    return visitor;
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 30 with ILanguageKit

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

the class AbstractByLanguageOperation method setVisitor.

@Override
public IVisitor setVisitor(IEntity entity, int absoluteStage, IVisitor visitor) {
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
    String languageUri = languageKit.getURI();
    IVisitor oldVisitor = hasVisitor(languageUri) ? getVisitor(entity, absoluteStage) : null;
    int normalizedStage = absoluteStage <= 0 ? 0 : 1;
    String uri = ReflectionFactory.getLanguageKit(entity).getURI();
    IVisitor[] stagedVisitors = stagedVisitorsMap.get(uri);
    if (stagedVisitors == null)
        stagedVisitorsMap.put(uri, stagedVisitors = new IVisitor[2]);
    stagedVisitors[normalizedStage] = visitor;
    return oldVisitor;
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Aggregations

ILanguageKit (org.whole.lang.reflect.ILanguageKit)41 IEntity (org.whole.lang.model.IEntity)12 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)8 Actions (org.whole.lang.actions.model.Actions)7 GroupAction (org.whole.lang.actions.model.GroupAction)7 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)7 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)6 ArrayList (java.util.ArrayList)5 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)5 Test (org.junit.Test)4 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)4 IVisitor (org.whole.lang.visitors.IVisitor)4 HashMap (java.util.HashMap)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 Grammar (org.whole.lang.grammars.model.Grammar)3 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)3 HashSet (java.util.HashSet)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)2