Search in sources :

Example 16 with ILanguageKit

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

the class XsdMappingTest method testModelsToXmlSchemaXXX.

@Test
public void testModelsToXmlSchemaXXX() throws Exception {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression path = new ModelToXmlSchemaQuery().create();
    Model model = (Model) ModelsTemplateManager.instance().create("Models model");
    String uri = model.getUri().getValue();
    ILanguageKit lk = ReflectionFactory.getLanguageKit(uri);
    IEntity tuple = BehaviorUtils.evaluateFirstResult(path, model, bm);
    Assert.assertNotNull(tuple);
    InterpreterOperation.interpret(tuple.wGet(1));
    ITemplateManager tm = lk.getTemplateManager();
    IEntity entity = tm.create("Editors model");
    IPersistenceProvider pp = new StringPersistenceProvider();
    XsiPersistenceKit.instance().writeModel(entity, pp);
    IEntity entity2 = XsiPersistenceKit.instance().readModel(pp);
    boolean matches = Matcher.match(entity, entity2);
    Assert.assertTrue(matches);
}
Also used : ModelToXmlSchemaQuery(org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery) PathExpression(org.whole.lang.queries.model.PathExpression) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) ILanguageKit(org.whole.lang.reflect.ILanguageKit) Test(org.junit.Test)

Example 17 with ILanguageKit

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

the class EntityAssistCompositeContributionItem method fillItems.

protected boolean fillItems(IItemContainer<MenuManager, ImageDescriptor> menuContainer, IItemContainer<IAction, ImageDescriptor> actionContainer, IBindingManager bm) {
    IEntity focusEntity = bm.wGet("focusEntity");
    IEntity targetEntity = getTargetEntity(focusEntity);
    IEntity targetParent = targetEntity.wGetParent();
    ILanguageKit targetLanguageKit = EntityUtils.isResolver(targetEntity) && !EntityUtils.isNull(targetParent) ? targetParent.wGetLanguageKit() : targetEntity.wGetLanguageKit();
    boolean hasExtendedActions = fillExtendedEntityAssistMenu(menuContainer, focusEntity, targetLanguageKit);
    actionContainer.addSeparator();
    boolean hasActions = fillEntityAssistMenu(actionContainer, focusEntity, targetLanguageKit);
    return hasExtendedActions || hasActions;
}
Also used : IEntity(org.whole.lang.model.IEntity) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 18 with ILanguageKit

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

the class AbstractEntity method wGetEditorKit.

public IEditorKit wGetEditorKit() {
    ILanguageKit languageKit = wGetEntityDescriptor().getLanguageKit();
    IFragmentModel model = wGetActualModel();
    if (model != NullFragmentModel.instance) {
        IEditorKit editorKit = model.getEditorKit();
        if (editorKit.canApply(languageKit))
            return editorKit;
    }
    return languageKit.getDefaultEditorKit();
// return model != NullFragmentModel.instance ? model.getEditorKit() : languageKit.getDefaultEditorKit();
}
Also used : IEditorKit(org.whole.lang.reflect.IEditorKit) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 19 with ILanguageKit

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

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

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