Search in sources :

Example 6 with EntityDescriptorEnum

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

the class GrammarBasedUIUtils method calculateSeparator.

public static String calculateSeparator(IEntity entity) {
    EntityDescriptorEnum edEnum = entity.wGetLanguageKit().getEntityDescriptorEnum();
    StringBuilder sb = new StringBuilder();
    IEntityIterator<IEntity> iterator = IteratorFactory.descendantOrSelfMatcherIterator().withPattern(edEnum.valueOf("Literal"));
    iterator.reset(entity);
    while (iterator.hasNext()) sb.append(EntityUtils.safeStringValue(iterator.next(), ""));
    String separatorText = sb.toString();
    return separatorText.trim();
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) IEntity(org.whole.lang.model.IEntity)

Example 7 with EntityDescriptorEnum

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

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

the class XsiDateTimeUtilsTest method testGregorianCalendar.

@Test
public void testGregorianCalendar() {
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(DATATYPES_URI);
    EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
    IDataTypeParser dataTypeParser = languageKit.getDataTypeParser(DataTypeParsers.PERSISTENCE);
    EntityDescriptor<?> dateTime = edEnum.valueOf("XSDateTime");
    EntityDescriptor<?> date = edEnum.valueOf("XSDate");
    EntityDescriptor<?> time = edEnum.valueOf("XSTime");
    EntityDescriptor<?> gYearMonth = edEnum.valueOf("XSGYearMonth");
    DateTime base = new DateTime(2001, 1, 1, 11, 22, 33, 444, DateTimeZone.UTC);
    assertEquals(dataTypeParser, base, dateTime, "1990-11-30T12:30:43.999Z", "1990-11-30T12:30:43.999Z");
    assertEquals(dataTypeParser, base, dateTime, "1990-11-30T12:30:43", "1990-11-30T12:30:43.000Z");
    assertEquals(dataTypeParser, base, gYearMonth, "1990-11", "1990-11-01T11:22:33.444Z");
    assertEquals(dataTypeParser, base, date, "1990-11-30", "1990-11-30T11:22:33.444Z");
    assertEquals(dataTypeParser, base, date, "1990-11-30Z", "1990-11-30T00:00:00.000Z");
    assertEquals(dataTypeParser, base, date, "1990-11-30+02:00", "1990-11-29T22:00:00.000Z");
    assertEquals(dataTypeParser, base, time, "12:30:43", "2001-01-01T12:30:43.000Z");
    assertEquals(dataTypeParser, base, time, "12:30:43.999Z", "1970-01-01T12:30:43.999Z");
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) ILanguageKit(org.whole.lang.reflect.ILanguageKit) DateTime(org.joda.time.DateTime) SchemaDataTypeParsersTest(org.whole.lang.xsd.parsers.SchemaDataTypeParsersTest) Test(org.junit.Test)

Example 9 with EntityDescriptorEnum

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

use of org.whole.lang.reflect.EntityDescriptorEnum 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)

Aggregations

EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)13 ILanguageKit (org.whole.lang.reflect.ILanguageKit)8 IEntity (org.whole.lang.model.IEntity)6 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)5 ArrayList (java.util.ArrayList)3 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 Test (org.junit.Test)2 NonTerminal (org.whole.lang.grammars.model.NonTerminal)2 Rule (org.whole.lang.grammars.model.Rule)2 GrammarsEntityDescriptorEnum (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 DateTime (org.joda.time.DateTime)1 FramesEntityFactory (org.whole.lang.frames.factories.FramesEntityFactory)1 DataTerminal (org.whole.lang.grammars.model.DataTerminal)1 Production (org.whole.lang.grammars.model.Production)1 JavaEntityDescriptorEnum (org.whole.lang.java.reflect.JavaEntityDescriptorEnum)1 ModelsModel (org.whole.lang.models.codebase.ModelsModel)1